diff options
author | Aki <please@ignore.pl> | 2023-01-28 16:54:36 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-01-28 17:05:40 +0100 |
commit | e3fbcfc085411475cb07da84308f03dbd3405e5e (patch) | |
tree | 1fd0cdc7e8b8f90b032973dca983200b4d273998 | |
parent | 161f92d0cf6982e605a7ec1be6eb19dc60951c45 (diff) | |
download | kurator-e3fbcfc085411475cb07da84308f03dbd3405e5e.zip kurator-e3fbcfc085411475cb07da84308f03dbd3405e5e.tar.gz kurator-e3fbcfc085411475cb07da84308f03dbd3405e5e.tar.bz2 |
Commits will now trigger version-files regeneration during build
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | cmake/modules/AddVersionFile.cmake | 15 | ||||
-rw-r--r-- | cmake/modules/GitRevParse.cmake | 14 | ||||
-rw-r--r-- | cmake/modules/generate_version_file.cmake | 12 | ||||
-rw-r--r-- | kurator/CMakeLists.txt | 2 | ||||
-rw-r--r-- | kurator/src/version.cpp.conf | 2 | ||||
-rw-r--r-- | version.txt.conf | 2 |
7 files changed, 33 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fe35ab7..79eae9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,12 @@ find_package(EnTT 3 REQUIRED) find_package(nlohmann_json 3 REQUIRED) find_package(raylib 4 REQUIRED) include(AddResources) -include(GitRevParse) -git_rev_parse(KURATOR_VERSION) +include(AddVersionFile) add_subdirectory(campaign) add_subdirectory(contrib) add_subdirectory(kurator) add_subdirectory(sim) add_subdirectory(stats) add_subdirectory(universe) -configure_file(version.txt.conf "${CMAKE_CURRENT_BINARY_DIR}/version.txt" @ONLY) +add_version_file(version.txt version.txt.conf) +add_custom_target(version ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/version.txt") diff --git a/cmake/modules/AddVersionFile.cmake b/cmake/modules/AddVersionFile.cmake new file mode 100644 index 0000000..1cce0b9 --- /dev/null +++ b/cmake/modules/AddVersionFile.cmake @@ -0,0 +1,15 @@ +set(ADD_VERSION_FILE_DIR "${CMAKE_CURRENT_LIST_DIR}") + +function(add_version_file OUTPUT TEMPLATE) + add_custom_target( + ${OUTPUT} + BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND + cmake + -DOUTPUT='${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT}' + -DTEMPLATE='${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE}' + -P "${ADD_VERSION_FILE_DIR}/generate_version_file.cmake" + ) +endfunction() diff --git a/cmake/modules/GitRevParse.cmake b/cmake/modules/GitRevParse.cmake deleted file mode 100644 index 9005d65..0000000 --- a/cmake/modules/GitRevParse.cmake +++ /dev/null @@ -1,14 +0,0 @@ -function(git_rev_parse VAR) - execute_process( - COMMAND git rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE PARSE_RESULT - OUTPUT_VARIABLE PARSE_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NOT PARSE_RESULT) - set(${VAR} ${PARSE_OUTPUT} PARENT_SCOPE) - else() - set(${VAR} "Unknown" PARENT_SCOPE) - endif() -endfunction() diff --git a/cmake/modules/generate_version_file.cmake b/cmake/modules/generate_version_file.cmake new file mode 100644 index 0000000..4479855 --- /dev/null +++ b/cmake/modules/generate_version_file.cmake @@ -0,0 +1,12 @@ +execute_process( + COMMAND git rev-parse --short HEAD + RESULT_VARIABLE PARSE_RESULT + OUTPUT_VARIABLE PARSE_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE +) +if(NOT PARSE_RESULT) + set(HASH "${PARSE_OUTPUT}") +else() + set(HASH "NOTFOUND") +endif() +configure_file("${TEMPLATE}" "${OUTPUT}" @ONLY) diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 7add534..e2e4821 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -27,7 +27,7 @@ target_link_libraries( PRIVATE stats PRIVATE universe ) -configure_file(src/version.cpp.conf "${CMAKE_CURRENT_BINARY_DIR}/version.cpp" @ONLY) +add_version_file(version.cpp src/version.cpp.conf) target_sources( ${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/version.cpp" diff --git a/kurator/src/version.cpp.conf b/kurator/src/version.cpp.conf index a6d0aa0..a389f23 100644 --- a/kurator/src/version.cpp.conf +++ b/kurator/src/version.cpp.conf @@ -2,7 +2,7 @@ namespace kurator { -const char* VERSION {"@KURATOR_VERSION@"}; +const char* VERSION {"@HASH@"}; } // namespace kurator diff --git a/version.txt.conf b/version.txt.conf index 926d433..cc0fa45 100644 --- a/version.txt.conf +++ b/version.txt.conf @@ -1 +1 @@ -@KURATOR_VERSION@ +@HASH@ |