diff --git a/CMakeLists.txt b/CMakeLists.txt index dd7c29f..5479804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,42 @@ set(PROJECT_DATE 2023-11-24) math(EXPR PROJECT_VERSION_CODE 100000*${PROJECT_VERSION_MAJOR}+1000*${PROJECT_VERSION_MINOR}+${PROJECT_VERSION_PATCH}) add_definitions( -DPROJECT_VERSION="${PROJECT_VERSION}" ) +# Find GIT repository data. +if (EXISTS ${CMAKE_SOURCE_DIR}/.git) + # Get the current working branch + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message("Currently working with git branch ${GIT_BRANCH}") + + # Get the latest abbreviated commit hash of the working branch + execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message("Currently working with git Commit ${GIT_COMMIT}") + + # Get the latest commit date of the working branch + execute_process( + COMMAND git log -1 --format=%as + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DATE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message("Currently working with git commit from ${GIT_DATE}") +else() + message("Not working from a GIT directory") + set(GIT_BRANCH "") + set(GIT_COMMIT "") + set(GIT_DATE "") +endif() +add_compile_definitions(GIT_COMMIT="${GIT_COMMIT}") + if(IOS) set(PRODUCT_BUNDLE_IDENTIFIER de.akafliegfreiburg.addhoursandminutes)