summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorManuel Bentele2020-11-13 08:03:07 +0100
committerManuel Bentele2020-11-13 08:03:07 +0100
commitc4bc6d6fd6ddefc369647871be4558bcb73561cb (patch)
treef29464ae30addefefbc699f527e72abd54799172 /cmake
parent[BUILD] add CMake toolchain files to cross-compile for ppc and aarch64 (diff)
downloaddnbd3-c4bc6d6fd6ddefc369647871be4558bcb73561cb.tar.gz
dnbd3-c4bc6d6fd6ddefc369647871be4558bcb73561cb.tar.xz
dnbd3-c4bc6d6fd6ddefc369647871be4558bcb73561cb.zip
[BUILD] add support to locate build directory out of Git directory
This patch adds support to locate the build directory for generated artifacts out of the original checked out Git source code repository.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/GenerateVersion.cmake2
-rw-r--r--cmake/Version.cmake12
2 files changed, 9 insertions, 5 deletions
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)