forked from RUrlus/carma
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
228 lines (194 loc) · 7.06 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
SET(CARMA_VERSION_MAJOR 0)
SET(CARMA_VERSION_MINOR 6)
SET(CARMA_VERSION_PATCH 6)
SET(CARMA_VERSION_INFO "${CARMA_VERSION_MAJOR}.${CARMA_VERSION_MINOR}.${CARMA_VERSION_PATCH}")
PROJECT(
carma
VERSION ${CARMA_VERSION_INFO}
LANGUAGES CXX
)
INCLUDE(GNUInstallDirs)
SET(CMAKE_MODULE_PATH_SAVED ${CMAKE_MODULE_PATH})
LIST(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake")
# ##############################################################################
# SETTINGS #
# ##############################################################################
OPTION(CARMA_INSTALL_LIB "Install CARMA headers" OFF)
SET(CARMA_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/carma")
SET(DEFAULT_BUILD_TYPE "Release")
# Set build type to Release if not specified
INCLUDE(BuildType)
IF (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# workaround like https://github.com/nlohmann/json/issues/1408
# to avoid error like: carma\...\include\armadillo_bits/arma_str.hpp(194):
# error C2039: '_snprintf': is not a member of 'std'
ADD_DEFINITIONS(-DHAVE_SNPRINTF)
ENDIF ()
OPTION(CARMA_DEV_MODE "Enable additional definitions for development" OFF)
OPTION(CARMA_DEV_DEBUG_MODE "Turn on all debugging definitions" OFF)
OPTION(CARMA_BUILD_TESTS "Build tests for carma" OFF)
OPTION(CARMA_BUILD_EXAMPLES "Build examples for carma" OFF)
# collect user settable options
INCLUDE(${PROJECT_SOURCE_DIR}/carma_config.cmake)
INCLUDE(ParseOptions)
CONFIGURE_FILE(
${PROJECT_SOURCE_DIR}/include/carma_bits/config.h.in
${PROJECT_BINARY_DIR}/include/carma_bits/generated_config.h
@ONLY
)
# ##############################################################################
# TARGET #
# ##############################################################################
ADD_LIBRARY(carma INTERFACE)
ADD_LIBRARY(carma::carma ALIAS carma)
TARGET_COMPILE_DEFINITIONS(carma
INTERFACE
CARMA_USE_GENERATED_CONFIG=1
CARMA_VERSION_MAJOR=${CARMA_VERSION_MAJOR}
CARMA_VERSION_MINOR=${CARMA_VERSION_MINOR}
CARMA_VERSION_PATCH=${CARMA_VERSION_PATCH}
CARMA_VERSION_NAME=${CARMA_VERSION_INFO}
"$<$<CONFIG:RELEASE>:${CARMA_RELEASE_DEFINITIONS}>"
)
TARGET_COMPILE_FEATURES(carma INTERFACE cxx_std_14)
IF(CARMA_DEV_MODE)
TARGET_COMPILE_OPTIONS(carma
INTERFACE
-Wall
-Wextra
-Wunused-variable
-Wunused-const-variable
)
ENDIF()
TARGET_INCLUDE_DIRECTORIES(carma
INTERFACE
$<INSTALL_INTERFACE:${CARMA_INCLUDE_INSTALL_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
)
TARGET_LINK_LIBRARIES(carma
INTERFACE
armadillo::armadillo
Python3::NumPy
Python3::Module
pybind11::pybind11
)
ADD_LIBRARY(carma_headers INTERFACE)
ADD_LIBRARY(carma::headers ALIAS carma_headers)
TARGET_COMPILE_DEFINITIONS(carma_headers
INTERFACE
CARMA_VERSION_MAJOR=${CARMA_VERSION_MAJOR}
CARMA_VERSION_MINOR=${CARMA_VERSION_MINOR}
CARMA_VERSION_PATCH=${CARMA_VERSION_PATCH}
CARMA_VERSION_NAME=${CARMA_VERSION_INFO}
)
TARGET_COMPILE_FEATURES(carma_headers INTERFACE cxx_std_14)
TARGET_INCLUDE_DIRECTORIES(carma_headers
INTERFACE
$<INSTALL_INTERFACE:${CARMA_INCLUDE_INSTALL_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
)
# Only install the headers
IF (CARMA_INSTALL_LIB)
# modified from https://dominikberner.ch/cmake-interface-lib/
# locations are provided by GNUInstallDirs
INSTALL(
TARGETS carma
EXPORT carma_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
INSTALL(
TARGETS carma_headers
EXPORT carma_Header_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
INCLUDE(CMakePackageConfigHelpers)
write_basic_package_version_file(
"carmaConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/carmaConfig.cmake.in"
"${PROJECT_BINARY_DIR}/carmaConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/carma/cmake
)
INSTALL(
EXPORT carma_Targets
FILE carmaCarmaTargets.cmake
NAMESPACE carma::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/carma/cmake
)
INSTALL(
EXPORT carma_Header_Targets
FILE carmaHeaderTargets.cmake
NAMESPACE carma::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/carma/cmake
)
INSTALL(
FILES
"${PROJECT_BINARY_DIR}/carmaConfig.cmake"
"${PROJECT_BINARY_DIR}/carmaConfigVersion.cmake"
"${PROJECT_SOURCE_DIR}/cmake/carmaDependencyTargets.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/carma/cmake
)
INSTALL(
FILES "${PROJECT_SOURCE_DIR}/include/carma"
DESTINATION ${CARMA_INCLUDE_INSTALL_DIR}
)
INSTALL(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/carma_bits
DESTINATION ${CARMA_INCLUDE_INSTALL_DIR}
FILES_MATCHING
PATTERN "*.h"
)
INSTALL(
FILES ${PROJECT_BINARY_DIR}/include/carma_bits/generated_config.h
DESTINATION ${CARMA_INCLUDE_INSTALL_DIR}/carma_bits
)
ELSE()
# ##############################################################################
# REQUIREMENTS #
# ##############################################################################
FIND_PACKAGE(Python3 COMPONENTS Development NumPy QUIET)
IF (NOT Python3_FOUND)
FIND_PACKAGE(Python3 COMPONENTS Development.Module NumPy REQUIRED)
ENDIF()
# Needed to ensure the same Python executable is found by Pybind11
IF (NOT DEFINED PYTHON_EXECUTABLE)
SET(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
ENDIF ()
# create armadillo and or pybind11 target if not defined
INCLUDE(ThirdPartyTargets)
TARGET_PRECOMPILE_HEADERS(carma
INTERFACE
${PROJECT_SOURCE_DIR}/include/carma_bits/cnalloc.h
)
ENDIF()
# ##############################################################################
# TEST TARGETS #
# ##############################################################################
IF(CARMA_BUILD_TESTS OR CARMA_BUILD_EXAMPLES)
SET(CMAKE_CXX_STANDARD 14)
ENDIF()
IF(CARMA_BUILD_TESTS)
INCLUDE(CTest)
ENABLE_TESTING()
INCLUDE(GetCatch2)
ADD_SUBDIRECTORY(tests)
INCLUDE(ClangFormatTarget)
INCLUDE(CoverageTarget)
ENDIF()
IF(CARMA_BUILD_EXAMPLES)
ADD_SUBDIRECTORY(examples)
ENDIF()
#------------------------------------------------------
INCLUDE(ClearOptions)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH_SAVED})
UNSET(CMAKE_MODULE_PATH_SAVED)