summaryrefslogtreecommitdiff
path: root/configurecompiler.cmake
diff options
context:
space:
mode:
authorJeremy Koritzinsky <jekoritz@microsoft.com>2019-06-05 21:48:55 (GMT)
committerGitHub <noreply@github.com>2019-06-05 21:48:55 (GMT)
commit90dd13ee1bd497d7724c2b1d0fd833d42f7001ad (patch)
treeae6167d368f59598c6dd6c71e3280d1af0485f02 /configurecompiler.cmake
parentd7e49efa6b41afb2b7a9ee3adc8f0850b968562a (diff)
downloadcoreclr-90dd13ee1bd497d7724c2b1d0fd833d42f7001ad.zip
coreclr-90dd13ee1bd497d7724c2b1d0fd833d42f7001ad.tar.gz
coreclr-90dd13ee1bd497d7724c2b1d0fd833d42f7001ad.tar.bz2
Use Modern CMake features instead of CMAKE_CXX_FLAGS (#24861)
* Convert C++ standard settings and warning options from CMAKE_<LANG>_FLAGS to Modern CMake isms. * More $<COMPILE_LANGUAGE> generator expressions instead of CMAKE_CXX_FLAGS. * Use $<COMPILE_LANGUAGE:CXX> for all -fpermissive usage * Fix generator expression that generates multiple flags * Fix invalid use of CMAKE_CXX_FLAGS instead of CMAKE_C_FLAGS. * Treat AppleClang as though it is Clang (match pre-3.0 behavior). * Update our build system to understand that AppleClang is distinct from Clang and remove CMP0025 policy setting. * PR Feedback.
Diffstat (limited to 'configurecompiler.cmake')
-rw-r--r--configurecompiler.cmake27
1 files changed, 12 insertions, 15 deletions
diff --git a/configurecompiler.cmake b/configurecompiler.cmake
index a8a8ffc..a5e44bb 100644
--- a/configurecompiler.cmake
+++ b/configurecompiler.cmake
@@ -1,6 +1,10 @@
# Set initial flags for each configuration
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED 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)
@@ -73,11 +77,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CLR_CMAKE_PLATFORM_UNIX 1)
set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
set(CLR_CMAKE_PLATFORM_DARWIN 1)
- if(CMAKE_VERSION VERSION_LESS "3.4.0")
- set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> -o <OBJECT> -c <SOURCE>")
- else()
- set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
- endif(CMAKE_VERSION VERSION_LESS "3.4.0")
+ set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_C_COMPILER} <FLAGS> <DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
@@ -189,14 +189,11 @@ 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(-Wall)
+ if (CMAKE_CXX_COMPILER_ID MATCHES "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")
+ add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Werror=conversion-null>)
endif()
endif()
@@ -479,9 +476,9 @@ if (CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-Wno-unused-function)
#These seem to indicate real issues
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
+ add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)
- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# The -ferror-limit is helpful during the porting, it makes sure the compiler doesn't stop
# after hitting just about 20 errors.
add_compile_options(-ferror-limit=4096)
@@ -515,7 +512,7 @@ if (CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-Wno-nonnull-compare)
endif()
if (COMPILER_SUPPORTS_F_ALIGNED_NEW)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-new")
+ add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-faligned-new>)
endif()
endif()
@@ -595,7 +592,7 @@ if (WIN32)
# enable control-flow-guard support for native components for non-Arm64 builds
# Added using variables instead of add_compile_options to let individual projects override it
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /guard:cf")
- set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /guard:cf")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
# Statically linked CRT (libcmt[d].lib, libvcruntime[d].lib and libucrt[d].lib) by default. This is done to avoid
# linking in VCRUNTIME140.DLL for a simplified xcopy experience by reducing the dependency on VC REDIST.