Skip to content

Commit 82f22ab

Browse files
ChristianTackeGSIdennisklein
authored andcommitted
build: Check codemeta version field
CMake can analyze JSON. So use this to get the version number from codemeta.json, and compare it with the Version in CMake.
1 parent cb546ac commit 82f22ab

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ include(FairRootSummary)
9090
include(FairMacros)
9191
include(WriteConfigFile)
9292
include(CheckCompiler)
93+
include(FairRootCodemeta)
9394

9495
if(FairCMakeModules_VERSION VERSION_GREATER_EQUAL 1.0.0)
9596
fair_get_git_version()
9697
endif()
98+
get_codemeta_version()
99+
if (PROJECT_CODEMETA_VERSION
100+
AND NOT "${PROJECT_CODEMETA_VERSION}" STREQUAL "${PROJECT_VERSION}")
101+
message(AUTHOR_WARNING "Project Version (${PROJECT_VERSION}) and "
102+
"CodeMeta Version (${PROJECT_CODEMETA_VERSION}) do not match!")
103+
endif()
97104

98105
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
99106

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
################################################################################
2+
# Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
3+
# #
4+
# This software is distributed under the terms of the #
5+
# GNU Lesser General Public Licence (LGPL) version 3, #
6+
# copied verbatim in the file "LICENSE" #
7+
################################################################################
8+
9+
function(get_codemeta_version)
10+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
11+
file(READ "${CMAKE_SOURCE_DIR}/codemeta.json" codemeta_content)
12+
string(JSON codemeta_version ERROR_VARIABLE json_error
13+
GET "${codemeta_content}" "softwareVersion")
14+
if(NOT "${json_error}" STREQUAL "NOTFOUND")
15+
string(JSON codemeta_version ERROR_VARIABLE json_error
16+
GET "${codemeta_content}" "version")
17+
endif()
18+
if(NOT "${json_error}" STREQUAL "NOTFOUND")
19+
return()
20+
endif()
21+
string(REGEX REPLACE "^v" "" codemeta_version "${codemeta_version}")
22+
set(PROJECT_CODEMETA_VERSION "${codemeta_version}" PARENT_SCOPE)
23+
endif()
24+
endfunction()

0 commit comments

Comments
 (0)