From be2865381df458f6510fa98250e39246487cb625 Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:22:32 +0100 Subject: [PATCH 1/8] Document MSVC.cmake a bit more --- build-scripts/MSVC.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build-scripts/MSVC.cmake b/build-scripts/MSVC.cmake index 458176b9ae97b..b0b7ddd68f684 100644 --- a/build-scripts/MSVC.cmake +++ b/build-scripts/MSVC.cmake @@ -48,6 +48,21 @@ Linker flags used by all builds: /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 +CMAKE_CXX_FLAGS_RELWITHDEBINFO=/Zi /O2 /Ob1 /DNDEBUG +CMAKE_EXE_LINKER_FLAGS=/machine:x64 +CMAKE_EXE_LINKER_FLAGS_DEBUG=/debug /INCREMENTAL +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO=/debug /INCREMENTAL + +Use the following for Dr. Memory: +/Zi or /ZI +/DEBUG:FULL +/Ob0 disable inlining +/Oy- don't omit frame pointers +Remove /RTC1 + #]=======================================================================] # Path has changed, so this configure run will find cl.exe @@ -61,6 +76,7 @@ set(CMAKE_CXX_FLAGS_INIT "\ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/Oi" ) + add_compile_definitions( _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS @@ -68,6 +84,7 @@ add_compile_definitions( LOCALIZE USE_VCPKG ) + add_link_options( /OPT:REF /OPT:ICF From a7ebd46a585cdfa1123fd290a5bc7437e0b9b199 Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:23:02 +0100 Subject: [PATCH 2/8] Do not always update version.h timestamp --- src/version.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/version.cmake b/src/version.cmake index de557a957102d..2ac18d914ba8b 100644 --- a/src/version.cmake +++ b/src/version.cmake @@ -1,4 +1,6 @@ -file(TOUCH ${CMAKE_SOURCE_DIR}/src/version.h) +if(NOT EXISTS ${CMAKE_SOURCE_DIR}/src/version.h) + file(TOUCH ${CMAKE_SOURCE_DIR}/src/version.h) +endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules) From 8758a6f3231efa49433ec95e28386c7295b4b095 Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:24:36 +0100 Subject: [PATCH 3/8] Add LLVM toolchain for Windows --- CMakePresets.json | 21 ++++++++++++-- build-scripts/LLVM.cmake | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 build-scripts/LLVM.cmake diff --git a/CMakePresets.json b/CMakePresets.json index 52c38460a4390..14028410c4329 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -30,10 +30,21 @@ "cacheVariables": { "CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/${presetName}.cmake", "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build-scripts/MSVC.cmake", + { + "name": "windows-tiles-sounds-x64-llvm", + "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", + "environment": { + "VCPKG_ROOT": "C:/vcpkg" + }, + "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", - "DYNAMIC_LINKING": "False", - "CURSES": "False", "LOCALIZE": "True", "TILES": "True", "SOUND": "True", "TESTS": "True", - "CMAKE_INSTALL_MESSAGE": "NEVER" + "VCPKG_APPLOCAL_DEPS": "False" } }, { @@ -80,6 +91,10 @@ { "name": "windows-tiles-sounds-x64-msvc", "configurePreset": "windows-tiles-sounds-x64-msvc" + }, + { + "name": "windows-tiles-sounds-x64-llvm", + "configurePreset": "windows-tiles-sounds-x64-llvm" } ], "testPresets": [ diff --git a/build-scripts/LLVM.cmake b/build-scripts/LLVM.cmake new file mode 100644 index 0000000000000..e2bb36ce07cb5 --- /dev/null +++ b/build-scripts/LLVM.cmake @@ -0,0 +1,60 @@ +#[=======================================================================[ + +LLVM +---- + +Toolchain file for LLVM CLANG on Windows + +Used by CMakePresets.json -> "toolchainFile". + +Using clang-cl.exe so we can copy MSVC.cmake flags over here. + +Refer to MSVC.cmake documentation + +#]=======================================================================] + +set(CMAKE_C_COMPILER "${LLVM_ROOT}/bin/clang-cl.exe") +set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_RC_COMPILER "${LLVM_ROOT}/bin/llvm-rc.exe") +set(CMAKE_MT "${LLVM_ROOT}/bin/llvm-mt.exe") +set(CMAKE_OBJDUMP "${LLVM_ROOT}/bin/llvm-objdump.exe") + +set(CMAKE_CXX_FLAGS_INIT "\ +/utf-8 /bigobj /permissive- /sdl- /FC /Gd /GS- /Gy /GF \ +/wd4068 /wd4146 /wd4661 /wd4819 /wd6237 /wd6319 /wd26444 /wd26451 /wd26495 /WX- /W1 \ +/Zc:forScope /Zc:inline /Zc:wchar_t" +) +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT +"/Oi" +) + +add_compile_definitions( + _SCL_SECURE_NO_WARNINGS + _CRT_SECURE_NO_WARNINGS + WIN32_LEAN_AND_MEAN + LOCALIZE + USE_VCPKG +) + +add_link_options( + /OPT:REF + /OPT:ICF + /LTCG:OFF + /INCREMENTAL:NO + /DYNAMICBASE + /NXCOMPAT + "$<$:/NODEFAULTLIB:LIBCMT>" + "$<$:/NODEFAULTLIB:LIBCMTD>" +) + +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + +# Where is vcpkg.json ? +set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/msvc-full-features) + +set(VCPKG_ROOT "" CACHE PATH "Path to VCPKG installation") +if (NOT $ENV{VCPKG_ROOT} STREQUAL "") + include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) +elseif(NOT $CACHE{VCPKG_ROOT} STREQUAL "") + include($CACHE{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) +endif() From 2816f434c41aee471d48d710f67f434e5b9dc47a Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:24:54 +0100 Subject: [PATCH 4/8] Use inheritance in CMakePresets.json --- CMakePresets.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakePresets.json b/CMakePresets.json index 14028410c4329..461cf714de61e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -24,12 +24,16 @@ "displayName": "Windows Tiles Sounds x64 MSVC", "description": "Target Windows (64-bit) with the Visual Studio development environment.", "generator": "Visual Studio 16 2019", + "inherits": "windows-tiles-sounds-x64", "environment": { "VCPKG_ROOT": "C:/vcpkg" }, "cacheVariables": { "CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/${presetName}.cmake", "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build-scripts/MSVC.cmake", + "VCPKG_TARGET_TRIPLET": "x64-windows-static" + } + }, { "name": "windows-tiles-sounds-x64-llvm", "binaryDir": "${sourceDir}/out/build/${presetName}", From 1191a08a3f59f40239647fb4059b9a283b29bd29 Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:25:30 +0100 Subject: [PATCH 5/8] Fix linking MSVC debug run-time libraries --- build-scripts/MSVC.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build-scripts/MSVC.cmake b/build-scripts/MSVC.cmake index b0b7ddd68f684..3fe220117c410 100644 --- a/build-scripts/MSVC.cmake +++ b/build-scripts/MSVC.cmake @@ -92,9 +92,11 @@ add_link_options( /INCREMENTAL:NO /DYNAMICBASE /NXCOMPAT + "$<$:/NODEFAULTLIB:LIBCMT>" + "$<$:/NODEFAULTLIB:LIBCMTD>" ) -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded") +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # Where is vcpkg.json ? set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/msvc-full-features) From c26363a8441ce01f728f449356f02c5cbcef467c Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:26:28 +0100 Subject: [PATCH 6/8] Simply don't ask link.exe to autogenerate manifests --- src/CMakeLists.txt | 5 ++--- src/resource.rc | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ebf562b409973..6e18c5b626adf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,10 +51,9 @@ if (TILES) # /MANIFESTINPUT not supported by GNU linker # Defaul embed via `windres.exe` compiling `resource.rc` -> `resource.rc.obj` else() - # Embed manifest directly to avoid: - # "fatal error CVT1100: duplicate resource. type:MANIFEST, name:1, language:0x0409" + # Use only our RT_MANIFEST from resource.rc target_link_options(cataclysm-tiles PRIVATE - "LINKER:/MANIFESTINPUT:${CMAKE_SOURCE_DIR}/data/application_manifest.xml" + "LINKER:/MANIFEST:NO" ) endif() else () diff --git a/src/resource.rc b/src/resource.rc index 4502a26cd3831..753f317b0e251 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -3,10 +3,6 @@ #include 0 ICON "../data/cataicon.ico" -#if defined(CMAKE) && !defined(MSYS2) - // Will embed it with MSVC' linker /MANIFESTINPUT: -#else 1 RT_MANIFEST "../data/application_manifest.xml" -#endif #endif // RESOURCE_RC_INCLUDED From fda4a4b70eaaa72f3b35186f307f2022922a9a81 Mon Sep 17 00:00:00 2001 From: alef Date: Mon, 12 Feb 2024 10:27:09 +0100 Subject: [PATCH 7/8] Strip MSYS/MINGW executable, like done in Makefile --- src/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e18c5b626adf..2c52276d32f4b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,8 +48,9 @@ if (TILES) ${MESSAGES_CPP} ${RESOURCE_RC}) if(MSYS2) - # /MANIFESTINPUT not supported by GNU linker - # Defaul embed via `windres.exe` compiling `resource.rc` -> `resource.rc.obj` + target_link_options(cataclysm-tiles PRIVATE + "LINKER:--strip-debug" + ) else() # Use only our RT_MANIFEST from resource.rc target_link_options(cataclysm-tiles PRIVATE From 93c7bffcf438bc47ad4290d0479eb88d2f6a33ec Mon Sep 17 00:00:00 2001 From: alef Date: Thu, 15 Feb 2024 22:30:34 +0100 Subject: [PATCH 8/8] Remove MINGW debug only for debug builds --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c52276d32f4b..49eae3a29fb90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,7 +49,7 @@ if (TILES) ${RESOURCE_RC}) if(MSYS2) target_link_options(cataclysm-tiles PRIVATE - "LINKER:--strip-debug" + "$<$:LINKER:--strip-debug>" ) else() # Use only our RT_MANIFEST from resource.rc