Store the version in version.cpp and group the library under src/core

libdpm-core.so's version was reaching the source as a compile-line
definition, with a fallback in two translation units that would have let
the library build and report 0.0.0 if the build ever stopped supplying
it. The version is a literal in src/core/version.cpp, the file named for
it, alongside dpm_core_version() which returns it and the parser for the
X.Y.Z strings modules report.

The library's sources and its version script move to src/core, leaving
src/cli, src/bundled-modules, and the documentation source beside it.
This commit is contained in:
2026-08-15 22:57:46 -04:00
parent d3f134aabf
commit b641318663
5 changed files with 16 additions and 23 deletions

View File

@@ -8,9 +8,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# libdpm-core.so — the library (C ABI) # libdpm-core.so — the library (C ABI)
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
add_library(dpm-core SHARED add_library(dpm-core SHARED
src/context.cpp src/core/context.cpp
src/modules.cpp src/core/modules.cpp
src/version.cpp src/core/version.cpp
) )
target_include_directories(dpm-core PUBLIC target_include_directories(dpm-core PUBLIC
@@ -18,10 +18,6 @@ target_include_directories(dpm-core PUBLIC
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
) )
target_compile_definitions(dpm-core PRIVATE
DPM_CORE_VERSION_STR="${PROJECT_VERSION}"
)
# The public C API is the library's entire exported surface; internals # The public C API is the library's entire exported surface; internals
# stay hidden. The version script pins the export list and versions the # stay hidden. The version script pins the export list and versions the
# symbols. # symbols.
@@ -30,10 +26,10 @@ target_compile_options(dpm-core PRIVATE
-fvisibility-inlines-hidden -fvisibility-inlines-hidden
) )
target_link_options(dpm-core PRIVATE target_link_options(dpm-core PRIVATE
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/libdpm-core.map -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/core/libdpm-core.map
) )
set_property(TARGET dpm-core APPEND PROPERTY set_property(TARGET dpm-core APPEND PROPERTY
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/libdpm-core.map LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/core/libdpm-core.map
) )
target_link_libraries(dpm-core PRIVATE ${CMAKE_DL_LIBS}) target_link_libraries(dpm-core PRIVATE ${CMAKE_DL_LIBS})

View File

@@ -32,10 +32,6 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
#ifndef DPM_CORE_VERSION_STR
#define DPM_CORE_VERSION_STR "0.0.0"
#endif
namespace { namespace {
const char* DEFAULT_CONFIG_DIR = "/etc/dpm/conf.d/"; const char* DEFAULT_CONFIG_DIR = "/etc/dpm/conf.d/";
@@ -252,11 +248,6 @@ void dpm_close(dpm_ctx* ctx)
delete ctx; delete ctx;
} }
const char* dpm_core_version(void)
{
return DPM_CORE_VERSION_STR;
}
const char* dpm_config_get(dpm_ctx* ctx, const char* module, const char* dpm_config_get(dpm_ctx* ctx, const char* module,
const char* section, const char* key) const char* section, const char* key)
{ {

View File

@@ -39,10 +39,6 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
#ifndef DPM_CORE_VERSION_STR
#define DPM_CORE_VERSION_STR "0.0.0"
#endif
/* dlclose wrapper referenced from context.cpp so handle release stays /* dlclose wrapper referenced from context.cpp so handle release stays
in one translation unit with the loader. */ in one translation unit with the loader. */
void dpm_internal_unload(void* handle) void dpm_internal_unload(void* handle)

View File

@@ -1,6 +1,6 @@
/** /**
* @file version.cpp * @file version.cpp
* @brief X.Y.Z version parsing * @brief libdpm-core.so's version, and X.Y.Z version parsing
* *
* @copyright Copyright (c) 2026 SILO GROUP LLC * @copyright Copyright (c) 2026 SILO GROUP LLC
* @author Chris Punches <chris.punches@silogroup.org> * @author Chris Punches <chris.punches@silogroup.org>
@@ -22,9 +22,19 @@
*/ */
#include "internal/version.hpp" #include "internal/version.hpp"
#include <dpm/core.h>
#include <cctype> #include <cctype>
#include <cstdlib> #include <cstdlib>
/** libdpm-core.so's own version. */
#define DPM_CORE_VERSION_STR "1.0.0"
extern "C" const char* dpm_core_version(void)
{
return DPM_CORE_VERSION_STR;
}
namespace dpm_core { namespace dpm_core {
bool parse_version(const char* s, long out[3]) bool parse_version(const char* s, long out[3])