Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
On systems that have both cmake 2 and cmake 3, use cmake 3.
Browse files Browse the repository at this point in the history
Move CMAKE_EXPORT_COMPILE_COMMANDS to top level instead of in gen-buildsys-*. Define the CMake install prefix in gen-buildsys-* instead of pulling from an environment variable.

Define C++ standard as CMake property instead of as flag.

Move CLR_DEFINES_*_INIT out of overrides and into configurecompiler.cmake

Move flags that generate debug info into configurecompiler.cmake

Remove the CMAKE_USER_RULES_OVERRIDE files.

Add cmake version output for determining what cmake versions each CI system has.

Fix syntax in gen-buildsys-clang.

Change add_compile_definitions back to add_definitions

Add -D prefix for adding definitions via add_definitions

Remove extraneous double-quote

Change default config definition adding to the syntax in master

Switch back to old CMAKE_<LANG>_FLAGS way of setting the language standards and try to go back to 2.8.12 minimum

Switch back setting compile definitions for non-Windows branch too.

Use SET with CMAKE_<LANG>_FLAGS. Convert some usages of appending to CMAKE_<LANG>_FLAGS to add_compile_options where possible.

Set CMAKE_<LANG>_FLAGS_INIT instead of CMAKE_<LANG>_FLAGS

Make sure configureopimitzation.cmake is included correctly in test build.

Try to add brackets to get the Linux ARM compilation working correctly.

Define standard language version in configurecompiler.cmake instead of root CMakeLists (so tests get it)

Try to move langauge standard check to configure.cmake

define language standard in each root CMakeLists.txt

Fix off-Windows test build.

Set CMAKE_EXPORT_COMPILE_COMMANDS after the project() call
  • Loading branch information
jkoritzinsky committed Apr 12, 2019
1 parent 38b7770 commit 7bb015e
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 109 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Verify minimum required version
cmake_minimum_required(VERSION 2.8.12)

if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
if(${CMAKE_VERSION} VERSION_EQUAL 3.0 OR ${CMAKE_VERSION} VERSION_GREATER 3.0)
cmake_policy(SET CMP0042 NEW)
endif()

if (NOT WIN32)
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -std=c++11" CACHE STRING "Flags used by the compiler during all build types.")
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -std=c11" CACHE STRING "Flags used by the compiler during all build types.")
endif()

# Set the project name
project(CoreCLR)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Include cmake functions
include(functions.cmake)
Expand Down Expand Up @@ -143,6 +149,7 @@ endif(WIN32)
# Configure compiler settings for environment
#----------------------------------------------------
include(configurecompiler.cmake)
include(configureoptimization.cmake)

#----------------------------------------------------
# Cross target Component build specific configuration
Expand Down
24 changes: 21 additions & 3 deletions configurecompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Set initial flags for each configuration

set(CLR_DEFINES_DEBUG_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
set(CLR_DEFINES_CHECKED_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1)
set(CLR_DEFINES_RELEASE_INIT NDEBUG URTBLDENV_FRIENDLY=Retail)
set(CLR_DEFINES_RELWITHDEBINFO_INIT NDEBUG URTBLDENV_FRIENDLY=Retail)

#----------------------------------------
# Detect and set platform variable names
# - for non-windows build platform & architecture is detected using inbuilt CMAKE variables and cross target component configure
Expand Down Expand Up @@ -174,12 +181,23 @@ endif()
# Initialize Cmake compiler flags and other variables
#-----------------------------------------------------

if(WIN32)
add_compile_options(/Zi /FC /Zc:strictStrings)
elseif (CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-g -Wall)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-null-conversion)
else()
add_compile_options(-Werror=conversion-null)
endif()
endif()

if (CMAKE_CONFIGURATION_TYPES) # multi-configuration generator?
set(CMAKE_CONFIGURATION_TYPES "Debug;Checked;Release;RelWithDebInfo" CACHE STRING "" FORCE)
endif (CMAKE_CONFIGURATION_TYPES)

set(CMAKE_C_FLAGS_CHECKED ${CLR_C_FLAGS_CHECKED_INIT} CACHE STRING "Flags used by the compiler during checked builds.")
set(CMAKE_CXX_FLAGS_CHECKED ${CLR_CXX_FLAGS_CHECKED_INIT} CACHE STRING "Flags used by the compiler during checked builds.")
set(CMAKE_C_FLAGS_CHECKED "")
set(CMAKE_CXX_FLAGS_CHECKED "")
set(CMAKE_EXE_LINKER_FLAGS_CHECKED "")
set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "")

