Skip to content

Commit

Permalink
Merge pull request #76116 from alef/vs-clang-cl
Browse files Browse the repository at this point in the history
Add ClangCL to CMake Visual Studio
  • Loading branch information
Maleclypse authored Sep 5, 2024
2 parents 5fca27f + 8a18ae5 commit fce7320
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 66 deletions.
31 changes: 17 additions & 14 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"binaryDir": "${sourceDir}/out/build/${presetName}",
"displayName": "Windows x64 MSVC",
"description": "Target Windows (64-bit) with the Visual Studio development environment.",
"generator": "Visual Studio 16 2019",
"generator": "Visual Studio 17 2022",
"environment": {
"VCPKG_ROOT": "C:/vcpkg"
},
Expand Down Expand Up @@ -53,7 +53,7 @@
"binaryDir": "${sourceDir}/out/build/${presetName}",
"displayName": "Windows Tiles Sounds x64 MSVC",
"description": "Target Windows (64-bit) with the Visual Studio development environment.",
"generator": "Visual Studio 16 2019",
"generator": "Visual Studio 17 2022",
"inherits": "windows-tiles-sounds-x64",
"environment": {
"VCPKG_ROOT": "C:/vcpkg"
Expand All @@ -65,19 +65,19 @@
}
},
{
"name": "windows-tiles-sounds-x64-llvm",
"name": "windows-tiles-sounds-x64-clang-cl",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"displayName": "Windows Tiles Sounds x64 LLVM",
"description": "Target Windows (64-bit) with the LLVM development environment.",
"inherits": "windows-tiles-sounds-x64",
"displayName": "Windows Tiles Sounds x64 ClangCL",
"description": "Target Windows (64-bit) with the ClangCL development environment.",
"inherits": "windows-tiles-sounds-x64-msvc",
"toolset": "CLangCL",
"environment": {
"VCPKG_ROOT": "C:/vcpkg"
"CXXFLAGS": "-ftime-trace"
},
"cacheVariables": {
"LLVM_ROOT": "C:/Program Files/LLVM",
"CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/windows-tiles-sounds-x64-msvc.cmake",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build-scripts/LLVM.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
"CMAKE_PROJECT_INCLUDE_BEFORE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_TOOLCHAIN_FILE": null,
"VCPKG_MANIFEST_DIR": "${sourceDir}/msvc-full-features",
"VCPKG_APPLOCAL_DEPS": "False"
}
},
Expand Down Expand Up @@ -157,9 +157,12 @@
"configuration": "RelWithDebInfo"
},
{
"name": "windows-tiles-sounds-x64-llvm",
"configurePreset": "windows-tiles-sounds-x64-llvm",
"configuration": "RelWithDebInfo"
"name": "windows-tiles-sounds-x64-clang-cl",
"configurePreset": "windows-tiles-sounds-x64-clang-cl",
"configuration": "RelWithDebInfo",
"environment": {
"UseMultiToolTask": "true"
}
}
],
"testPresets": [
Expand Down
88 changes: 36 additions & 52 deletions build-scripts/MSVC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,6 @@ Toolchain file for Microsoft Visual C++.

Used by CMakePresets.json -> "toolchainFile".

C++ flags used by all builds:

/MP cl.exe build with multiple processes
/utf-8 set source and execution character sets to UTF-8
/bigobj increase # of sections in object files
/permissive- enforce more standards compliant behavior
/sdl- disable additional security checks
/FC full path in compiler messages
/Gd __cdecl
/GS- disable buffer security checks
/Gy Enable Function-Level Linking
/GF Eliminate Duplicate Strings
/wd4068 unknown pragma
/wd4146 negate unsigned
/wd4661 explicit template undefined
/wd4819 codepage?
/wd6237 short-circuit eval
/wd6319 a, b: unused a
/wd26444 unnamed objects
/wd26451 overflow
/wd26495 uninitialized member
/WX- (do not) Treat Warnings as Errors
/W1 Warning Level
/TP every file is a C++ file
/Zc:forScope Force Conformance in for Loop Scope
/Zc:inline Remove unreferenced COMDAT
/Zc:wchar_t wchar_t Is Native Type

Additional C++ flags used by RelWithDebInfo builds:

/Ob1 Inline Function Expansion (1 = only when marked as such)
/Oi Generate Intrinsic Functions

Linker flags used by all builds:

/OPT:REF remove unreferenced COMDATs
/OPT:ICF folds identical COMDATs
/DYNAMICBASE does this app really need ASLR ?
/NXCOMPAT same as above
No need to force /TLBID:1 because is default

CMake defaults seen in generators:
CMAKE_CXX_FLAGS=/DWIN32 /D_WINDOWS /EHsc
CMAKE_CXX_FLAGS_DEBUG=/Zi /Ob0 /Od /RTC1
Expand All @@ -68,13 +27,35 @@ Remove /RTC1
# Path has changed, so this configure run will find cl.exe
set(CMAKE_C_COMPILER cl.exe)
set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_FLAGS_INIT "\
/MP /utf-8 /bigobj /permissive- /sdl- /FC /Gd /GS- /Gy /GF \
/wd4068 /wd4146 /wd4661 /wd4819 /wd6237 /wd6319 /wd26444 /wd26451 /wd26495 /WX- /W1 \
/TP /Zc:forScope /Zc:inline /Zc:wchar_t"
)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT
"/Oi"

# C++ flags used by all builds
add_compile_options(
/MP # cl.exe build with multiple processes
/utf-8 # set source and execution character sets to UTF-8
/bigobj # increase # of sections in object files
/permissive- # enforce more standards compliant behavior
/sdl- # disable additional security checks
/FC # full path in compiler messages
/Gd # __cdecl
/GS- # disable buffer security checks
/Gy # enable function-level linking
/GF # eliminate duplicate strings
/wd4068 # unknown pargam
/wd4146 # negate unsigned
/wd4661 # explicit template undefined
/wd4819 # codepage?
/wd6237 # short-circuit eval
/wd6319 # a, b: unused a
/wd26444 # unnamed objects
/wd26451 # overflow
/wd26495 # uninitialized mamber
/WX- # do not tread warnings as errors
/W1 # warning level
/TP # every source file is a C++ file
/Zc:forScope # force conformace in for loop scope
/Zc:inline # remove unreferenced COMDAT
/Zc:wchar_t # wchar_t is native type
$<$<CONFIG:RelWithDebInfo>:/Oi> # inline function expansions (1 = only when marked as such)
)

add_compile_definitions(
Expand All @@ -85,16 +66,19 @@ add_compile_definitions(
USE_VCPKG
)


# Linker flags used by all builds:
add_link_options(
/OPT:REF
/OPT:ICF
/OPT:REF # remove unreferenced COMDATs
/OPT:ICF # force identical COMDATs
/LTCG:OFF
/INCREMENTAL:NO
/DYNAMICBASE
/NXCOMPAT
/DYNAMICBAS # does this app realy need ASLR ?
/NXCOMPAT # same as above
"$<$<CONFIG:Debug>:/NODEFAULTLIB:LIBCMT>"
"$<$<CONFIG:RelWithDebInfo>:/NODEFAULTLIB:LIBCMTD>"
)
# Note: no need to force /TLBID:1 because is default

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

Expand Down

0 comments on commit fce7320

Please sign in to comment.