diff --git a/CMakeLists.txt b/CMakeLists.txt index f69beabe119..80c3b5d718d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ else () endif () find_package(Git) +set(GIT_COMMIT_HASH "0000000") if(DEFINED ENV{git_commit_hash} AND NOT "$ENV{git_commit_hash}" STREQUAL "") message(STATUS "Specified git commit hash: $ENV{git_commit_hash}") if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") @@ -99,7 +100,6 @@ if(DEFINED ENV{git_commit_hash} AND NOT "$ENV{git_commit_hash}" STREQUAL "") # No .git directory (e.g., Flatpak sandbox) — truncate directly string(SUBSTRING "$ENV{git_commit_hash}" 0 7 GIT_COMMIT_HASH) endif() - add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") elseif(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") # Check current Git commit hash execute_process( @@ -108,7 +108,6 @@ elseif(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ) - add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") endif() if(DEFINED ENV{SLIC3R_STATIC}) diff --git a/cmake/GenerateSoftFeverVersion.cmake b/cmake/GenerateSoftFeverVersion.cmake index cfe8ca0bb57..e6cc7de9074 100644 --- a/cmake/GenerateSoftFeverVersion.cmake +++ b/cmake/GenerateSoftFeverVersion.cmake @@ -6,6 +6,10 @@ if(NOT DEFINED OUTPUT) message(FATAL_ERROR "OUTPUT is required") endif() +if(NOT DEFINED GIT_COMMIT_HASH) + set(GIT_COMMIT_HASH "0000000") +endif() + file(STRINGS "${INPUT}" SOFTFEVER_VERSION LIMIT_COUNT 1) string(STRIP "${SOFTFEVER_VERSION}" SOFTFEVER_VERSION) @@ -19,6 +23,11 @@ const char* softfever_version() return "@SOFTFEVER_VERSION@"; } +const char* git_commit_hash() +{ + return "@GIT_COMMIT_HASH@"; +} + } // namespace Slic3r ]=]) string(CONFIGURE "${CONTENT}" CONTENT @ONLY) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index ae9f292ccd9..232925e3362 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -14,6 +14,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} "-DINPUT=${SOFTFEVER_VERSION_FILE}" "-DOUTPUT=${LIBSLIC3R_VERSION_CPP}" + "-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}" -P "${CMAKE_SOURCE_DIR}/cmake/GenerateSoftFeverVersion.cmake" DEPENDS "${SOFTFEVER_VERSION_FILE}" "${CMAKE_SOURCE_DIR}/cmake/GenerateSoftFeverVersion.cmake" VERBATIM diff --git a/src/libslic3r/libslic3r_version.h.in b/src/libslic3r/libslic3r_version.h.in index 0b7bc1c07ef..1e4de209c04 100644 --- a/src/libslic3r/libslic3r_version.h.in +++ b/src/libslic3r/libslic3r_version.h.in @@ -5,10 +5,9 @@ #define SLIC3R_APP_KEY "@SLIC3R_APP_KEY@" #define SLIC3R_VERSION "@SLIC3R_VERSION@" namespace Slic3r { const char* softfever_version(); } +namespace Slic3r { const char* git_commit_hash(); } #define SoftFever_VERSION (Slic3r::softfever_version()) -#ifndef GIT_COMMIT_HASH - #define GIT_COMMIT_HASH "0000000" // 0000000 means uninitialized -#endif +#define GIT_COMMIT_HASH (Slic3r::git_commit_hash()) #define SLIC3R_BUILD_ID "@SLIC3R_BUILD_ID@" //#define SLIC3R_RC_VERSION "@SLIC3R_VERSION@" #define BBL_INTERNAL_TESTING @BBL_INTERNAL_TESTING@