From 71f9a0e82ac7398c335ce320aa2a8bdc8549bfe8 Mon Sep 17 00:00:00 2001 From: jzaki Date: Wed, 8 Jul 2026 14:32:10 +0100 Subject: [PATCH 1/2] Wire module through version to c++ definition from metadata --- cmake/LogosModule.cmake | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cmake/LogosModule.cmake b/cmake/LogosModule.cmake index 0c773f4..73616dc 100644 --- a/cmake/LogosModule.cmake +++ b/cmake/LogosModule.cmake @@ -178,6 +178,8 @@ Usage: logos_module( NAME SOURCES + [VERSION ] + [PROVIDER_HEADER ] [EXTERNAL_LIBS ] [FIND_PACKAGES ] [LINK_LIBRARIES ] @@ -186,6 +188,13 @@ Usage: [INCLUDE_DIRS ] ) +VERSION is optional: it defaults to the `version` field of metadata.json, +falling back to "1.0.0" (the same default as parseMetadata.nix). It is +exposed to the module's code as the LOGOS_MODULE_VERSION compile definition. + +PROVIDER_HEADER names a header to run provider-dispatch code generation +against (the LogosProviderBase API). + Example: logos_module( NAME my_module @@ -207,7 +216,7 @@ function(logos_module) cmake_parse_arguments( MODULE "" - "NAME;PROVIDER_HEADER" + "NAME;VERSION;PROVIDER_HEADER" "SOURCES;EXTERNAL_LIBS;FIND_PACKAGES;LINK_LIBRARIES;LINK_TARGETS;AUTOGEN_DEPENDS;INCLUDE_DIRS" ${ARGN} ) @@ -246,6 +255,20 @@ function(logos_module) set(METADATA_FILE "${CMAKE_CURRENT_BINARY_DIR}/metadata.json") endif() + # Module version: explicit VERSION arg wins; else metadata.json's + # `version`; else "1.0.0" (same default as parseMetadata.nix). + if(NOT MODULE_VERSION) + set(MODULE_VERSION "1.0.0") + if(EXISTS "${METADATA_FILE}") + file(READ "${METADATA_FILE}" _metadata_json) + string(JSON _meta_version ERROR_VARIABLE _meta_version_err + GET "${_metadata_json}" version) + if(NOT _meta_version_err) + set(MODULE_VERSION "${_meta_version}") + endif() + endif() + endif() + # Find additional packages foreach(pkg ${MODULE_FIND_PACKAGES}) find_package(${pkg} REQUIRED) @@ -374,6 +397,10 @@ function(logos_module) OUTPUT_NAME "${MODULE_NAME}_plugin" ) + # Expose the module version to the module's own code. + target_compile_definitions(${MODULE_NAME}_module_plugin PRIVATE + LOGOS_MODULE_VERSION="${MODULE_VERSION}") + # Add dependency on code generator for source layout if(LOGOS_CPP_SDK_IS_SOURCE) add_dependencies(${MODULE_NAME}_module_plugin run_cpp_generator_${MODULE_NAME}) @@ -676,5 +703,5 @@ function(logos_module) OPTIONAL ) - message(STATUS "Logos module ${MODULE_NAME} configured successfully") + message(STATUS "Logos module ${MODULE_NAME} v${MODULE_VERSION} configured successfully") endfunction() From 2ece9834c3f58b26ee39aa4f325ff915405db1d0 Mon Sep 17 00:00:00 2001 From: jzaki Date: Wed, 8 Jul 2026 17:32:06 +0100 Subject: [PATCH 2/2] Update template examples --- templates/CMakeLists.txt.template | 1 + templates/minimal-module/src/minimal_impl.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index dc7b3dc..4864296 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -39,6 +39,7 @@ logos_module( SOURCES @MODULE_SOURCES@ # Uncomment and modify as needed: + # VERSION 1.0.0 (defaults to metadata.json's `version`) # EXTERNAL_LIBS # @EXTERNAL_LIBS@ # FIND_PACKAGES diff --git a/templates/minimal-module/src/minimal_impl.cpp b/templates/minimal-module/src/minimal_impl.cpp index ff94646..905e4f1 100644 --- a/templates/minimal-module/src/minimal_impl.cpp +++ b/templates/minimal-module/src/minimal_impl.cpp @@ -1,5 +1,12 @@ #include "minimal_impl.h" +// LOGOS_MODULE_VERSION is defined by logos_module() from metadata.json's +// `version` field (or an explicit VERSION argument in CMakeLists.txt). +// The fallback keeps IDEs and standalone compiles working. +#ifndef LOGOS_MODULE_VERSION +#define LOGOS_MODULE_VERSION "0.0.0-dev" +#endif + std::string MinimalImpl::greet(const std::string& name) { std::string greeting = "Hello, " + name + "! Greetings from the minimal module."; @@ -12,5 +19,5 @@ std::string MinimalImpl::greet(const std::string& name) std::string MinimalImpl::getStatus() { - return "Minimal module is running."; + return "Minimal module v" LOGOS_MODULE_VERSION " is running."; }