-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable using the Ninja generator instead of Visual Studio on Windows builds. #41897
Changes from 57 commits
cad3f29
e921ecc
a69c346
d1b12b5
df589ef
0524739
e99246f
03140d8
9bdf0f1
417b07a
db7454a
b70eeca
36cc91e
fe484c9
cba81df
c20b356
86f5f90
a2478cc
ca84dd2
3b17211
8422b09
885974e
a8feb74
e7b9280
6bcaec4
cb1f6a1
03c4cc9
0378122
195fa3e
7c7c168
5dc02c0
86019b9
823cef9
3e60c98
4d81fe8
8286fba
0d9205a
82f0491
6541aeb
ca101e9
78fd252
18acb6f
d38ae03
5051f71
43e8a7b
a34284e
ccd66f5
992817d
7db1ecb
aa79e4f
327b002
bc701d1
d95091e
334293c
c1b3676
2945f4d
cfc26f5
343690e
9af32b3
61e4c81
a437115
83939c6
f95c8f6
ff80bab
4db3105
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -451,27 +451,48 @@ endif(CLR_CMAKE_HOST_UNIX) | |
if (MSVC) | ||
# Compile options for targeting windows | ||
|
||
add_compile_options(/TP) # compile all files as C++ | ||
add_compile_options(/nologo) # Suppress Startup Banner | ||
add_compile_options(/W3) # set warning level to 3 | ||
add_compile_options(/WX) # treat warnings as errors | ||
add_compile_options(/Oi) # enable intrinsics | ||
add_compile_options(/Oy-) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls | ||
add_compile_options(/Gm-) # disable minimal rebuild | ||
add_compile_options(/Zp8) # pack structs on 8-byte boundary | ||
add_compile_options(/Gy) # separate functions for linker | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") # disable C++ RTTI | ||
add_compile_options(/FC) # use full pathnames in diagnostics | ||
add_compile_options(/MP) # Build with Multiple Processes (number of processes equal to the number of processors) | ||
add_compile_options(/Zm200) # Specify Precompiled Header Memory Allocation Limit of 150MB | ||
add_compile_options(/Zc:strictStrings) # Disable string-literal to char* or wchar_t* conversion | ||
|
||
add_compile_options(/wd4960 /wd4961 /wd4603 /wd4627 /wd4838 /wd4456 /wd4457 /wd4458 /wd4459 /wd4091 /we4640) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/TP>) # compile all files as C++ | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/nologo>) # Suppress Startup Banner | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/W3>) # set warning level to 3 | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/WX>) # treat warnings as errors | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Oi>) # enable intrinsics | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Oy->) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gm->) # disable minimal rebuild | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zp8>) # pack structs on 8-byte boundary | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gy>) # separate functions for linker | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/GS>) # Explicitly enable the buffer security checks | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/fp:precise>) # Enable precise floating point | ||
|
||
# disable C++ RTTI | ||
# /GR is added by default by CMake, so remove it manually. | ||
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CL does use the rightmost option, but it emits an unsuppressable warning when doing so. |
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") | ||
|
||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/FC>) # use full pathnames in diagnostics | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/MP>) # Build with Multiple Processes (number of processes equal to the number of processors) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zm200>) # Specify Precompiled Header Memory Allocation Limit of 150MB | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zc:strictStrings>) # Disable string-literal to char* or wchar_t* conversion | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zc:wchar_t>) # wchar_t is a built-in type. | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zc:inline>) # All inline functions must have their definition available in the current translation unit. | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zc:forScope>) # Enforce standards-compliant for scope. | ||
|
||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4960>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4961>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4603>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4627>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4838>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4456>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4457>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4458>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4459>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4091>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4640>) | ||
|
||
# Disable Warnings: | ||
# 4291: Delete not defined for new, c++ exception may cause leak. | ||
# 5105: Windows SDK headers use 'defined' operator in some macros | ||
add_compile_options(/wd4291 /wd5105) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd4291>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/wd5105>) | ||
|
||
# Treat Warnings as Errors: | ||
# 4007: 'main' : must be __cdecl. | ||
|
@@ -480,7 +501,12 @@ if (MSVC) | |
# 4551: Function call missing argument list. | ||
# 4700: Local used w/o being initialized. | ||
# 4806: Unsafe operation involving type 'bool'. | ||
add_compile_options(/we4007 /we4013 /we4102 /we4551 /we4700 /we4806) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4007>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4013>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4102>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4551>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4700>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4806>) | ||
|
||
# Set Warning Level 3: | ||
# 4092: Sizeof returns 'unsigned long'. | ||
|
@@ -491,26 +517,32 @@ if (MSVC) | |
# 4212: Function declaration used ellipsis. | ||
# 4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX. | ||
# 35038: data member 'member1' will be initialized after data member 'member2'. | ||
add_compile_options(/w34092 /w34121 /w34125 /w34130 /w34132 /w34212 /w34530 /w35038) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34092>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34121>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34125>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34130>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34132>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34212>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w34530>) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w35038>) | ||
|
||
# Set Warning Level 4: | ||
# 4177: Pragma data_seg s/b at global scope. | ||
add_compile_options(/w44177) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/w44177>) | ||
|
||
add_compile_options(/Zi) # enable debugging information | ||
add_compile_options(/ZH:SHA_256) # use SHA256 for generating hashes of compiler processed source files. | ||
add_compile_options(/source-charset:utf-8) # Force MSVC to compile source as UTF-8. | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Zi>) # enable debugging information | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/ZH:SHA_256>) # use SHA256 for generating hashes of compiler processed source files. | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/source-charset:utf-8>) # Force MSVC to compile source as UTF-8. | ||
|
||
if (CLR_CMAKE_HOST_ARCH_I386) | ||
add_compile_options(/Gz) | ||
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/Gz>) | ||
endif (CLR_CMAKE_HOST_ARCH_I386) | ||
|
||
add_compile_options($<$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>:/GL>) | ||
add_compile_options($<$<OR:$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>,$<CONFIG:Checked>>:/O1>) | ||
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:C,CXX>,$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>>:/GL>) | ||
|
||
if (CLR_CMAKE_HOST_ARCH_AMD64) | ||
# The generator expression in the following command means that the /homeparams option is added only for debug builds | ||
add_compile_options($<$<CONFIG:Debug>:/homeparams>) # Force parameters passed in registers to be written to the stack | ||
# The generator expression in the following command means that the /homeparams option is added only for debug builds for C and C++ source files | ||
add_compile_options($<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C,CXX>>:/homeparams>) # Force parameters passed in registers to be written to the stack | ||
endif (CLR_CMAKE_HOST_ARCH_AMD64) | ||
|
||
# enable control-flow-guard support for native components for non-Arm64 builds | ||
|
@@ -524,9 +556,7 @@ if (MSVC) | |
# For Release builds, we shall dynamically link into uCRT [ucrtbase.dll] (which is pushed down as a Windows Update on downlevel OS) but | ||
# wont do the same for debug/checked builds since ucrtbased.dll is not redistributable and Debug/Checked builds are not | ||
# production-time scenarios. | ||
|
||
add_compile_options($<$<OR:$<OR:$<CONFIG:Release>,$<CONFIG:Relwithdebinfo>>,$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>:/MT>) | ||
add_compile_options($<$<AND:$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>,$<NOT:$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>>:/MTd>) | ||
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<AND:$<OR:$<CONFIG:Debug>,$<CONFIG:Checked>>,$<NOT:$<BOOL:$<TARGET_PROPERTY:DAC_COMPONENT>>>>:Debug>) | ||
|
||
add_compile_options($<$<COMPILE_LANGUAGE:ASM_MASM>:/ZH:SHA_256>) | ||
|
||
|
@@ -535,6 +565,8 @@ if (MSVC) | |
add_definitions(-DDISABLE_CONTRACTS) | ||
endif (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64) | ||
|
||
# Don't display the output header when building RC files. | ||
add_compile_options($<$<COMPILE_LANGUAGE:RC>:/nologo>) | ||
endif (MSVC) | ||
|
||
if(CLR_CMAKE_ENABLE_CODE_COVERAGE) | ||
|
@@ -554,21 +586,14 @@ if(CLR_CMAKE_ENABLE_CODE_COVERAGE) | |
|
||
endif(CLR_CMAKE_ENABLE_CODE_COVERAGE) | ||
|
||
if (CMAKE_BUILD_TOOL STREQUAL nmake) | ||
if (CMAKE_GENERATOR MATCHES "(Makefile|Ninja)") | ||
set(CMAKE_RC_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}") | ||
endif(CMAKE_BUILD_TOOL STREQUAL nmake) | ||
endif() | ||
|
||
# Ensure other tools are present | ||
if (CLR_CMAKE_HOST_WIN32) | ||
if(CLR_CMAKE_HOST_ARCH_ARM) | ||
|
||
# Confirm that Windows SDK is present | ||
if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" ) | ||
message(FATAL_ERROR "Windows SDK is required for the Arm32 build.") | ||
else() | ||
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") | ||
endif() | ||
|
||
# Explicitly specify the assembler to be used for Arm32 compile | ||
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER) | ||
|
||
|
@@ -578,14 +603,13 @@ if (CLR_CMAKE_HOST_WIN32) | |
# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly | ||
# use ml[64].exe as the assembler. | ||
enable_language(ASM) | ||
elseif(CLR_CMAKE_HOST_ARCH_ARM64) | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "") | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "") | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "") | ||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -g <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>") | ||
|
||
# Confirm that Windows SDK is present | ||
if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" ) | ||
message(FATAL_ERROR "Windows SDK is required for the ARM64 build.") | ||
else() | ||
message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") | ||
endif() | ||
elseif(CLR_CMAKE_HOST_ARCH_ARM64) | ||
|
||
# Explicitly specify the assembler to be used for Arm64 compile | ||
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER) | ||
|
@@ -596,6 +620,11 @@ if (CLR_CMAKE_HOST_WIN32) | |
# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly | ||
# use ml[64].exe as the assembler. | ||
enable_language(ASM) | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "") | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "") | ||
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "") | ||
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -g <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>") | ||
else() | ||
enable_language(ASM_MASM) | ||
endif() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder - why was this change in specifying options needed for enabling Ninja?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes were needed because both MASM and RC are CMake langauges, so
add_compile_options
was adding all of these flags to files of those languages as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, multiple languages in the COMPILE_LANGUAGE are not supported until CMake 3.15, according to cmake doc. Some of the test legs in this CI are failing due to that. Also, the doc discourages using this generator expression:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point me to where that doc is from? I haven’t seen that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in the COMPILE_LANGUAGE doc: https://cmake.org/cmake/help/v3.6/manual/cmake-generator-expressions.7.html?highlight=compile_language. The doc for 3.15+ use a little different wording, but it is there as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for 3.15+ describe the behavior I expect, with the VS generator treating everything as C++. Since all cases we use this generator expressions here we apply to both C and C++, we’re in the supported zone.
Re outdated CMake on the CI machines: I’m working on getting 3.16 installed on CI along with Ninja so the new precompiled header functionality works on CI machines.