From 263664abd6d33c6aaf18fc8b258e6a383c2f31fd Mon Sep 17 00:00:00 2001 From: Tomislav Novak Date: Fri, 13 Dec 2024 14:29:51 -0800 Subject: [PATCH] cmake: Fix version.h build rule If cmake is invoked from a separate directory, running "git describe" to get the version info fails: $ cd /tmp/build && cmake [...] ~/bpftrace && make version_h -- Could not obtain version string from Git. Falling back to CMake version string. That's because cmake -P sets CMAKE_CURRENT_SOURCE_DIR to the current _working_ directory[1], which may be outside of the git repository. Fix it by explicitly passing CMAKE_SOURCE_DIR to Version.cmake. [1] https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_SOURCE_DIR.html --- cmake/Version.cmake | 2 +- src/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 2cadd0157b22..74c246173e3b 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -13,7 +13,7 @@ # Try and get a version string from Git tags execute_process( COMMAND git describe --abbrev=4 --dirty --tags - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${bpftrace_SOURCE_DIR} OUTPUT_VARIABLE BPFTRACE_VERSION ERROR_VARIABLE GIT_DESCRIBE_ERROR OUTPUT_STRIP_TRAILING_WHITESPACE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dec186ceed64..679728c8cab7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,6 +107,7 @@ add_custom_target(version_h -Dbpftrace_VERSION_MAJOR=${bpftrace_VERSION_MAJOR} -Dbpftrace_VERSION_MINOR=${bpftrace_VERSION_MINOR} -Dbpftrace_VERSION_PATCH=${bpftrace_VERSION_PATCH} + -Dbpftrace_SOURCE_DIR=${CMAKE_SOURCE_DIR} -P ${CMAKE_SOURCE_DIR}/cmake/Version.cmake ) add_dependencies(${BPFTRACE} version_h)