diff --git a/cmake/sbs.cmake b/cmake/sbs.cmake index 9df48c04a99ece503974294456ac899b39a32496..266519e937eb482bfc5dba4ac89538cb593b2f02 100644 --- a/cmake/sbs.cmake +++ b/cmake/sbs.cmake @@ -39,30 +39,33 @@ function(sbs_target TARGET OPT_BOARD) target_include_directories(${TARGET} PRIVATE src/shared) - add_custom_target(${TARGET}-version-info + # Define version information generation command + add_custom_target(${TARGET}-version-info-gen COMMAND "${CMAKE_COMMAND}" "-D" "TARGET_NAME=${TARGET}" "-D" "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" "-D" "BOARDCORE_PATH=${BOARDCORE_PATH}" - "-D" "BIN_DIR=${CMAKE_CURRENT_BINARY_DIR}/include/${TARGET}" + "-D" "OUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/include/${TARGET}" "-P" "${BOARDCORE_PATH}/cmake/version.cmake" - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/${TARGET}/version.h" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/${TARGET}/version.cpp" COMMENT "Generating version information file for ${TARGET}" VERBATIM ) - add_dependencies(${TARGET} ${TARGET}-version-info) + # Create the version information interface library target + # Linking with this target will add the include directory to the target + add_library(${TARGET}-version-info STATIC + ${CMAKE_CURRENT_BINARY_DIR}/include/${TARGET}/version.cpp + ) + # The version info needs to be generated before building the target + add_dependencies(${TARGET}-version-info ${TARGET}-version-info-gen) + + # Link the version information library to the target + target_link_libraries(${TARGET} PRIVATE ${TARGET}-version-info) if(CMAKE_CROSSCOMPILING) # Link the embedded Boardcore library target_link_libraries(${TARGET} PRIVATE Skyward::Boardcore::${OPT_BOARD}) - - # Add the generated include directory to the target - # This also works for injecting include directories into consumed libs - # E.g. adding version information to the kernel library - target_include_directories(${TARGET} PRIVATE - $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/${TARGET}> - ) - + # Linker script and linking options are inherited from the kernel library # Add a post build command to create the hex file to flash on the board diff --git a/cmake/version.cmake b/cmake/version.cmake index 9b2b977adef80f0b4ac479d1614c4ddd8c30997d..f53e7b597b88fe37319147a5dbce367a5cb28b9c 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -88,6 +88,6 @@ set(GIT_VERSION_STRING "${GIT_VERSION_INFO}${GIT_DIRTY_SUFFIX}") # - CMAKE_BUILD_TYPE configure_file( - "${BOARDCORE_PATH}/cmake/version.h.in" - "${BIN_DIR}/version.h" + "${BOARDCORE_PATH}/cmake/version.cpp.in" + "${OUT_DIR}/version.cpp" ) diff --git a/cmake/version.cpp.in b/cmake/version.cpp.in new file mode 100644 index 0000000000000000000000000000000000000000..008d4a909c10d030d0d57ab7a0caf2f98a3d96ca --- /dev/null +++ b/cmake/version.cpp.in @@ -0,0 +1,19 @@ +#pragma once + +// This file is generated by CMake. Do not edit it directly. +// See cmake/version.cmake for details. + +constexpr auto GIT_REV = "@GIT_REV@@GIT_DIRTY_SUFFIX@"; +constexpr auto GIT_TAG = "@GIT_TAG@"; +constexpr auto GIT_BRANCH = "@GIT_BRANCH@"; + +constexpr auto GIT_VERSION_STRING = "@GIT_VERSION_STRING@"; + +constexpr auto TARGET_NAME = "@TARGET_NAME@"; +constexpr auto BUILD_TYPE = "@CMAKE_BUILD_TYPE@"; + +constexpr auto VERSION_STRING = "@TARGET_NAME@ @ @GIT_VERSION_STRING@"; + +constexpr auto SKYWARD_VERSION_STRING = + "Skyward Eperimental Rocketry (c) @TARGET_NAME@ @ @GIT_VERSION_STRING@ " + "(@CMAKE_BUILD_TYPE@)"; diff --git a/cmake/version.h.in b/cmake/version.h.in deleted file mode 100644 index 69b974da6299290bf70533eaf2ff7a3f381db4f9..0000000000000000000000000000000000000000 --- a/cmake/version.h.in +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -// This file is generated by CMake. Do not edit it directly. -// See cmake/version.cmake for details. - -#define GIT_REV "@GIT_REV@@GIT_DIRTY_SUFFIX@" -#define GIT_TAG "@GIT_TAG@" -#define GIT_BRANCH "@GIT_BRANCH@" - -#define GIT_VERSION_STRING "@GIT_VERSION_STRING@" - -#define TARGET_NAME "@TARGET_NAME@" -#define BUILD_TYPE "@CMAKE_BUILD_TYPE@" - -#define VERSION_STRING "@TARGET_NAME@ @ @GIT_VERSION_STRING@" - -#define SKYWARD_VERSION_STRING \ - "Skyward Eperimental Rocketry (c) " VERSION_STRING " (" BUILD_TYPE ")"