Skip to content

Commit

Permalink
cmake: Fix version.h build rule
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tnovak committed Dec 13, 2024
1 parent c11adab commit 263664a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmake/Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 263664a

Please sign in to comment.