Expand Down Expand Up @@ -263,7 +281,7 @@ elseif (CLR_CMAKE_PLATFORM_UNIX)
# set the different configuration defines.
if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG)
# First DEBUG
set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS ${CLR_DEFINES_DEBUG_INIT})
set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS ${CLR_DEFINES_DEBUG_INIT})
elseif (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
# Then CHECKED
set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS ${CLR_DEFINES_CHECKED_INIT})
Expand Down
22 changes: 22 additions & 0 deletions configureoptimization.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if(WIN32)
add_compile_options($<$<CONFIG:Debug>:/Od>)
add_compile_options($<$<CONFIG:Checked>:/O1>)
add_compile_options($<$<CONFIG:Release>:/Ox>)
add_compile_options($<$<CONFIG:RelWithDebInfo>:/O2>)
elseif(CLR_CMAKE_PLATFORM_UNIX)
set(CLR_CMAKE_ARM_OPTIMIZATION_FALLBACK OFF)
if(CLR_CMAKE_TARGET_ARCH STREQUAL "arm" OR CLR_CMAKE_TARGET_ARCH STREQUAL "armel")
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9))
set(CLR_CMAKE_ARM_OPTIMIZATION_FALLBACK ON)
endif()
endif()
add_compile_options($<$<CONFIG:Debug>:-O0>)
if (CLR_CMAKE_ARM_OPTIMIZATION_FALLBACK)
add_compile_options($<$<NOT:$<CONFIG:Debug>>:-O1>)
else()
add_compile_options($<$<CONFIG:Checked>:-O2>)
add_compile_options($<$<CONFIG:Release>:-O3>)
add_compile_options($<$<CONFIG:RelWithDebInfo>:-O2>)
endif()

endif()
2 changes: 1 addition & 1 deletion src/ToolBox/SOS/lldbplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ endif()

message(STATUS "LLDB_H: ${LLDB_H}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-virtual-dtor")
add_compile_options(-Wno-delete-non-virtual-dtor)

include_directories(inc)
include_directories("${LLDB_H}")
Expand Down
7 changes: 3 additions & 4 deletions src/dlls/mscorpe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ set(MSCORPE_SOURCES
ceefilegenwritertokens.cpp
)

if(WIN32)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-virtual-dtor")
endif(WIN32)
if(NOT WIN32)
add_compile_options(-Wno-delete-non-virtual-dtor)
endif()

