diff --git a/src/RobotNode/CMakeLists.txt b/src/RobotNode/CMakeLists.txt index 438c2e1..1c94c6e 100644 --- a/src/RobotNode/CMakeLists.txt +++ b/src/RobotNode/CMakeLists.txt @@ -1,7 +1,22 @@ cmake_minimum_required(VERSION 3.10) -# Defines the project name -project(Dixon) +# 1. Define the Version Bumper Target +# This target is like a "recipe" that isn't cooked until we ask for it. +add_custom_target(BumpVersion + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/bump_version.py + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Bumping version in version.txt..." +) + +# 2. Read the version for the Project metadata +# This still happens during "Reload" so CMake knows the project version. +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" RAW_VERSION) +string(STRIP "${RAW_VERSION}" DIXON_VERSION_FROM_FILE) + +message(STATUS "Dixon Version detected from file: ${DIXON_VERSION_FROM_FILE}") + +# Use that variable in your project definition +project(Dixon VERSION ${DIXON_VERSION_FROM_FILE} LANGUAGES CXX) # Forces the compiler to use C++20 features set(CMAKE_CXX_STANDARD 20) @@ -16,9 +31,18 @@ add_executable(Dixon CardioCenter/Heart.cpp CardioCenter/Heart.h) -# Header Path: Use the local v2.1 headers staged in the project -target_include_directories(Dixon PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/extern/libgpiod/include") +# 3. Create the Dependency +# This tells CMake: "Before you build Dixon, you MUST run BumpVersion." +add_dependencies(Dixon BumpVersion) +# Generate the header from the template +configure_file(Version.h.in "${CMAKE_CURRENT_BINARY_DIR}/Version.h") + +# Consolidated Include Paths +target_include_directories(Dixon PRIVATE + "${CMAKE_CURRENT_BINARY_DIR}" # For generated Version.h + "${CMAKE_CURRENT_SOURCE_DIR}/extern/libgpiod/include" # For libgpiod headers +) # Link the gpiod libraries target_link_libraries(Dixon PRIVATE diff --git a/src/RobotNode/Version.h.in b/src/RobotNode/Version.h.in new file mode 100644 index 0000000..57196b3 --- /dev/null +++ b/src/RobotNode/Version.h.in @@ -0,0 +1,7 @@ +#pragma once +#define VERSION_H + +#define DIXON_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define DIXON_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define DIXON_VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define DIXON_VERSION "@PROJECT_VERSION@" diff --git a/src/RobotNode/bump_version.py b/src/RobotNode/bump_version.py new file mode 100644 index 0000000..d2adfaa --- /dev/null +++ b/src/RobotNode/bump_version.py @@ -0,0 +1,30 @@ +import os + +def bump_version(): + file_path = 'version.txt' + + # Read the current version, default to 1.0.0 if file is missing + if os.path.exists(file_path): + with open(file_path, 'r') as f: + version_str = f.read().strip() + else: + version_str = "1.0.0" + + try: + # Split 1.0.2 into [1, 0, 2] + parts = version_str.split('.') + major, minor, patch = map(int, parts) + + # Increment the patch + new_version = f"{major}.{minor}.{patch + 1}" + + # Write it back to the file + with open(file_path, 'w') as f: + f.write(new_version) + + print(f"Version bumped to {new_version}") + except Exception as e: + print(f"Error bumping version: {e}") + +if __name__ == "__main__": + bump_version() \ No newline at end of file diff --git a/src/RobotNode/main.cpp b/src/RobotNode/main.cpp index 109face..094eefa 100644 --- a/src/RobotNode/main.cpp +++ b/src/RobotNode/main.cpp @@ -1,10 +1,12 @@ #include #include "DixonBrain.h" #include "DixonNodeState.h" +#include "Version.h" // The generated header int main() { - std::cout << "Starting Dixon...\n"; + // The "Splash Screen" + std::cout << "Starting Dixon v" << DIXON_VERSION << "...\n"; // Create the brain controller DixonBrain brain; @@ -20,4 +22,4 @@ int main() std::cout << "Dixon shut down.\n"; return 0; -} +} \ No newline at end of file diff --git a/src/RobotNode/version.txt b/src/RobotNode/version.txt new file mode 100644 index 0000000..f9cbc01 --- /dev/null +++ b/src/RobotNode/version.txt @@ -0,0 +1 @@ +1.0.7 \ No newline at end of file