Skip to content

Commit

Permalink
cmake: set CMAKE_PROJECT_VERSION from git, add it back to thisepic.sh (
Browse files Browse the repository at this point in the history
…#758)

### Briefly, what does this PR introduce?
This uses same code as in EICrecon. This partially undoes of #733,
geometry version is useful.

### What kind of change does this PR introduce?
- [ ] Bug fix (issue #__)
- [x] New feature (issue #__)
- [ ] Documentation update
- [ ] Other: __

### Please check if this PR fulfills the following:
- [ ] Tests for the changes have been added
- [ ] Documentation has been added / updated
- [ ] Changes have been communicated to collaborators

### Does this PR introduce breaking changes? What changes might users
need to make to their code?
No

### Does this PR change default behavior?
No

---------

Co-authored-by: Wouter Deconinck <[email protected]>
  • Loading branch information
veprbl and wdconinc authored Jul 23, 2024
1 parent 292e12d commit 50bc89b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ PROJECT(epic
DESCRIPTION "DD4hep Geometry Description of the EPIC Experiment"
)

# Set version based on git
include(cmake/git_version.cmake)
set_git_version(CMAKE_PROJECT_VERSION)

# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "Set the C++ standard to be used")
Expand Down Expand Up @@ -101,14 +105,16 @@ install(DIRECTORY calibrations/
)

#-----------------------------------------------------------------------------------
# Configure and install detector setup script
# Configure and install compact/version.xml
#
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
configure_file(templates/version.xml.in ${CMAKE_CURRENT_BINARY_DIR}/version.xml @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.xml
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/compact
)

#-----------------------------------------------------------------------------------
# Configure and install detector setup script
#
configure_file(templates/thisepic.sh.in ${CMAKE_CURRENT_BINARY_DIR}/thisepic.sh @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/thisepic.sh
DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
29 changes: 29 additions & 0 deletions cmake/git_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Determine version from git describe cmake-lint: disable=C0103
macro(set_git_version VERSION)
if(NOT Git_Found)
find_package(Git)
endif()

if(GIT_EXECUTABLE)
# Generate a git-describe version string from Git repository tags
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(${VERSION} ${GIT_DESCRIBE_VERSION})
endif()
endif()

# Final fallback: Just use a bogus version string that is semantically older
# than anything else and spit out a warning to the developer.
if(NOT DEFINED ${VERSION})
set(${VERSION} v0.0.0-unknown)
message(
WARNING
"Failed to determine VERSION from Git tags. Using default version \"${${VERSION}}\"."
)
endif()
endmacro()
1 change: 1 addition & 0 deletions templates/epic.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<include ref="${DETECTOR_PATH}/compact/far_forward/definitions.xml" />
<include ref="${DETECTOR_PATH}/compact/far_backward/definitions.xml" />
<include ref="${DETECTOR_PATH}/compact/definitions.xml" />
<include ref="${DETECTOR_PATH}/compact/version.xml"/>
<include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/>
</define>

Expand Down
1 change: 1 addition & 0 deletions templates/thisepic.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export DETECTOR=@PROJECT_NAME@
export DETECTOR_PATH=@CMAKE_INSTALL_FULL_DATADIR@/@PROJECT_NAME@
export DETECTOR_CONFIG=${1:-@PROJECT_NAME@}
export DETECTOR_VERSION=@CMAKE_PROJECT_VERSION@

## Warn is not the right name (this script is sourced, hence $1)
if [[ "$(basename ${BASH_SOURCE[0]})" != "thisepic.sh" ]]; then
Expand Down
4 changes: 4 additions & 0 deletions templates/version.xml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- SPDX-License-Identifier: LGPL-3.0-or-later -->
<!-- Copyright (C) 2024 Dmitry Kalinkin -->

<constant name="epic_version" value="@CMAKE_PROJECT_VERSION@" />

0 comments on commit 50bc89b

Please sign in to comment.