From 05743741577206e58e5e0e9d780e5ff5395062f7 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 19 Oct 2026 14:33:49 +0200 Subject: [PATCH] Added common version number file to drive both conan and cmake. Change agent_version.txt to update the version number of the build --- CMakeLists.txt | 11 +++++------ agent_version.txt | 1 + cmake/get_version_number.cmake | 22 ++++++++++++++++++++++ conanfile.py | 11 +++++++---- 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 agent_version.txt create mode 100644 cmake/get_version_number.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f0af9e0d..94b72b93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,6 @@ # The version number. -set(AGENT_VERSION_MAJOR 2) -set(AGENT_VERSION_MINOR 8) -set(AGENT_VERSION_PATCH 0) -set(AGENT_VERSION_BUILD 4) -set(AGENT_VERSION_RC "") +include(cmake/get_version_number.cmake) + # This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent cmake_minimum_required(VERSION 3.23 FATAL_ERROR) @@ -28,7 +25,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CXX_COMPILE_FEATURES cxx_std_20) -project(cppagent LANGUAGES C CXX) +project(cppagent + VERSION ${AGENT_VERSION_MAJOR}.${AGENT_VERSION_MINOR}.${AGENT_VERSION_PATCH}.${AGENT_VERSION_BUILD} + LANGUAGES C CXX) set(WITH_RUBY ON CACHE STRING "With Ruby Support") diff --git a/agent_version.txt b/agent_version.txt new file mode 100644 index 00000000..342f75f9 --- /dev/null +++ b/agent_version.txt @@ -0,0 +1 @@ +2.8.0.5 diff --git a/cmake/get_version_number.cmake b/cmake/get_version_number.cmake new file mode 100644 index 00000000..7f6de365 --- /dev/null +++ b/cmake/get_version_number.cmake @@ -0,0 +1,22 @@ +set(AGENT_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/agent_version.txt") + +# Read the first line and trim whitespace / stray \r from CRLF files +file(STRINGS "${AGENT_VERSION_FILE}" _agent_version_line LIMIT_COUNT 1) +string(STRIP "${_agent_version_line}" _agent_version_line) + +# MAJOR.MINOR.PATCH.BUILD with an optional RC suffix: 2.8.0.4, 2.8.0.4-RC1, 2.8.0.4_RC1, 2.8.0.4RC1 +if(NOT _agent_version_line MATCHES + "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)([-_]?(RC[0-9]+))?$") + message(FATAL_ERROR + "Invalid version '${_agent_version_line}' in ${AGENT_VERSION_FILE}; " + "expected MAJOR.MINOR.PATCH.BUILD[-RCn]") +endif() + +set(AGENT_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(AGENT_VERSION_MINOR ${CMAKE_MATCH_2}) +set(AGENT_VERSION_PATCH ${CMAKE_MATCH_3}) +set(AGENT_VERSION_BUILD ${CMAKE_MATCH_4}) +set(AGENT_VERSION_RC "${CMAKE_MATCH_6}") # "" when there's no RC + +# Re-run configure automatically when the version file changes +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${AGENT_VERSION_FILE}") diff --git a/conanfile.py b/conanfile.py index f9ff3215..a0ae1857 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,7 +1,7 @@ from conan import ConanFile from conan.tools.microsoft import is_msvc, is_msvc_static_runtime from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout -from conan.tools.files import copy +from conan.tools.files import copy, load import os import io @@ -9,7 +9,6 @@ class MTConnectAgentConan(ConanFile): name = "mtconnect_agent" - version = "2.7" url = "https://github.com/mtconnect/cppagent.git" license = "Apache License 2.0" settings = "os", "compiler", "arch", "build_type" @@ -27,7 +26,6 @@ class MTConnectAgentConan(ConanFile): "cpack_name": [None, "ANY"], "cpack_generator": [None, "ANY"] } - description = "MTConnect reference C++ agent copyright Association for Manufacturing Technology" build_policy = "missing" @@ -74,7 +72,7 @@ class MTConnectAgentConan(ConanFile): } exports_sources = "*", "!build", "!test_package/build", "!*~" - exports = "conan/mqtt_cpp/*", "conan/mruby/*", "conan/oniguruma/*" + exports = "conan/mqtt_cpp/*", "conan/mruby/*", "conan/oniguruma/*", "agent_version.txt" def validate(self): if is_msvc(self) and self.options.shared and self.settings.compiler.runtime != 'dynamic': @@ -90,6 +88,11 @@ def config_options(self): if is_msvc(self): self.options.rm_safe("fPIC") + def set_version(self): + if not self.version: + self.version = load(self, os.path.join(self.recipe_folder, "agent_version.txt")).splitlines()[0].strip() + print(f"Building MTConnect Version {self.version}") + def tool_requires_version(self, package, version): self.output.info(f"Checking version of {package} > {version}") buf = io.StringIO()