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

Commit

Permalink
Refactor native build to remove the compiler-override files (#23897)
Browse files Browse the repository at this point in the history
* On systems that have both cmake 2 and cmake 3, use cmake 3.

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

* Set CMAKE_USER_MAKE_RULES_OVERRIDE to "" to not break incremental builds after building on a branch that had it set to a path.

* Remove CMake version output.

* Move comment outside of multiline command.

* Retry setting CMAKE_USER_MAKE_RULES_OVERRIDE

* Remove unnecessary variable wrappers.

* Simplify cmake 3 resolution.

* Explicitly use CMAKE_CXX_FLAGS for C++-only flags that GCC complains about on C files.

* Set -Wall via CMAKE_<LANG>_FLAGS until we can move all flag settings to add_compile_options

* Fix typos

* Another temporary precedence issue.

* include configureoptimization.cmake in configurecompiler.cmake

* Move setting CMAKE_EXPORT_COMPILE_COMMANDS to configurecompiler.cmake.

* Rename configure.cmake -> verify_lto.cmake.

* Fix path to verify-lto

* Try using CMAKE_<LANG>_FLAGS instead of CMAKE_<LANG>_FLAGS_INIT.

* Revert name change to configure.camek
  • Loading branch information
jkoritzinsky authored May 29, 2019
1 parent 3ac7761 commit 38f121b
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 106 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ 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)

# Include cmake functions
include(functions.cmake)

# Include global configure settings
# Verify that LTCG/LTO is available
include(configure.cmake)

if (WIN32)
Expand Down
32 changes: 29 additions & 3 deletions configurecompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Set initial flags for each configuration

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

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 +183,27 @@ 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)
# We need to add -Wall to CMAKE_<LANG>_FLAGS since add_compile_options takes precedence
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-null-conversion)
else()
# We need to add -Werror=conversion-null to CMAKE_<LANG>_FLAGS since add_compile_options takes precedence
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -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 +287,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 Expand Up @@ -604,3 +628,5 @@ if(CLR_CMAKE_ENABLE_CODE_COVERAGE)
endif(CLR_CMAKE_PLATFORM_UNIX)

endif(CLR_CMAKE_ENABLE_CODE_COVERAGE)

include(${CMAKE_CURRENT_LIST_DIR}/configureoptimization.cmake)
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()
5 changes: 2 additions & 3 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()
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-virtual-dtor")
endif(WIN32)
endif()

add_library_clr(mscorpe STATIC
${MSCORPE_SOURCES}
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.

17 changes: 4 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,9 @@ 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
cmake_command=$(command -v cmake3 || command -v cmake)

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

# Include CMAKE_USER_MAKE_RULES_OVERRIDE as uninitialized since it will hold its value in the CMake cache otherwise can cause issues when branch switching
$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" \
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=" \
$cmake_extra_defines \
$__UnprocessedCMakeArgs \
"$1"
11 changes: 6 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,24 @@ if [ "$build_arch" = "armel" ]; then
cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1"
fi

overridefile=gcc-compiler-override.txt

__currentScriptDir="$script_dir"

cmake \
cmake_command=$(command -v cmake3 || command -v cmake)

# Include CMAKE_USER_MAKE_RULES_OVERRIDE as uninitialized since it will hold its value in the CMake cache otherwise can cause issues when branch switching
$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_USER_MAKE_RULES_OVERRIDE=" \
"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir" \
$cmake_extra_defines \
"$__UnprocessedCMakeArgs" \
"$1"
3 changes: 2 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,9 @@ 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=%__CMakeBinDir%" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" %__SourceDir%
"%CMakePath%" -DCMAKE_USER_MAKE_RULES_OVERRIDE= "-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.

11 changes: 8 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# 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 "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
endif()

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

# Verify that LTCG/LTO is available
include(${CMAKE_CURRENT_SOURCE_DIR}/../configure.cmake)
# Include global configure settings
include(${CMAKE_CURRENT_SOURCE_DIR}/../configurecompiler.cmake)
# Compile options

if (WIN32)
Expand Down

0 comments on commit 38f121b

Please sign in to comment.