From 5395194ed6d2513027701ca12c231cb13971596c Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 27 Dec 2022 00:35:57 -0800 Subject: [PATCH] cmake: generate config.h at build time, always rebuild comptime.c --- cmake/Comptime.cmake | 13 +++++++++++++ src/CMakeLists.txt | 26 ++++++++++++++++++++++++++ src/d_main.c | 7 +------ src/sdl/i_system.c | 6 ------ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 cmake/Comptime.cmake diff --git a/cmake/Comptime.cmake b/cmake/Comptime.cmake new file mode 100644 index 000000000..c6d64efa3 --- /dev/null +++ b/cmake/Comptime.cmake @@ -0,0 +1,13 @@ +set(CMAKE_BINARY_DIR "${BINARY_DIR}") +set(CMAKE_CURRENT_BINARY_DIR "${BINARY_DIR}") + +# Set up CMAKE path +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") + +include(GitUtilities) + +git_current_branch(SRB2_COMP_BRANCH) +git_summary(SRB2_COMP_REVISION) +git_working_tree_dirty(SRB2_COMP_UNCOMMITTED) + +configure_file(src/config.h.in src/config.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 318c9cb7e..9725b792a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,6 +132,32 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 k_roulette.c ) +# This updates the modification time for comptime.c at the +# end of building so when the build system is ran next time, +# that file gets flagged. comptime.c will always be rebuilt. +# +# This begs the question, why always rebuild comptime.c? +# Some things like the git commit must be checked each time +# the program is built. But the build system determines which +# files should be rebuilt before anything else. So +# comptime.c, which only needs to be rebuilt based on +# information known at build time, must be told to rebuild +# before that information can be ascertained. +add_custom_command( + TARGET SRB2SDL2 + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_BINARY_DIR}/comptime.c +) + +# config.h is generated by this command. It should be done at +# build time for accurate git information and before anything +# that needs it, obviously. +add_custom_target(_SRB2_reconf ALL + COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/.. -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Comptime.cmake + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.." +) +add_dependencies(SRB2SDL2 _SRB2_reconf) + if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase") if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") diff --git a/src/d_main.c b/src/d_main.c index 7b0d2a4f6..392a45ece 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -77,12 +77,6 @@ #include "m_random.h" // P_ClearRandom #include "k_specialstage.h" -#ifdef CMAKECONFIG -#include "config.h" -#else -#include "config.h.in" -#endif - #ifdef HWRENDER #include "hardware/hw_main.h" // 3D View Rendering #endif @@ -1446,6 +1440,7 @@ void D_SRB2Main(void) mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_PK3); // maps.pk3 -- 4 - If you touch this, make sure to touch up the majormods stuff below. mainwads++; W_VerifyFileMd5(mainwads, ASSET_HASH_FOLLOWERS_PK3); // followers.pk3 #ifdef USE_PATCH_FILE + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_PK3); // patch.pk3 #endif #else diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 707d20427..b390b6d1e 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -23,12 +23,6 @@ /// \file /// \brief SRB2 system stuff for SDL -#ifdef CMAKECONFIG -#include "config.h" -#else -#include "../config.h.in" -#endif - #include #ifdef _WIN32