Read the version from version.cpp instead of declaring it twice

The library's version reached the build through project(), and reached
the library itself through a separate literal in version.cpp. The two
had to be kept equal by hand; the tests caught drift but the number was
written in both places.

CMakeLists.txt now reads DPM_CORE_VERSION_STR out of the source and
passes it to project(), so the soname, the artifact filenames, the
generated PDF's name, and the value the library reports all derive from
one line. Configuration fails outright if that declaration is missing.

SOVERSION follows PROJECT_VERSION_MAJOR rather than a hardcoded 1.
This commit is contained in:
2026-08-16 01:06:44 -04:00
parent 0fa2205bf6
commit 282423d768

View File

@@ -1,5 +1,18 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
project(dpm-core VERSION 1.0.0 LANGUAGES CXX)
# libdpm-core.so's version is declared in src/core/version.cpp, the file
# that reports it. The build reads that declaration rather than carrying
# its own copy, so the soname, the artifact filenames, and the version
# the library answers with all derive from one line of source.
file(READ src/core/version.cpp DPM_VERSION_SOURCE)
string(REGEX MATCH "DPM_CORE_VERSION_STR[ \t]+\"([0-9]+\\.[0-9]+\\.[0-9]+)\""
DPM_VERSION_MATCH "${DPM_VERSION_SOURCE}")
if(NOT CMAKE_MATCH_1)
message(FATAL_ERROR
"No DPM_CORE_VERSION_STR found in src/core/version.cpp")
endif()
project(dpm-core VERSION ${CMAKE_MATCH_1} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -35,9 +48,8 @@ set_property(TARGET dpm-core APPEND PROPERTY
target_link_libraries(dpm-core PRIVATE ${CMAKE_DL_LIBS}) target_link_libraries(dpm-core PRIVATE ${CMAKE_DL_LIBS})
set_target_properties(dpm-core PROPERTIES set_target_properties(dpm-core PROPERTIES
OUTPUT_NAME "dpm-core"
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION 1 SOVERSION ${PROJECT_VERSION_MAJOR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
) )