From 18541359646bcbe4018da0d916f6ed15c26b4c6c Mon Sep 17 00:00:00 2001 From: jaw Date: Wed, 23 Oct 2024 13:54:45 +0200 Subject: [PATCH] fixed version check in wrong directory --- cmake/modules/GetVersionFromGitTag.cmake | 14 +++++++------- cmake/modules/MacroOutOfSourceBuild.cmake | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmake/modules/GetVersionFromGitTag.cmake b/cmake/modules/GetVersionFromGitTag.cmake index 70182660..c48d34cb 100644 --- a/cmake/modules/GetVersionFromGitTag.cmake +++ b/cmake/modules/GetVersionFromGitTag.cmake @@ -35,23 +35,23 @@ # Author: Nuno Fachada # Check if git is found... -if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git) +if (GIT_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) # Get last tag from git execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE) #How many commits since last tag execute_process(COMMAND ${GIT_EXECUTABLE} rev-list ${${PROJECT_NAME}_VERSION_STRING}..HEAD --count - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_AHEAD OUTPUT_STRIP_TRAILING_WHITESPACE) # Get current commit SHA from git execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_GIT_SHA OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -83,7 +83,7 @@ if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git) # Check wether working tree is clean execute_process(COMMAND ${GIT_EXECUTABLE} status --porcelain - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE ${PROJECT_NAME}_WORKING_DIR_CLEAN) if(NOT ${PROJECT_NAME}_WORKING_DIR_CLEAN STREQUAL "") @@ -96,7 +96,7 @@ if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git) # Save version to file (which will be used when Git is not available # or VERSION_UPDATE_FROM_GIT is disabled) - file(WRITE ${CMAKE_BINARY_DIR}/VERSION ${${PROJECT_NAME}_VERSION_STRING_FULL} + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/VERSION ${${PROJECT_NAME}_VERSION_STRING_FULL} "*" ${${PROJECT_NAME}_VERSION_STRING} "*" ${${PROJECT_NAME}_VERSION_MAJOR} "*" ${${PROJECT_NAME}_VERSION_MINOR} @@ -108,7 +108,7 @@ if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git) else() # Git not available, get version from file - file(STRINGS ${CMAKE_SOURCE_DIR}/VERSION ${PROJECT_NAME}_VERSION_LIST) + file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION ${PROJECT_NAME}_VERSION_LIST) string(REPLACE "*" ";" ${PROJECT_NAME}_VERSION_LIST ${${PROJECT_NAME}_VERSION_LIST}) # Get Length of the version elements diff --git a/cmake/modules/MacroOutOfSourceBuild.cmake b/cmake/modules/MacroOutOfSourceBuild.cmake index 10d1ab27..7bcf13f2 100644 --- a/cmake/modules/MacroOutOfSourceBuild.cmake +++ b/cmake/modules/MacroOutOfSourceBuild.cmake @@ -1,10 +1,10 @@ # Ensures that we do an out of source build MACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD MSG) - STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" -"${CMAKE_BINARY_DIR}" insource) - GET_FILENAME_COMPONENT(PARENTDIR ${CMAKE_SOURCE_DIR} PATH) - STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" + STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" +"${PROJECT_BINARY_DIR}" insource) + GET_FILENAME_COMPONENT(PARENTDIR ${PROJECT_SOURCE_DIR} PATH) + STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "${PARENTDIR}" insourcesubdir) IF(insource OR insourcesubdir) MESSAGE(FATAL_ERROR "${MSG}")