-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathCMakeLists.txt
133 lines (113 loc) · 5.64 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Zserio C++ runtime library and tests.
#
# This CMake file defines a static library which contains the zserio C++ runtime and an executable which
# contains the zserio C++ runtime tests.
#
# This CMake file is designed to be included directly without any further dependencies.
#
cmake_minimum_required(VERSION 3.15.0)
project(ZserioCppRuntimeAll)
enable_testing()
set(SANITIZERS_ENABLED OFF CACHE BOOL "Whether the compiler sanitizers are enabled.")
set(CLANG_TIDY_BIN "" CACHE STRING "Name of clang-tidy binary. If empty, clang-tidy tool is not called.")
set(CLANG_FORMAT_BIN "" CACHE STRING "Name of clang-format binary. If empty, clang-format tool is not called.")
set(ZSERIO_PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../..")
set(CMAKE_MODULE_PATH "${ZSERIO_PROJECT_ROOT}/cmake")
set(ZSERIO_CODE_COVERAGE_ENABLE OFF CACHE BOOL "Enable unit test code coverage calculation.")
set(ZSERIO_CODE_COVERAGE_FAIL_ON_INCOMPLETE ON CACHE BOOL
"Fail build if line coverage is not below this threshold.")
set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard to use.")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Whether C++ standard is required.")
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Whether compiler specific C++ standard extensions are allowed.")
# cmake helpers
include(cmake_utils)
# setup compiler
include(compiler_utils)
compiler_set_static_clibs()
if (SANITIZERS_ENABLED)
compiler_set_address_sanitizer()
endif ()
# warnings and sanitizers only for src
compiler_set_warnings()
compiler_set_warnings_as_errors()
if (SANITIZERS_ENABLED)
compiler_set_undefined_sanitizer()
endif ()
add_subdirectory(src runtime)
compiler_reset_warnings()
compiler_reset_warnings_as_errors()
if (SANITIZERS_ENABLED)
compiler_reset_undefined_sanitizer()
endif ()
add_subdirectory(test runtime_test)
# coverage
if (${ZSERIO_CODE_COVERAGE_ENABLE})
include(coverage_utils)
enable_coverage_for_target(ZserioCppRuntime)
enable_coverage_for_target(ZserioCppRuntimeTest)
set(COV_PARAMS)
if (${ZSERIO_CODE_COVERAGE_FAIL_ON_INCOMPLETE})
list(APPEND COV_PARAMS "INCOMPLETE_COVERAGE_FAIL")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(APPEND COV_PARAMS "99.8")
else ()
list(APPEND COV_PARAMS "99.5")
endif ()
endif ()
list(APPEND COV_PARAMS "EXCLUDE_SOURCES")
list(APPEND COV_PARAMS ".*test_object.*")
create_coverage_target(${COV_PARAMS})
endif ()
# install Zserio C++ runtime library (we release sources only)
install(DIRECTORY src/ DESTINATION cpp
FILES_MATCHING
PATTERN "CMakeLists.txt"
PATTERN "*.h"
PATTERN "*.cpp")
# add clang-tidy custom target
include(clang_tidy_utils)
clang_tidy_add_custom_target(ZserioCppRuntime-clang-tidy
DEPENDS ZserioCppRuntime ZserioCppRuntimeTest
SOURCES_GLOBS
"${CMAKE_CURRENT_SOURCE_DIR}/src/zserio/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test/zserio/*.cpp"
BUILD_PATH "${CMAKE_BINARY_DIR}"
CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ClangTidyConfig.txt"
HEADER_FILTER
".*(src|test)/zserio/.*"
SUPPRESSIONS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ClangTidySuppressions.txt"
WERROR_UNUSED_SUPPRESSIONS ON)
# add clang-format custom target
include(clang_format_utils)
clang_format_add_custom_target(ZserioCppRuntime-clang-format
DEPENDS ZserioCppRuntime ZserioCppRuntimeTest
SOURCES_GLOBS
"${CMAKE_CURRENT_SOURCE_DIR}/src/zserio/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/zserio/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/test/zserio/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test/zserio/*.h"
CONFIG_FILE "${ZSERIO_PROJECT_ROOT}/.clang-format"
WERROR ON)
# build and install doxygen documentation
find_package(Doxygen REQUIRED)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/zserio/CppRuntimeVersion.h" ZSERIO_CPP_RUNTIME_VERSION_FILE)
string(REGEX MATCH "CPP_EXTENSION_RUNTIME_VERSION_STRING = \"([0-9]+.[0-9]+.[0-9]+(-[A-Za-z0-9]+)?)\""
ZSERIO_CPP_RUNTIME_VERSION_LINE "${ZSERIO_CPP_RUNTIME_VERSION_FILE}")
set(ZSERIO_CPP_RUNTIME_VERSION "${CMAKE_MATCH_1}")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../src/zserio/extension/cpp/CppExtensionVersion.java"
ZSERIO_CPP_EXTENSION_VERSION_FILE)
string(REGEX MATCH "EXPECTED_ZSERIO_VERSION_STRING = \"([0-9]+.[0-9]+.[0-9]+(-[A-Za-z0-9]+)?)\""
ZSERIO_CPP_EXTENSION_VERSION_LINE "${ZSERIO_CPP_EXTENSION_VERSION_FILE}")
set(ZSERIO_VERSION "${CMAKE_MATCH_1}")
add_custom_target(ZserioCppRuntime-doxygen ALL
${CMAKE_COMMAND} -E env ZSERIO_CPP_RUNTIME_OUTPUT_DIR="${CMAKE_CURRENT_BINARY_DIR}"
${CMAKE_COMMAND} -E env ZSERIO_CPP_RUNTIME_VERSION="${ZSERIO_CPP_RUNTIME_VERSION}"
${CMAKE_COMMAND} -E env ZSERIO_VERSION="${ZSERIO_VERSION}"
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
COMMENT "Generating C++ runtime HTML documentation"
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/zserio_doc DESTINATION cpp)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/coverage/clang DESTINATION cpp/zserio_doc/coverage OPTIONAL)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/coverage/gcc DESTINATION cpp/zserio_doc/coverage OPTIONAL)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-report.txt DESTINATION cpp/zserio_doc/clang-tidy OPTIONAL)