Skip to content

Commit

Permalink
CMake: Skip fetching git information that is not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed May 7, 2021
1 parent 7b12867 commit 76641c5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ get_target_property(MIXXX_BUILD_FLAGS mixxx-lib COMPILE_OPTIONS)
configure_file(src/buildinfo.h.in src/buildinfo.h @ONLY)

add_custom_target(mixxx-gitinfo
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/src/gitinfo.h.in" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/src/gitinfo.h" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/gitinfo.cmake"
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/src/gitinfo.h.in" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/src/gitinfo.h" -DSKIP_GIT_COMMIT_COUNT=ON -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/gitinfo.cmake"
COMMENT "Update git version information in gitinfo.h"
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/src/gitinfo.h"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down Expand Up @@ -1649,7 +1649,7 @@ if(WIN32)
@ONLY
)
add_custom_target(mixxx-rc-gitinfo
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/src/mixxxgitinfo.rc.include.template" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/src/mixxxgitinfo.rc.include" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/gitinfo.cmake"
COMMAND ${CMAKE_COMMAND} -DINPUT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/src/mixxxgitinfo.rc.include.template" -DOUTPUT_FILE="${CMAKE_CURRENT_BINARY_DIR}/src/mixxxgitinfo.rc.include" -DSKIP_GIT_BRANCH=ON -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/gitinfo.cmake"
COMMENT "Update git version information in Windows RC file"
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/src/mixxxgitinfo.rc.include"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
82 changes: 44 additions & 38 deletions cmake/modules/GitInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,52 @@ else()
endif()
endif()

# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_BRANCH)
message(NOTICE "Git branch: unknown")
else()
message(NOTICE "Git branch: ${GIT_BRANCH}")
if(NOT SKIP_GIT_BRANCH)
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_BRANCH)
message(NOTICE "Git branch: unknown")
else()
message(NOTICE "Git branch: ${GIT_BRANCH}")
endif()
endif()

# Get the current commit date
execute_process(
COMMAND git show --quiet --format=%cI --date=short
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_COMMIT_DATE)
message(NOTICE "Git commit date: unknown")
else()
message(NOTICE "Git commit date: ${GIT_COMMIT_DATE}")
string(REGEX MATCH "^[0-9][0-9][0-9][0-9]" GIT_COMMIT_YEAR "${GIT_COMMIT_DATE}")
message(NOTICE "Git commit year: ${GIT_COMMIT_YEAR}")
if(NOT SKIP_GIT_COMMIT_DATE)
# Get the current commit date
execute_process(
COMMAND git show --quiet --format=%cI --date=short
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_COMMIT_DATE)
message(NOTICE "Git commit date: unknown")
else()
message(NOTICE "Git commit date: ${GIT_COMMIT_DATE}")
string(REGEX MATCH "^[0-9][0-9][0-9][0-9]" GIT_COMMIT_YEAR "${GIT_COMMIT_DATE}")
message(NOTICE "Git commit year: ${GIT_COMMIT_YEAR}")
endif()
endif()

# Get the number of commits on the working branch
execute_process(
COMMAND git rev-list --count --first-parent HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_COMMIT_COUNT)
message(NOTICE "Git commit count: unknown")
else()
message(NOTICE "Git commit count: ${GIT_COMMIT_COUNT}")
if(NOT SKIP_GIT_COMMIT_COUNT)
# Get the number of commits on the working branch
execute_process(
COMMAND git rev-list --count --first-parent HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_COMMIT_COUNT)
message(NOTICE "Git commit count: unknown")
else()
message(NOTICE "Git commit count: ${GIT_COMMIT_COUNT}")
endif()
endif()
4 changes: 4 additions & 0 deletions cmake/scripts/gitinfo.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
option(SKIP_GIT_BRANCH "Skip retrieving the current git branch." OFF)
option(SKIP_GIT_COMMIT_DATE "Skip retrieving the current git commit's date." OFF)
option(SKIP_GIT_COMMIT_COUNT "Skip retrieving the current git commit count." OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(GitInfo)
configure_file("${INPUT_FILE}" "${OUTPUT_FILE}" @ONLY)
2 changes: 2 additions & 0 deletions packaging/CPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# unlike CMakeLists.txt this file is include at cpack time, once per generator after CPack has set CPACK_GENERATOR
# to the actual generator being used. It allows per-generator setting of CPACK_* variables at cpack time.
set(CMAKE_CURRENT_SOURCE_DIR "${CPACK_SOURCE_DIR}")

set(SKIP_GIT_COMMIT_COUNT ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(GitInfo)

Expand Down

0 comments on commit 76641c5

Please sign in to comment.