Compare commits
2 Commits
6c6f48c468
...
d8c4257a0c
Author | SHA1 | Date | |
---|---|---|---|
d8c4257a0c | |||
5651a4767e |
@ -50,6 +50,7 @@ include(CMLibDocDoxygen)
|
||||
include(CMLibDocBreathe)
|
||||
include(CMLibQtTranslation)
|
||||
include(CMLibToday)
|
||||
include(CMLibGit)
|
||||
include(CMLibAuxilarySymlinks)
|
||||
include(CMLibGeneratePrivateConfigHPP)
|
||||
include(CMLibNinjaGeneratorHelper)
|
||||
|
14
CMLibGit.cmake
Normal file
14
CMLibGit.cmake
Normal file
@ -0,0 +1,14 @@
|
||||
set(output_file ${CMAKE_BINARY_DIR}/include/cmlib_git_version.hpp)
|
||||
if(CMLIB_GENERATED_HEADERS_PATH)
|
||||
set(output_file ${CMLIB_GENERATED_HEADERS_PATH}/cmlib_git_version.hpp)
|
||||
elseif(ARGV0)
|
||||
set(output_file ${ARGV0})
|
||||
endif()
|
||||
|
||||
add_custom_target(git-version ALL ${CMAKE_COMMAND}
|
||||
-DCMLIB_PROJECT_NAME_UPPER=${CMLIB_PROJECT_NAME_UPPER}
|
||||
-DCMLIB_MODULE_DIR=${CMLIB_MODULE_DIR}
|
||||
-DCMLIB_GIT_VERSION_FILE=${output_file} -P ${CMLIB_MODULE_DIR}/CMLibGitVersion.cmake
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
|
||||
unset(output_file)
|
28
CMLibGitVersion.cmake
Normal file
28
CMLibGitVersion.cmake
Normal file
@ -0,0 +1,28 @@
|
||||
set(CMLIB_GIT_REV "N/A")
|
||||
set(CMLIB_GIT_DIFF "")
|
||||
set(CMLIB_GIT_TAG "N/A")
|
||||
set(CMLIB_GIT_BRANCH "N/A")
|
||||
|
||||
message("aaaaaa")
|
||||
|
||||
find_program(GIT_EXECUTABLE git)
|
||||
if(GIT_EXECUTABLE)
|
||||
execute_process(COMMAND git log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE CMLIB_GIT_REV ERROR_QUIET)
|
||||
|
||||
# Check whether we got any revision (which isn't
|
||||
# always the case, e.g. when someone downloaded a zip
|
||||
# file from Github instead of a checkout)
|
||||
if(NOT "${CMLIB_GIT_REV}" STREQUAL "")
|
||||
execute_process(COMMAND bash -c "git diff --quiet --exit-code || echo +" OUTPUT_VARIABLE CMLIB_GIT_DIFF)
|
||||
execute_process(COMMAND git describe --exact-match --tags OUTPUT_VARIABLE CMLIB_GIT_TAG ERROR_QUIET)
|
||||
execute_process(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE CMLIB_GIT_BRANCH)
|
||||
|
||||
string(STRIP "${CMLIB_GIT_REV}" CMLIB_GIT_REV)
|
||||
string(SUBSTRING "${CMLIB_GIT_REV}" 1 8 CMLIB_GIT_REV)
|
||||
string(STRIP "${CMLIB_GIT_DIFF}" CMLIB_GIT_DIFF)
|
||||
string(STRIP "${CMLIB_GIT_TAG}" CMLIB_GIT_TAG)
|
||||
string(STRIP "${CMLIB_GIT_BRANCH}" CMLIB_GIT_BRANCH)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
configure_file(${CMLIB_MODULE_DIR}/hpp/cmlib_git_version.hpp.in ${CMLIB_GIT_VERSION_FILE})
|
31
hpp/cmlib_git_version.hpp.in
Normal file
31
hpp/cmlib_git_version.hpp.in
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef @CMLIB_PROJECT_NAME_UPPER@_CMLIB_GIT_VERSION_HPP_
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_CMLIB_GIT_VERSION_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined (@CMLIB_PROJECT_NAME_UPPER@_GIT_REV)
|
||||
#error "Duplicate definition of macros @CMLIB_PROJECT_NAME_UPPER@_GIT_REV"
|
||||
#else
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_GIT_REV "@CMLIB_GIT_REV@"
|
||||
#endif
|
||||
|
||||
#if defined (@CMLIB_PROJECT_NAME_UPPER@_GIT_DIFF)
|
||||
#error "Duplicate definition of macros @CMLIB_PROJECT_NAME_UPPER@_GIT_DIFF"
|
||||
#else
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_GIT_DIFF "@CMLIB_GIT_DIFF@"
|
||||
#endif
|
||||
|
||||
#if defined (@CMLIB_PROJECT_NAME_UPPER@_GIT_BRANCH)
|
||||
#error "Duplicate definition of macros @CMLIB_PROJECT_NAME_UPPER@_GIT_BRANCH"
|
||||
#else
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_GIT_BRANCH "@CMLIB_GIT_BRANCH@"
|
||||
#endif
|
||||
|
||||
#if defined (@CMLIB_PROJECT_NAME_UPPER@_GIT_TAG)
|
||||
#error "Duplicate definition of macros @CMLIB_PROJECT_NAME_UPPER@_GIT_TAG"
|
||||
#else
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_GIT_TAG "@CMLIB_GIT_TAG@"
|
||||
#endif
|
||||
|
||||
#endif /* @CMLIB_PROJECT_NAME_CANONICAL@_CMLIB_GIT_VERSION_HPP_ */
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef @CMLIB_PROJECT_NAME_CANONICAL@_CMLIB_CONFIG_HPP_
|
||||
#define @CMLIB_PROJECT_NAME_CANONICAL@_CMLIB_CONFIG_HPP_
|
||||
#ifndef @CMLIB_PROJECT_NAME_UPPER@_CMLIB_CONFIG_HPP_
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_CMLIB_CONFIG_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#define @CMLIB_PROJECT_NAME_CANONICAL@_VERSION_STR "@PROJECT_VERSION@"
|
||||
#define @CMLIB_PROJECT_NAME_CANONICAL@_VERSION_INT @PROJECT_VERSION_INT@
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_VERSION_STR "@PROJECT_VERSION@"
|
||||
#define @CMLIB_PROJECT_NAME_UPPER@_VERSION_INT @PROJECT_VERSION_INT@
|
||||
|
||||
#if defined (CMLIB_ORGANIZATION_NAME)
|
||||
#error "Duplicate definition of macros CMLIB_ORGANIZATION_NAME"
|
||||
@ -90,5 +90,5 @@
|
||||
#define CMLIB_BUILD_DATE "@TODAY@"
|
||||
#endif
|
||||
|
||||
#endif /* @CMLIB_PROJECT_NAME_CANONICAL@_CMLIB_CONFIG_HPP_ */
|
||||
#endif /* @CMLIB_PROJECT_NAME_UPPER@_CMLIB_CONFIG_HPP_ */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user