summaryrefslogtreecommitdiffstats
path: root/cmake/Build.cmake
diff options
context:
space:
mode:
authorManuel Bentele2020-10-23 18:13:15 +0200
committerManuel Bentele2020-10-23 18:13:15 +0200
commit588368dd2a46ddec70741c6cc87a79a0b26ee383 (patch)
tree69265caba9b1fb0ee126c142538b75fd49bbe8ee /cmake/Build.cmake
parentMove the source code of all xloop components to the common 'src' directory (diff)
downloadxloop-588368dd2a46ddec70741c6cc87a79a0b26ee383.tar.gz
xloop-588368dd2a46ddec70741c6cc87a79a0b26ee383.tar.xz
xloop-588368dd2a46ddec70741c6cc87a79a0b26ee383.zip
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.
Diffstat (limited to 'cmake/Build.cmake')
-rw-r--r--cmake/Build.cmake27
1 files changed, 27 insertions, 0 deletions
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 <development@manuel-bentele.de>
+#
+
+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)