From d77646ed709df9bd491d907f17f22f32298d096b Mon Sep 17 00:00:00 2001 From: Angad <66992519+ThirdEyeSqueegee@users.noreply.github.com> Date: Fri, 15 Sep 2023 21:48:25 -0700 Subject: [PATCH] chore: some CMakeLists and CMakePresets tweaks/fixes (#57) 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 --- CommonLibSF/CMakeLists.txt | 3 +- CommonLibSF/CMakePresets.json | 99 ++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/CommonLibSF/CMakeLists.txt b/CommonLibSF/CMakeLists.txt index 9176bc0b..a8d31b35 100644 --- a/CommonLibSF/CMakeLists.txt +++ b/CommonLibSF/CMakeLists.txt @@ -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) @@ -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( @@ -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 diff --git a/CommonLibSF/CMakePresets.json b/CommonLibSF/CMakePresets.json index beea7e80..11659a4c 100644 --- a/CommonLibSF/CMakePresets.json +++ b/CommonLibSF/CMakePresets.json @@ -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$<$: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$<$: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" }, { @@ -68,39 +77,31 @@ "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 + } } }, { @@ -108,7 +109,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-debug", + "buildtype-debug-msvc", "generator-msvc", "compiler-msvc" ] @@ -118,7 +119,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-debug", + "buildtype-debug-msvc", "generator-ninja", "compiler-msvc" ] @@ -129,7 +130,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-debug", + "buildtype-debug-clang-cl", "generator-msvc", "compiler-clang-cl" ] @@ -139,7 +140,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-debug", + "buildtype-debug-clang-cl", "generator-ninja", "compiler-clang-cl" ] @@ -149,7 +150,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-release", + "buildtype-release-msvc", "generator-msvc", "compiler-msvc" ] @@ -159,7 +160,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-release", + "buildtype-release-msvc", "generator-ninja", "compiler-msvc" ] @@ -170,7 +171,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-release", + "buildtype-release-clang-cl", "generator-msvc", "compiler-clang-cl" ] @@ -180,7 +181,7 @@ "inherits": [ "common", "packaging-vcpkg", - "buildtype-release", + "buildtype-release-clang-cl", "generator-ninja", "compiler-clang-cl" ]