-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cmake
More file actions
175 lines (148 loc) · 6.31 KB
/
setup.cmake
File metadata and controls
175 lines (148 loc) · 6.31 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#
# Copyright (C) 2024 Nikolas Koesling <nikolas@koesling.info>.
# This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
#
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
include(CTest)
include(ClangFormat.cmake)
# Determine whether this is a standalone project or included by other projects
set(STANDALONE_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(STANDALONE_PROJECT ON)
endif ()
# ----------------------------------------------- clang-tidy -----------------------------------------------------------
# ======================================================================================================================
if(CLANG_TIDY)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (${CLANG_TIDY_NO_ERRORS})
set (CLANG_TIDY_CONFIG_FILE ${CMAKE_SOURCE_DIR}/.clang-tidy-noerrors)
else()
set (CLANG_TIDY_CONFIG_FILE ${CMAKE_SOURCE_DIR}/.clang-tidy)
endif()
set(CMAKE_CXX_CLANG_TIDY
clang-tidy
-config-file=${CLANG_TIDY_CONFIG_FILE})
message(STATUS "clang-tidy enabled: ${CLANG_TIDY_CONFIG_FILE}")
else()
message(WARNING "clang-tidy requested, but only available if clang is selected as compiler")
endif()
endif()
# ----------------------------------------------- library target -------------------------------------------------------
# ======================================================================================================================
if (STATIC_LIB)
add_library(${Target} STATIC)
else ()
add_library(${Target} SHARED)
endif ()
if (INSTAL_LIB)
install(TARGETS ${Target})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h*"
)
endif ()
# ----------------------------------------------- set source and include directory -------------------------------------
# ======================================================================================================================
add_subdirectory(src)
add_subdirectory(include)
target_include_directories(${Target} PUBLIC include)
# ----------------------------------------------- warnings, compiler definitions and otions ----------------------------
# ======================================================================================================================
include(warnings.cmake)
include(define.cmake)
include(compileropts.cmake)
# force C++ Standard and disable/enable compiler specific extensions
set_target_properties(${Target} PROPERTIES
CXX_STANDARD ${STANDARD}
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ${COMPILER_EXTENSIONS}
)
# enable tests only for standalone project
if (ENABLE_TEST AND STANDALONE_PROJECT)
add_subdirectory(test)
endif ()
# disable compiler warnings if project is not a standalone project
if (NOT STANDALONE_PROJECT)
unset(COMPILER_WARNINGS)
endif ()
set_definitions(${Target})
if (ENABLE_MULTITHREADING AND OPENMP)
set_options(${Target} ON)
else ()
set_options(${Target} OFF)
endif ()
if (COMPILER_WARNINGS)
enable_warnings(${Target})
message(STATUS "Compiler warnings enabled.")
else ()
disable_warnings(${Target})
message(STATUS "Compiler warnings disabled.")
endif ()
if (ENABLE_MULTITHREADING)
# required by threading lib (std::thread)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${Target} PRIVATE Threads::Threads)
endif ()
# ----------------------------------------------- doxygen documentation ------------------------------------------------
# ======================================================================================================================
if (BUILD_DOC AND NOT STANDALONE_PROJECT)
# doxygen documentation (https://vicrucann.github.io/tutorials/quick-cmake-doxygen/)
# check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
if (EXISTS ${DOXYGEN_IN})
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message(STATUS "Doxygen configured")
# note the option ALL which allows to build the docs together with the application
add_custom_target(doc_doxygen_${Target} ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
message(STATUS "Added target doc_doxygen_${Target}")
if (TARGET doc_doxygen)
add_dependencies(doc_doxygen doc_doxygen_${Target})
else ()
add_custom_target(doc_doxygen DEPENDS doc_doxygen_${Target})
endif ()
else ()
message(WARNING "doxygen documentation requested, but file ${DOXYGEN_IN} does not exist.")
endif ()
else (DOXYGEN_FOUND)
message(WARNING "Doxygen must be installed and accessible to generate the doxygen documentation.")
endif (DOXYGEN_FOUND)
endif ()
# add clang format target
if (CLANG_FORMAT AND NOT STANDALONE_PROJECT)
set(CLANG_FORMAT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format)
if (EXISTS ${CLANG_FORMAT_FILE})
include(ClangFormat.cmake)
target_clangformat_setup(${Target})
message(STATUS "Added clang format target(s)")
else ()
message(WARNING "Clang format enabled, but file ${CLANG_FORMAT_FILE} does not exist")
endif ()
endif ()
# generate version_info.cpp
# output is not the acutal generated file --> command is always executed
add_custom_command(
OUTPUT
${CMAKE_SOURCE_DIR}/src/generated/version_info_cpp
COMMAND
bash ${CMAKE_SOURCE_DIR}/scripts/gen_version_info_cpp.sh ${PROJECT_NAME}
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
)
execute_process(
COMMAND bash "${CMAKE_SOURCE_DIR}/scripts/gen_version_info_cpp.sh" ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(${Target}_generated_version_info
DEPENDS ${CMAKE_SOURCE_DIR}/src/generated/version_info_cpp
)
add_dependencies(${Target} ${Target}_generated_version_info)