From 588368dd2a46ddec70741c6cc87a79a0b26ee383 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 23 Oct 2020 18:13:15 +0200 Subject: Add automatic generation of version and build type headers for compilation This change replaces the static version and build type header file generation by CMake with dynamic CMake targets to generate the version file whenever a Make target is executed. Thus, there is no need anymore to reconfigure and rerun CMake after the repository version or build configuration has changed. --- cmake/Build.cmake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cmake/Build.cmake (limited to 'cmake/Build.cmake') diff --git a/cmake/Build.cmake b/cmake/Build.cmake new file mode 100644 index 0000000..bad9755 --- /dev/null +++ b/cmake/Build.cmake @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020 Manuel Bentele +# + +macro(gen_build_type BUILD_INPUT_FILE_TEMPLATE BUILD_OUTPUT_FILE) + get_filename_component(BUILD_OUTPUT_FILENAME ${BUILD_OUTPUT_FILE} NAME) + # command that will trigger a rebuild of build.h every time + add_custom_command(OUTPUT regenerate-build-file + COMMAND ${CMAKE_COMMAND} -E sleep 0 + COMMENT "Trigger generating ${BUILD_OUTPUT_FILENAME}") + + # call the GenerateBuild.cmake file to generate the build.h file + add_custom_command(OUTPUT ${BUILD_OUTPUT_FILE} + COMMAND ${CMAKE_COMMAND} -D BUILD_INPUT_FILE_TEMPLATE=${BUILD_INPUT_FILE_TEMPLATE} + -D BUILD_OUTPUT_FILE=${BUILD_OUTPUT_FILE} + -D BUILD_TYPE=${CMAKE_BUILD_TYPE} + -P ${PROJECT_MODULES_DIR}/GenerateBuild.cmake + COMMENT "Generating ${BUILD_OUTPUT_FILENAME}" + DEPENDS regenerate-build-file) + add_custom_target(xloop-generate-build DEPENDS ${BUILD_OUTPUT_FILE}) + + # create target to expose project build type + add_library(xloop-build INTERFACE) + target_include_directories(xloop-build INTERFACE ${PROJECT_INCLUDE_GEN_DIR}) + add_dependencies(xloop-build xloop-generate-build) +endmacro(gen_build_type BUILD_INPUT_FILE_TEMPLATE BUILD_OUTPUT_FILE) -- cgit v1.2.3-55-g7522