summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/GenerateVersion.cmake2
-rw-r--r--cmake/Version.cmake12
3 files changed, 11 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 76f5190..542f2ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,7 +65,7 @@ set(INCLUDE_VERSION_HEADER ${PROJECT_INCLUDE_DIR}/dnbd3/version.h)
set(INCLUDE_VERSION_HEADER_TEMPLATE ${PROJECT_INCLUDE_DIR}/dnbd3/version.h.in)
set(INCLUDE_VERSION_HEADER_GENERATE ${PROJECT_INCLUDE_GEN_DIR}/dnbd3/version.h)
set(INCLUDE_VERSION_HEADER_GENERATE_PREFIX ${PROJECT_INCLUDE_DIR_PREFIX}/dnbd3)
-gen_project_version(${INCLUDE_VERSION_HEADER} ${INCLUDE_VERSION_HEADER_TEMPLATE} ${INCLUDE_VERSION_HEADER_GENERATE})
+gen_project_version(${INCLUDE_VERSION_HEADER} ${INCLUDE_VERSION_HEADER_TEMPLATE} ${INCLUDE_VERSION_HEADER_GENERATE} ${GIT_EXECUTABLE} ${CMAKE_SOURCE_DIR})
# generate project build type C header file from template
# exposes dnbd3-generate-build and dnbd3-build target
@@ -102,7 +102,7 @@ endif(DNBD3_RELEASE_HARDEN AND CMAKE_BUILD_TYPE MATCHES "Release")
# define packaging if Release build is enabled
if(CMAKE_BUILD_TYPE MATCHES Release)
# get version source package or Git repository
- get_repository_version(REPOSITORY_VERSION ${INCLUDE_VERSION_HEADER} ${CMAKE_BUILD_TYPE})
+ get_repository_version(REPOSITORY_VERSION ${INCLUDE_VERSION_HEADER} ${CMAKE_BUILD_TYPE} ${GIT_EXECUTABLE} ${CMAKE_SOURCE_DIR})
# define project version
if(KernelHeaders_VERSION)
diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake
index 8574ba7..e7c551b 100644
--- a/cmake/GenerateVersion.cmake
+++ b/cmake/GenerateVersion.cmake
@@ -11,7 +11,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
include(Version)
# get Git version of Git repository
-get_repository_version(DNBD3_VERSION ${VERSION_INPUT_FILE} ${VERSION_BUILD_TYPE})
+get_repository_version(DNBD3_VERSION ${VERSION_INPUT_FILE} ${VERSION_BUILD_TYPE} ${GIT_EXECUTABLE} ${REPOSITORY_DIR})
# generate version header if header does not exists
if(NOT EXISTS ${VERSION_INPUT_FILE})
diff --git a/cmake/Version.cmake b/cmake/Version.cmake
index 097afd5..5f63a31 100644
--- a/cmake/Version.cmake
+++ b/cmake/Version.cmake
@@ -3,7 +3,7 @@
# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
#
-macro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION_OUTPUT_FILE)
+macro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION_OUTPUT_FILE GIT_EXECUTABLE REPOSITORY_DIR)
get_filename_component(VERSION_OUTPUT_FILENAME ${VERSION_OUTPUT_FILE} NAME)
# command that will trigger a rebuild of version.h every time
add_custom_command(OUTPUT regenerate-version-file
@@ -17,6 +17,8 @@ macro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION
-D VERSION_INPUT_FILE_TEMPLATE=${VERSION_INPUT_FILE_TEMPLATE}
-D VERSION_OUTPUT_FILE=${VERSION_OUTPUT_FILE}
-D VERSION_BUILD_TYPE=${CMAKE_BUILD_TYPE}
+ -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
+ -D REPOSITORY_DIR=${REPOSITORY_DIR}
-P ${PROJECT_MODULES_DIR}/GenerateVersion.cmake
COMMENT "Generating ${VERSION_OUTPUT_FILENAME}"
DEPENDS regenerate-version-file)
@@ -29,7 +31,7 @@ macro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION
endmacro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION_OUTPUT_FILE)
# macro to get Git version information
-macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUILD_TYPE)
+macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUILD_TYPE GIT_EXECUTABLE REPOSITORY_DIR)
# check if generated version header from source package is available
if(EXISTS ${VERSION_HEADER_FILE})
# get version information from the generated version header of the source package
@@ -38,7 +40,8 @@ macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUIL
set(GIT_VERSION "${CMAKE_MATCH_1}")
else(EXISTS ${VERSION_HEADER_FILE})
# get detailed Git version information from Git repository
- execute_process(COMMAND git describe HEAD
+ execute_process(COMMAND ${GIT_EXECUTABLE} describe HEAD
+ WORKING_DIRECTORY ${REPOSITORY_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -51,7 +54,8 @@ macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUIL
endif(GIT_VERSION STREQUAL "")
# get status of Git repository
- execute_process(COMMAND git status --porcelain
+ execute_process(COMMAND ${GIT_EXECUTABLE} status --porcelain
+ WORKING_DIRECTORY ${REPOSITORY_DIR}
OUTPUT_VARIABLE GIT_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE)