Skip to content

Commit 2ff1c79

Browse files
chore: do not hardcode the library version in cpp/CMakeLists.txt
1 parent 42153e4 commit 2ff1c79

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ add_library(libjsonnet SHARED ${LIBJSONNET_HEADERS} ${LIBJSONNET_SOURCE})
3434
add_dependencies(libjsonnet md5 stdlib)
3535
target_link_libraries(libjsonnet md5 nlohmann_json::nlohmann_json ryml)
3636

37+
# Version extraction logic duplicated in ../cpp/CMakeLists.txt
38+
# TODO: Put this logic somewhere else.
3739
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h JSONNET_VERSION_DEF
3840
REGEX "[#]define[ \t]+LIB_JSONNET_VERSION[ \t]+")
3941
string(REGEX REPLACE ".*\"v([^\"]+)\".*" "\\1" JSONNET_VERSION ${JSONNET_VERSION_DEF})

cpp/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ add_library(libjsonnet++ SHARED ${LIBJSONNETPP_HEADERS} ${LIBJSONNETPP_SOURCE})
1212
add_dependencies(libjsonnet++ jsonnet)
1313
target_link_libraries(libjsonnet++ libjsonnet)
1414

15+
# Version extraction logic duplicated from ../core/CMakeLists.txt
16+
# TODO: Put this logic somewhere else.
17+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../include/libjsonnet.h JSONNET_VERSION_DEF
18+
REGEX "[#]define[ \t]+LIB_JSONNET_VERSION[ \t]+")
19+
string(REGEX REPLACE ".*\"v([^\"]+)\".*" "\\1" JSONNET_VERSION ${JSONNET_VERSION_DEF})
20+
message("Extracted Jsonnet version: " ${JSONNET_VERSION})
21+
1522
# CMake prepends CMAKE_SHARED_LIBRARY_PREFIX to shared libraries, so without
1623
# this step the output would be |liblibjsonnet|.
1724
set_target_properties(libjsonnet++ PROPERTIES OUTPUT_NAME jsonnet++
18-
VERSION "0.21.0"
25+
VERSION "${JSONNET_VERSION}"
1926
SOVERSION "0"
2027
PUBLIC_HEADER "${LIB_HEADER}")
2128
install(TARGETS libjsonnet++

0 commit comments

Comments
 (0)