summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorManuel Bentele2020-10-22 12:08:34 +0200
committerManuel Bentele2020-10-22 12:08:34 +0200
commitf9872723efc831827d179c3baf5b9f6c428512c4 (patch)
tree9662cc3071362570a1f4051f0850b41fbdfff246 /cmake
parent[BUILD] add option to build the dnbd3-server with afl-fuzz support (diff)
downloaddnbd3-f9872723efc831827d179c3baf5b9f6c428512c4.tar.gz
dnbd3-f9872723efc831827d179c3baf5b9f6c428512c4.tar.xz
dnbd3-f9872723efc831827d179c3baf5b9f6c428512c4.zip
[BUILD] add CMake targets to build binary and source packages with CPack
This patch adds the following CMake targets - package - source to build bundeled packages. Those packages contain either all built binary artifacts or all source files for source code distribution. Both CMake targets are available in Release build configuration.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Build.cmake27
-rw-r--r--cmake/GenerateBuild.cmake10
-rw-r--r--cmake/GenerateVersion.cmake38
-rw-r--r--cmake/InstallVersionFile.cmake.in8
-rw-r--r--cmake/KernelVersion.cmake12
-rw-r--r--cmake/ProjectVersion.cmake28
-rw-r--r--cmake/Version.cmake80
7 files changed, 137 insertions, 66 deletions
diff --git a/cmake/Build.cmake b/cmake/Build.cmake
new file mode 100644
index 0000000..a7f4c07
--- /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(dnbd3-generate-build DEPENDS ${BUILD_OUTPUT_FILE})
+
+ # create target to expose project build type
+ add_library(dnbd3-build INTERFACE)
+ target_include_directories(dnbd3-build INTERFACE ${PROJECT_INCLUDE_GEN_DIR})
+ add_dependencies(dnbd3-build dnbd3-generate-build)
+endmacro(gen_build_type BUILD_INPUT_FILE_TEMPLATE BUILD_OUTPUT_FILE)
diff --git a/cmake/GenerateBuild.cmake b/cmake/GenerateBuild.cmake
new file mode 100644
index 0000000..020eb84
--- /dev/null
+++ b/cmake/GenerateBuild.cmake
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
+#
+
+# set current build type of the project
+set(DNBD3_BUILD ${BUILD_TYPE})
+
+# write dnbd3 build type into a new C source file based on the specified build file template
+configure_file(${BUILD_INPUT_FILE_TEMPLATE} ${BUILD_OUTPUT_FILE})
diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake
index 4dfdaa8..8574ba7 100644
--- a/cmake/GenerateVersion.cmake
+++ b/cmake/GenerateVersion.cmake
@@ -3,32 +3,18 @@
# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
#
-# get Git short hash and tag of latest repository commit
-execute_process(COMMAND git describe HEAD
- OUTPUT_VARIABLE DNBD3_BUILD_VERSION
- OUTPUT_STRIP_TRAILING_WHITESPACE)
-if(DNBD3_BUILD_VERSION STREQUAL "")
- set(DNBD3_BUILD_VERSION "unknown")
-endif(DNBD3_BUILD_VERSION STREQUAL "")
+# set CMake module path to include version macros
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ ${VERSION_MODULE_PATH})
-# get status of Git repository
-execute_process(COMMAND git status --porcelain
- OUTPUT_VARIABLE DNBD3_GIT_STATUS
- OUTPUT_STRIP_TRAILING_WHITESPACE)
+# include version macros
+include(Version)
-# check if Git repository is dirty
-if(NOT DNBD3_GIT_STATUS STREQUAL "")
- # the Git repository is dirty, thus extend the version information
- set(DNBD3_BUILD_VERSION "${DNBD3_BUILD_VERSION}-modified")
+# get Git version of Git repository
+get_repository_version(DNBD3_VERSION ${VERSION_INPUT_FILE} ${VERSION_BUILD_TYPE})
- # print a message in Release build configuration to warn about the dirty repository
- if(VERSION_BUILD_TYPE MATCHES "Release")
- message(WARNING "This dnbd3 Git repository is dirty! Please commit or revert all changes for a ${VERSION_BUILD_TYPE} build!")
- endif(VERSION_BUILD_TYPE MATCHES "Release")
-endif(NOT DNBD3_GIT_STATUS STREQUAL "")
-
-# set current build type of the project
-set(DNBD3_BUILD_TYPE ${VERSION_BUILD_TYPE})
-
-# write dnbd3 version into a new C source file based on the specified version template
-configure_file(${VERSION_INPUT_FILE} ${VERSION_OUTPUT_FILE})
+# generate version header if header does not exists
+if(NOT EXISTS ${VERSION_INPUT_FILE})
+ # write dnbd3 version into a new C source file based on the specified version template
+ configure_file(${VERSION_INPUT_FILE_TEMPLATE} ${VERSION_OUTPUT_FILE})
+endif(NOT EXISTS ${VERSION_INPUT_FILE})
diff --git a/cmake/InstallVersionFile.cmake.in b/cmake/InstallVersionFile.cmake.in
new file mode 100644
index 0000000..8121c25
--- /dev/null
+++ b/cmake/InstallVersionFile.cmake.in
@@ -0,0 +1,8 @@
+#
+# AUTOGENERATED: DO NOT EDIT THIS FILE
+#
+
+if(CPACK_SOURCE_INSTALLED_DIRECTORIES AND EXISTS "@INCLUDE_VERSION_HEADER_GENERATE@")
+ file(INSTALL "@INCLUDE_VERSION_HEADER_GENERATE@"
+ DESTINATION "@INCLUDE_VERSION_HEADER_GENERATE_PREFIX@")
+endif(CPACK_SOURCE_INSTALLED_DIRECTORIES AND EXISTS "@INCLUDE_VERSION_HEADER_GENERATE@")
diff --git a/cmake/KernelVersion.cmake b/cmake/KernelVersion.cmake
deleted file mode 100644
index 1ded072..0000000
--- a/cmake/KernelVersion.cmake
+++ /dev/null
@@ -1,12 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-#
-# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
-#
-
-# get Linux kernel version from KERNEL_BUILD_DIR string
-macro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR)
- string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR})
- if(LINUX_KERNEL_VERSION STREQUAL "")
- set(LINUX_KERNEL_VERSION "unknown")
- endif(LINUX_KERNEL_VERSION STREQUAL "")
-endmacro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR)
diff --git a/cmake/ProjectVersion.cmake b/cmake/ProjectVersion.cmake
deleted file mode 100644
index 8b7160c..0000000
--- a/cmake/ProjectVersion.cmake
+++ /dev/null
@@ -1,28 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-#
-# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
-#
-
-macro(gen_project_version VERSION_INPUT_FILE VERSION_OUTPUT_FILE)
- get_filename_component(VERSION_OUTPUT_FILENAME ${VERSION_OUTPUT_FILE} NAME)
- # command that will trigger a rebuild of version.c every time
- add_custom_command(OUTPUT regenerate-version-file
- COMMAND ${CMAKE_COMMAND} -E sleep 0
- COMMENT "Trigger generating ${VERSION_OUTPUT_FILENAME}")
-
- # call the GenerateVersion.cmake file to generate the version.c file
- add_custom_command(OUTPUT ${VERSION_OUTPUT_FILE}
- COMMAND ${CMAKE_COMMAND} -D VERSION_INPUT_FILE=${VERSION_INPUT_FILE}
- -D VERSION_OUTPUT_FILE=${VERSION_OUTPUT_FILE}
- -D VERSION_BUILD_TYPE=${CMAKE_BUILD_TYPE}
- -P ${PROJECT_MODULES_DIR}/GenerateVersion.cmake
- COMMENT "Generating ${VERSION_OUTPUT_FILENAME}"
- DEPENDS regenerate-version-file)
- add_custom_target(dnbd3-generate-version DEPENDS ${VERSION_OUTPUT_FILE})
-
- # create target to expose project version
- add_library(dnbd3-version INTERFACE)
- target_include_directories(dnbd3-version INTERFACE ${PROJECT_INCLUDE_TMP_DIR})
- add_dependencies(dnbd3-version dnbd3-generate-version)
-
-endmacro(gen_project_version VERSION_INPUT_FILE VERSION_OUTPUT_FILE)
diff --git a/cmake/Version.cmake b/cmake/Version.cmake
new file mode 100644
index 0000000..939007e
--- /dev/null
+++ b/cmake/Version.cmake
@@ -0,0 +1,80 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
+#
+
+macro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION_OUTPUT_FILE)
+ get_filename_component(VERSION_OUTPUT_FILENAME ${VERSION_OUTPUT_FILE} NAME)
+ # command that will trigger a rebuild of version.h every time
+ add_custom_command(OUTPUT regenerate-version-file
+ COMMAND ${CMAKE_COMMAND} -E sleep 0
+ COMMENT "Trigger generating ${VERSION_OUTPUT_FILENAME}")
+
+ # call the GenerateVersion.cmake file to generate the version.c file
+ add_custom_command(OUTPUT ${VERSION_OUTPUT_FILE}
+ COMMAND ${CMAKE_COMMAND} -D VERSION_MODULE_PATH=${PROJECT_MODULES_DIR}
+ -D VERSION_INPUT_FILE=${VERSION_INPUT_FILE}
+ -D VERSION_INPUT_FILE_TEMPLATE=${VERSION_INPUT_FILE_TEMPLATE}
+ -D VERSION_OUTPUT_FILE=${VERSION_OUTPUT_FILE}
+ -D VERSION_BUILD_TYPE=${CMAKE_BUILD_TYPE}
+ -P ${PROJECT_MODULES_DIR}/GenerateVersion.cmake
+ COMMENT "Generating ${VERSION_OUTPUT_FILENAME}"
+ DEPENDS regenerate-version-file)
+ add_custom_target(dnbd3-generate-version DEPENDS ${VERSION_OUTPUT_FILE})
+
+ # create target to expose project version
+ add_library(dnbd3-version INTERFACE)
+ target_include_directories(dnbd3-version INTERFACE ${PROJECT_INCLUDE_GEN_DIR})
+ add_dependencies(dnbd3-version dnbd3-generate-version)
+endmacro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION_OUTPUT_FILE)
+
+# macro to get Linux kernel version from KERNEL_BUILD_DIR string
+macro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR)
+ string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR})
+ if(LINUX_KERNEL_VERSION STREQUAL "")
+ set(LINUX_KERNEL_VERSION "unknown")
+ endif(LINUX_KERNEL_VERSION STREQUAL "")
+endmacro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR)
+
+# macro to get Git version information
+macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUILD_TYPE)
+ # check if generated version header from source package is available
+ if(EXISTS ${VERSION_HEADER_FILE})
+ # get version information from the generated version header of the source package
+ file(READ ${VERSION_HEADER_FILE} GIT_VERSION)
+ string(REGEX MATCH "\"(([0-9]+:)?[0-9][A-Za-z0-9.+~-]*)\"" GIT_VERSION ${GIT_VERSION})
+ set(GIT_VERSION "${CMAKE_MATCH_1}")
+ else(EXISTS ${VERSION_HEADER_FILE})
+ # get detailed Git version information from Git repository
+ execute_process(COMMAND git describe HEAD
+ OUTPUT_VARIABLE GIT_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ # remove the first letter of the version to satisfy packaging rules
+ string(REGEX MATCH "([0-9]+:)?[0-9][A-Za-z0-9.+~-]*" GIT_VERSION ${GIT_VERSION})
+
+ # overwrite version from Git if version is unknown
+ if(GIT_VERSION STREQUAL "")
+ set(GIT_VERSION "unknown")
+ endif(GIT_VERSION STREQUAL "")
+
+ # get status of Git repository
+ execute_process(COMMAND git status --porcelain
+ OUTPUT_VARIABLE GIT_STATUS
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ # check if Git repository is dirty
+ if(NOT GIT_STATUS STREQUAL "")
+ # the Git repository is dirty, thus extend the version information
+ set(GIT_VERSION "${GIT_VERSION}-modified")
+
+ # print a message in Release build configuration to warn about the dirty repository
+ if(${VERSION_BUILD_TYPE} MATCHES "Release")
+ message(WARNING "This dnbd3 Git repository is dirty! Please commit or revert all changes for a ${VERSION_BUILD_TYPE} build!")
+ endif(${VERSION_BUILD_TYPE} MATCHES "Release")
+ endif(NOT GIT_STATUS STREQUAL "")
+ endif(EXISTS ${VERSION_HEADER_FILE})
+
+ # return version to caller
+ set(${REPOSITORY_VERSION} ${GIT_VERSION})
+endmacro(get_repository_version)