Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for setting git version externally #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,37 @@ if(MINIMAL)
add_definitions(-DTINI_MINIMAL=1)
endif()

# Extract git version and dirty-ness
execute_process (
COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" log -n 1 --date=local --pretty=format:%h
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE git_version_check_ret
OUTPUT_VARIABLE tini_VERSION_GIT
)

execute_process(
COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" status --porcelain --untracked-files=no
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE git_dirty_check_out
)

if("${git_version_check_ret}" EQUAL 0)
set(tini_VERSION_GIT " - git.${tini_VERSION_GIT}")
if(NOT "${git_dirty_check_out}" STREQUAL "")
set(tini_VERSION_GIT "${tini_VERSION_GIT}-dirty")
endif()
# Set the git version
if (NOT "${TINI_VERSION_GIT}" STREQUAL "")
# Set by the user directly
set(tini_VERSION_GIT "${TINI_VERSION_GIT}")
else()
set(tini_VERSION_GIT "")
# Extract git version
execute_process (
COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" log -n 1 --date=local --pretty=format:%h
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
RESULT_VARIABLE git_version_check_ret
OUTPUT_VARIABLE tini_VERSION_GIT
)

if("${git_version_check_ret}" EQUAL 0)
# Extract git dirty-ness
execute_process(
COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" status --porcelain --untracked-files=no
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE git_dirty_check_out
)

if(NOT "${git_dirty_check_out}" STREQUAL "")
set(tini_VERSION_GIT "${tini_VERSION_GIT}-dirty")
endif()
else()
set(tini_VERSION_GIT "")
endif()
endif()

if(NOT ${tini_VERSION_GIT} STREQUAL "")
set(tini_VERSION_GIT " - git.${tini_VERSION_GIT}")
endif()

# Flags
Expand Down