Skip to content
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

CMake: Add LLVM build for Windows and other linker fixes #71713

Merged
merged 8 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,31 @@
"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}",
"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"
}
},
{
Expand Down Expand Up @@ -80,6 +95,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": [
Expand Down
60 changes: 60 additions & 0 deletions build-scripts/LLVM.cmake
Original file line number Diff line number Diff line change
@@ -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
"$<$<CONFIG:Debug>:/NODEFAULTLIB:LIBCMT>"
"$<$<CONFIG:RelWithDebInfo>:/NODEFAULTLIB:LIBCMTD>"
)

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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()
21 changes: 20 additions & 1 deletion build-scripts/MSVC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -61,23 +76,27 @@ set(CMAKE_CXX_FLAGS_INIT "\
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
"$<$<CONFIG:Debug>:/NODEFAULTLIB:LIBCMT>"
"$<$<CONFIG:RelWithDebInfo>:/NODEFAULTLIB:LIBCMTD>"
)

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

# Where is vcpkg.json ?
set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/msvc-full-features)
Expand Down
10 changes: 5 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ 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
"$<$<CONFIG:Debug,RelWithDebInfo>:LINKER:--strip-debug>"
alef marked this conversation as resolved.
Show resolved Hide resolved
)
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 ()
Expand Down
4 changes: 0 additions & 4 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#include <windows.h>
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
4 changes: 3 additions & 1 deletion src/version.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Loading