add_library_clr(mscorpe STATIC
${MSCORPE_SOURCES}
Expand Down
2 changes: 1 addition & 1 deletion src/ilasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if(CLR_CMAKE_PLATFORM_UNIX)
# Need generate a right form of asmparse.cpp to avoid the following options.
# Clang also produces a bad-codegen on this prebuilt file with optimization.
# https://github.com/dotnet/coreclr/issues/2305
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-virtual-dtor")
add_compile_options(-Wno-delete-non-virtual-dtor)
add_compile_options(-Wno-register)
add_compile_options(-Wno-array-bounds)
add_compile_options(-Wno-unused-label)
Expand Down
1 change: 0 additions & 1 deletion src/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories("./jitstd")
include_directories("../inc")
Expand Down
20 changes: 0 additions & 20 deletions src/pal/tools/clang-compiler-override-arm.txt

This file was deleted.

20 changes: 0 additions & 20 deletions src/pal/tools/clang-compiler-override.txt

This file was deleted.

20 changes: 0 additions & 20 deletions src/pal/tools/gcc-compiler-override.txt

This file was deleted.

22 changes: 9 additions & 13 deletions src/pal/tools/gen-buildsys-clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,14 @@ if [ "$build_arch" == "armel" ]; then
cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
fi

clang_version=$( $CC --version | head -1 | sed 's/[^0-9]*\([0-9]*\.[0-9]*\).*/\1/' )
# Use O1 option when the clang version is smaller than 3.9
# Otherwise use O3 option in release build
if [[ ( ${clang_version%.*} -eq 3 && ${clang_version#*.} -lt 9 ) &&
( "$build_arch" == "arm" || "$build_arch" == "armel" ) ]]; then
overridefile=clang-compiler-override-arm.txt
else
overridefile=clang-compiler-override.txt
fi

__currentScriptDir="$script_dir"

cmake_command=cmake
if command -v "cmake3" > /dev/null 2>&1
then
cmake_command=$(command -v cmake3)
else
cmake_command=$(command -v cmake)
fi

if [[ "$scan_build" == "ON" ]]; then
export CCC_CC=$CC
Expand All @@ -168,16 +163,17 @@ if [[ "$scan_build" == "ON" ]]; then
cmake_command="$SCAN_BUILD_COMMAND $cmake_command"
fi

$cmake_command --version

$cmake_command \
-G "$generator" \
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${__currentScriptDir}/$overridefile" \
"-DCMAKE_AR=$llvm_ar" \
"-DCMAKE_LINKER=$llvm_link" \
"-DCMAKE_NM=$llvm_nm" \
"-DCMAKE_OBJDUMP=$llvm_objdump" \
"-DCMAKE_BUILD_TYPE=$buildtype" \
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1 " \
"-DCLR_CMAKE_ENABLE_CODE_COVERAGE=$code_coverage" \
"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir" \
"-DCLR_CMAKE_COMPILER=Clang" \
$cmake_extra_defines \
$__UnprocessedCMakeArgs \
Expand Down
13 changes: 8 additions & 5 deletions src/pal/tools/gen-buildsys-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,26 @@ if [ "$build_arch" = "armel" ]; then
cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
fi

overridefile=gcc-compiler-override.txt

__currentScriptDir="$script_dir"

cmake \
if command -v "cmake3" > /dev/null 2>&1
cmake_command=$(command -v cmake3)
else
cmake_command=$(command -v cmake)
fi

$cmake_command \
-G "$generator" \
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${__currentScriptDir}/$overridefile" \
"-DCMAKE_AR=$gcc_ar" \
"-DCMAKE_LINKER=$gcc_link" \
"-DCMAKE_NM=$gcc_nm" \
"-DCMAKE_RANLIB=$gcc_ranlib" \
"-DCMAKE_OBJCOPY=$gcc_objcopy" \
"-DCMAKE_OBJDUMP=$gcc_objdump" \
"-DCMAKE_BUILD_TYPE=$buildtype" \
"-DCMAKE_EXPORT_COMPILE_COMMANDS=1 " \
"-DCLR_CMAKE_ENABLE_CODE_COVERAGE=$code_coverage" \
"-DCLR_CMAKE_COMPILER=GNU" \
"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir" \
$cmake_extra_defines \
"$__UnprocessedCMakeArgs" \
"$1"
4 changes: 3 additions & 1 deletion src/pal/tools/gen-buildsys-win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ if defined CMakePath goto DoGen
:: Eval the output from set-cmake-path.ps1
for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& "%basePath%\set-cmake-path.ps1""') do %%a


:DoGen
"%CMakePath%" "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\windows-compiler-override.txt" "-DCMAKE_INSTALL_PREFIX:PATH=$ENV{__CMakeBinDir}" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" %__SourceDir%
"%CMakePath%" --version
"%CMakePath%" -DCMAKE_INSTALL_PREFIX=%__CMakeBinDir% "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" %__SourceDir%
endlocal
GOTO :DONE

Expand Down
16 changes: 0 additions & 16 deletions src/pal/tools/windows-compiler-override.txt

This file was deleted.

13 changes: 10 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# Require at least version 2.8.12 of CMake
cmake_minimum_required(VERSION 2.8.12)

# Include global configure settings
include(${CMAKE_CURRENT_SOURCE_DIR}/../configure.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../configurecompiler.cmake)
if (NOT WIN32)
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -std=c++11" CACHE STRING "Flags used by the compiler during all build types.")
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -std=c11" CACHE STRING "Flags used by the compiler during all build types.")
endif()

project(Project)

set(INC_PLATFORM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/Common/Platform)
if (WIN32)
add_definitions(-DWINDOWS=1)
endif()

# Include global configure settings
include(${CMAKE_CURRENT_SOURCE_DIR}/../configure.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../configurecompiler.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/../configureoptimization.cmake)
# Compile options

if (WIN32)
Expand Down

0 comments on commit 7bb015e

Please sign in to comment.