diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d3fd3582c..25ac79164 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -201,9 +201,7 @@ jobs: run: | # sccache can only cache MSVC objects when the debug information is embedded # in them (/Z7) instead of collected in a shared PDB (/Zi, the CMake default) - cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DApplications="$Env:JA2Application" ` - -DCMAKE_POLICY_DEFAULT_CMP0141=NEW -DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded ` - -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DApplications="$Env:JA2Application" - name: Build run: | cmake --build build/ -- -v diff --git a/CMakeLists.txt b/CMakeLists.txt index 511cb0e47..f31cb25dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,23 @@ cmake_minimum_required(VERSION 3.20) +# /Z7 embedded debug info so objects are self-contained and sccache-able. +# CMP0141 is a 3.25 policy; our floor is 3.20, so opt in explicitly where known. +if(POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) +endif() + project(ja2) +option(USE_SCCACHE "Cache compiled objects with sccache if installed" ON) +if(USE_SCCACHE) + find_program(SCCACHE_PROGRAM sccache) + if(SCCACHE_PROGRAM) + message(STATUS "Using sccache: ${SCCACHE_PROGRAM}") + set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}") + set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}") + endif() +endif() + include(cmake/CopyUserPresetTemplate.cmake) CopyUserPresetTemplate() @@ -40,6 +56,9 @@ set(usingMsBuild $) # lua51.lib and lua51.vc9.lib have been built with /MTx, so we must as well # TODO: build our own Lua 5.1.2 from source so we can use whichever set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +# make Debug builds /Z7 instead of /Zi so they can be sccache'd +set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT + "$<$:Embedded>") add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP _CRT_SECURE_NO_DEPRECATE) include_directories(