Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.gitversion export-subst
1 change: 1 addition & 0 deletions .gitversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%cs-%h$
26 changes: 14 additions & 12 deletions libtrellis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,22 @@ endfunction()
# Avoid perturbing build if git version hasn't changed
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated")
set(LAST_GIT_VERSION "")

# Get version string in following order of priority:
# 1) Externally defined -DCURRENT_GIT_VERSION
# 2) git-archive export-subst trick from .gitversion
# 3) Call git describe (if available)
if (NOT DEFINED CURRENT_GIT_VERSION)
execute_process(COMMAND git describe --tags --always OUTPUT_VARIABLE CURRENT_GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
string(STRIP "${CURRENT_GIT_VERSION}" CURRENT_GIT_VERSION)
if (EXISTS "${CMAKE_BINARY_DIR}/generated/last_git_version")
file(READ "${CMAKE_BINARY_DIR}/generated/last_git_version" LAST_GIT_VERSION)
endif()
if (NOT ("${LAST_GIT_VERSION}" STREQUAL "${CURRENT_GIT_VERSION}") OR NOT GIT_EXECUTABLE)
configure_file(
${CMAKE_SOURCE_DIR}/tools/version.cpp.in
${CMAKE_BINARY_DIR}/generated/version.cpp
)
file(READ "${CMAKE_SOURCE_DIR}/.gitversion" CURRENT_GIT_VERSION)
if ("${CURRENT_GIT_VERSION}" STREQUAL "$Format:%cs-%h$") # if not substituted we're in a git checkout
if (GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always OUTPUT_VARIABLE CURRENT_GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
string(STRIP "${CURRENT_GIT_VERSION}" CURRENT_GIT_VERSION)
endif()
else() # we're in a git-archive tarball
file(READ "${CMAKE_SOURCE_DIR}/.gitversion" CURRENT_GIT_VERSION)
endif()
endif()
file(WRITE "${CMAKE_BINARY_DIR}/generated/last_git_version" CURRENT_GIT_VERSION)

if (BUILD_ECPBRAM)
add_executable(${PROGRAM_PREFIX}ecpbram ${INCLUDE_FILES} tools/ecpbram.cpp "${CMAKE_BINARY_DIR}/generated/version.cpp")
Expand Down