cmake_minimum_required(VERSION 3.10) # 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) # Define the executable and its source files add_executable(dixon main.cpp DixonNodeState.cpp DixonNodeState.h DixonBrain.cpp DixonBrain.h CardioCenter/Heart.cpp CardioCenter/Heart.h) # 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 "${CMAKE_CURRENT_SOURCE_DIR}/extern/libgpiod/aarch64/libgpiodcxx.so.2" "${CMAKE_CURRENT_SOURCE_DIR}/extern/libgpiod/aarch64/libgpiod.so.3") # Tell the linker: "Trust me, the Pi has the rest of the C++ and C libraries" target_link_options(dixon PRIVATE "-Wl,--allow-shlib-undefined")