Skip to content
This repository has been archived by the owner on Jun 30, 2020. It is now read-only.

Commit

Permalink
cmake: support git info in released tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
mathstuf committed Oct 23, 2014
1 parent eeffac6 commit eba180a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.git* export-ignore
/CMakeLists.txt export-subst
version.cmake export-subst
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,7 @@ elseif(NOT MSVC)
set(EXTRA_LIBRARIES ${RT} ${PTHREAD} ${DL})
endif()

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
find_package(Git QUIET)
if(Git_FOUND OR GIT_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
else()
message(STATUS "WARNING: Git was not found!")
set(VERSIONTAG "unknown")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
endif()
include(version.cmake)

add_subdirectory(src)
add_subdirectory(tests)
23 changes: 23 additions & 0 deletions version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function (write_static_version_header hash)
set(VERSIONTAG "${hash}")
configure_file("src/version.h.in" "version/version.h")
add_custom_target(version ALL)
endfunction ()

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
find_package(Git QUIET)
if ("$Format:$" STREQUAL "")
# We're in a tarball; use hard-coded variables.
write_static_version_header("release")
elseif (GIT_FOUND OR Git_FOUND)
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
add_custom_target(version ALL
COMMAND "${CMAKE_COMMAND}"
"-D" "GIT=${GIT_EXECUTABLE}"
"-D" "TO=${CMAKE_BINARY_DIR}/version/version.h"
"-P" "src/version.cmake"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
else()
message(STATUS "WARNING: Git was not found!")
write_static_version_header("unknown")
endif ()

0 comments on commit eba180a

Please sign in to comment.