From eec2032418e17bd318b33d7f4b9ef846aa135918 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 13 Nov 2020 08:19:58 +0100 Subject: [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. --- CMakeLists.txt | 4 ++-- cmake/GenerateVersion.cmake | 2 +- cmake/Version.cmake | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66d67a4..26e786f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ set(INCLUDE_VERSION_HEADER ${PROJECT_INCLUDE_DIR}/xloop/version.h) set(INCLUDE_VERSION_HEADER_TEMPLATE ${PROJECT_INCLUDE_DIR}/xloop/version.h.in) set(INCLUDE_VERSION_HEADER_GENERATE ${PROJECT_INCLUDE_GEN_DIR}/xloop/version.h) set(INCLUDE_VERSION_HEADER_GENERATE_PREFIX ${PROJECT_INCLUDE_DIR_PREFIX}/xloop) -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 xloop-generate-build and xloop-build target @@ -82,7 +82,7 @@ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -DNDEBUG") # 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 73b0771..c714428 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(XLOOP_VERSION ${VERSION_INPUT_FILE} ${VERSION_BUILD_TYPE}) +get_repository_version(XLOOP_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 5c72c35..d785e1f 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -3,7 +3,7 @@ # Copyright (C) 2020 Manuel Bentele # -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) -- cgit v1.2.3-55-g7522