Skip to content

Commit

Permalink
chore: some CMakeLists and CMakePresets tweaks/fixes (#57)
Browse files Browse the repository at this point in the history
Changes:
- Add `VCPKG_HOST_TRIPLET` to match `VCPKG_TARGET_TRIPLET`
- Add a few compiler and linker flags for debug/release configs for MSVC
and clang-cl
- Suppress two warnings:
  - `C4996` (MSVC)
  - `-Wreturn-type` (clang-cl)
- Remove redundant `set(CMAKE_TOOLCHAIN_FILE ...)` call from
CMakeLists.txt (it's already set in CMakePresets.json)
- Remove unused `clang` build preset and `CMAKE_C_COMPILER` cache
variable
  • Loading branch information
ThirdEyeSqueegee authored Sep 16, 2023
1 parent 032cc32 commit d77646e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
3 changes: 2 additions & 1 deletion CommonLibSF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.26)
message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.")

# singleton target across multiple projects
if(TARGET CommonLibSF)
Expand All @@ -14,7 +15,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "")

# info
project(
Expand Down Expand Up @@ -95,6 +95,7 @@ if (MSVC)
/wd4710 # 'function' : function not inlined
/wd4711 # function 'function' selected for inline expansion
/wd4820 # 'bytes' bytes padding added after construct 'member_name'
/wd4996
/wd5026 # 'type': move constructor was implicitly defined as deleted
/wd5027 # 'type': move assignment operator was implicitly defined as deleted
/wd5045 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
Expand Down
99 changes: 50 additions & 49 deletions CommonLibSF/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,62 @@
"name": "common",
"hidden": true,
"cacheVariables": {
"CMAKE_CXX_FLAGS": "$env{PROJECT_PLATFORM_FLAGS} $env{PROJECT_TEXT_FLAGS} $env{PROJECT_COMPILER_FLAGS} $penv{CXXFLAGS}"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-msvc-x64",
"enableMicrosoftCodeAnalysis": true,
"enableClangTidyCodeAnalysis": true
}
"CMAKE_CXX_FLAGS": "$env{PROJECT_PLATFORM_FLAGS} $env{PROJECT_TEXT_FLAGS} $env{PROJECT_COMPILER_FLAGS} $penv{CXXFLAGS}",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
}
},
{
"name": "packaging-vcpkg",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "STRING",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
},
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md",
"VCPKG_HOST_TRIPLET": "x64-windows-static-md"
}
},
{
"name": "buildtype-debug",
"name": "buildtype-debug-msvc",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/CGTHREADS:8 /DEBUG:FULL /DEBUGTYPE:FIXUP"
}
},
{
"name": "buildtype-release",
"name": "buildtype-release-msvc",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_FLAGS_RELEASE": "/fp:fast /GR- /Gw /O2 /Ob3 /Qpar",
"CMAKE_SHARED_LINKER_FLAGS_RELEASE": "/CGTHREADS:8 /OPT:ICF=4"
}
},
{
"name": "x64",
"name": "buildtype-debug-clang-cl",
"hidden": true,
"architecture": "x64",
"cacheVariables": {
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/DEBUG:FULL /DEBUGTYPE:FIXUP"
}
},
{
"name": "generator-msvc",
"name": "buildtype-release-clang-cl",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_FLAGS_RELEASE": "/fp:fast /GR- /Gw /O2",
"CMAKE_SHARED_LINKER_FLAGS_RELEASE": "/OPT:ICF=4"
}
},
{
"name": "x64",
"hidden": true,
"architecture": "x64"
},
{
"name": "generator-msvc",
"inherits": "x64",
"hidden": true,
"generator": "Visual Studio 17 2022"
},
{
Expand All @@ -68,47 +77,39 @@
"name": "compiler-msvc",
"hidden": true,
"environment": {
"PROJECT_COMPILER_FLAGS": "/cgthreads8 /diagnostics:caret /fp:contract /fp:except- /guard:cf- /permissive- /Zc:__cplusplus /Zc:enumTypes /Zc:lambda /Zc:preprocessor /Zc:referenceBinding /Zc:rvalueCast /Zc:templateScope /Zc:ternary /Zc:preprocessor /EHsc /MP /W4 /external:anglebrackets /external:W0",
"PROJECT_COMPILER": "msvc"
}
},
{
"name": "compiler-clang",
"hidden": true,
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
},
"environment": {
"PROJECT_COMPILER": "clang",
"PROJECT_COMPILER_FLAGS": "-Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class"
"PROJECT_COMPILER_FLAGS": "/cgthreads8 /diagnostics:caret /EHsc /fp:contract /fp:except- /guard:cf- /MP /permissive- /W4 /Zc:__cplusplus /Zc:enumTypes /Zc:lambda /Zc:preprocessor /Zc:referenceBinding /Zc:rvalueCast /Zc:templateScope /Zc:ternary /external:anglebrackets /external:W0"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-clang-x64"
"intelliSenseMode": "windows-msvc-x64",
"enableMicrosoftCodeAnalysis": true,
"enableClangTidyCodeAnalysis": true
}
}
},
{
"name": "compiler-clang-cl",
"hidden": true,
"inherits": "compiler-clang",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
},
"environment": {
"CC": "clang-cl",
"CXX": "clang-cl",
"PROJECT_COMPILER_FLAGS": "/permissive- /EHsc /W4 -Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class -D__cpp_consteval"
"PROJECT_COMPILER_FLAGS": "/cgthreads8 /diagnostics:caret /EHsc /fp:contract /fp:except- /guard:cf- /permissive- /Zc:__cplusplus /Zc:rvalueCast /Zc:ternary /external:W0 -Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class -Wno-return-type"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-clang-x64",
"enableMicrosoftCodeAnalysis": true,
"enableClangTidyCodeAnalysis": true
}
}
},
{
"name": "build-debug-msvc-msvc",
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-debug",
"buildtype-debug-msvc",
"generator-msvc",
"compiler-msvc"
]
Expand All @@ -118,7 +119,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-debug",
"buildtype-debug-msvc",
"generator-ninja",
"compiler-msvc"
]
Expand All @@ -129,7 +130,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-debug",
"buildtype-debug-clang-cl",
"generator-msvc",
"compiler-clang-cl"
]
Expand All @@ -139,7 +140,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-debug",
"buildtype-debug-clang-cl",
"generator-ninja",
"compiler-clang-cl"
]
Expand All @@ -149,7 +150,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-release",
"buildtype-release-msvc",
"generator-msvc",
"compiler-msvc"
]
Expand All @@ -159,7 +160,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-release",
"buildtype-release-msvc",
"generator-ninja",
"compiler-msvc"
]
Expand All @@ -170,7 +171,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-release",
"buildtype-release-clang-cl",
"generator-msvc",
"compiler-clang-cl"
]
Expand All @@ -180,7 +181,7 @@
"inherits": [
"common",
"packaging-vcpkg",
"buildtype-release",
"buildtype-release-clang-cl",
"generator-ninja",
"compiler-clang-cl"
]
Expand Down

0 comments on commit d77646e

Please sign in to comment.