-
Notifications
You must be signed in to change notification settings - Fork 244
/
CMakeLists.txt
345 lines (294 loc) · 11.5 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# -*- mode: cmake; -*-
# vi: set ft=cmake:
#
# CMakeLists.txt
# RVO2 Library
#
# SPDX-FileCopyrightText: 2008 University of North Carolina at Chapel Hill
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Please send all bug reports to <geom@cs.unc.edu>.
#
# The authors may be contacted via:
#
# Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
# Dept. of Computer Science
# 201 S. Columbia St.
# Frederick P. Brooks, Jr. Computer Science Bldg.
# Chapel Hill, N.C. 27599-3175
# United States of America
#
# <https://gamma.cs.unc.edu/RVO2/>
#
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(RVO
VERSION 2.0.3
DESCRIPTION "Optimal Reciprocal Collision Avoidance"
HOMEPAGE_URL https://gamma.cs.unc.edu/RVO2/
LANGUAGES CXX)
list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# cmake-lint: disable=C0301
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build; options are Debug Release RelWithDebInfo MinSizeRel"
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS Debug Release RelWithDebInfo MinSizeRel)
endif()
include(CTest)
if(WIN32)
set(BUILD_SHARED_LIBS OFF)
else()
option(BUILD_SHARED_LIBS "Build all libraries as shared" ON)
endif()
include(GNUInstallDirs)
set(RVO_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
set(RVO_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
set(RVO_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
set(RVO_LIBRARY RVO)
set(RVO_NAME "RVO2 Library")
set(CMAKE_CXX_STANDARD 98)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(ENABLE_OPENMP "Enable OpenMP if available" OFF)
if(ENABLE_OPENMP)
find_package(OpenMP MODULE)
endif()
option(ENABLE_INTERPROCEDURAL_OPTIMIZATION
"Enable interprocedural optimization if supported" OFF)
if(ENABLE_INTERPROCEDURAL_OPTIMIZATION)
include(CheckIPOSupported)
check_ipo_supported(RESULT RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED
LANGUAGES CXX)
if(RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED)
message(STATUS "Interprocedural optimization is supported")
else()
message(STATUS "Interprocedural optimization is NOT supported")
endif()
else()
set(RVO_INTERPROCEDURAL_OPTIMIZATION_SUPPORTED)
endif()
include(CheckCXXCompilerFlag)
include(CheckCXXLinkerFlag)
option(ENABLE_HARDENING
"Enable hardening compiler and linker flags if supported" OFF)
if(ENABLE_HARDENING)
if(MSVC)
check_cxx_compiler_flag(/GS RVO_COMPILER_SUPPORTS_GS)
check_cxx_compiler_flag(/guard:cf RVO_COMPILER_SUPPORTS_GUARD_CF)
if(RVO_COMPILER_SUPPORTS_GS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS")
endif()
check_cxx_linker_flag(/DYNAMICBASE RVO_LINKER_SUPPORTS_DYNAMICBASE)
check_cxx_linker_flag(/GUARD:CF RVO_LINKER_SUPPORTS_GUARD_CF)
check_cxx_linker_flag(/NXCOMPAT RVO_LINKER_SUPPORTS_NXCOMPAT)
if(RVO_COMPILER_SUPPORTS_GUARD_CF
AND RVO_LINKER_SUPPORTS_DYNAMICBASE
AND RVO_LINKER_SUPPORTS_GUARD_CF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /guard:cf")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE /GUARD:CF")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} /DYNAMICBASE /GUARD:CF")
endif()
if(RVO_LINKER_SUPPORTS_NXCOMPAT)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NXCOMPAT")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NXCOMPAT")
endif()
else()
check_cxx_compiler_flag(-D_FORTIFY_SOURCE=2
RVO_COMPILER_SUPPORTS_D_FORTIFY_SOURCE_2)
check_cxx_compiler_flag(-fcf-protection
RVO_COMPILER_SUPPORTS_FCF_PROTECTION)
check_cxx_compiler_flag(-fno-common RVO_COMPILER_SUPPORTS_FNO_COMMON)
check_cxx_compiler_flag(-fsanitize=safe-stack
RVO_COMPILER_SUPPORTS_FSANITIZE_SAFE_STACK)
check_cxx_compiler_flag(-fstack-clash-protection
RVO_COMPILER_SUPPORTS_FSTACK_CLASH_PROTECTION)
check_cxx_compiler_flag(-fstack-protector-strong
RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR_STRONG)
if(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR_STRONG)
set(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR)
else()
check_cxx_compiler_flag(-fstack-protector
RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR)
endif()
if(RVO_COMPILER_SUPPORTS_D_FORTIFY_SOURCE_2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2")
endif()
if(RVO_COMPILER_SUPPORTS_FCF_PROTECTION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcf-protection")
endif()
if(RVO_COMPILER_SUPPORTS_FNO_COMMON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common")
endif()
if(RVO_COMPILER_SUPPORTS_FSTACK_CLASH_PROTECTION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-clash-protection")
endif()
if(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR_STRONG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong")
elseif(RVO_COMPILER_SUPPORTS_FSTACK_PROTECTOR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
endif()
check_cxx_linker_flag(-Wl,-Bsymbolic-functions
RVO_LINKER_SUPPORTS_BSYMBOLIC_FUNCTIONS)
check_cxx_linker_flag(-fsanitize=safe-stack
RVO_LINKER_SUPPORTS_FSANITIZE_SAFE_STACK)
check_cxx_linker_flag(-Wl,-z,defs RVO_LINKER_SUPPORTS_Z_DEFS)
check_cxx_linker_flag(-Wl,-z,noexecheap RVO_LINKER_SUPPORTS_Z_NOEXECHEAP)
check_cxx_linker_flag(-Wl,-z,noexecstack RVO_LINKER_SUPPORTS_Z_NOEXECSTACK)
check_cxx_linker_flag(-Wl,-z,now RVO_LINKER_SUPPORTS_Z_NOW)
check_cxx_linker_flag(-Wl,-z,relro RVO_LINKER_SUPPORTS_Z_RELRO)
if(RVO_LINKER_SUPPORTS_BSYMBOLIC_FUNCTIONS)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
endif()
if(RVO_COMPILER_SUPPORTS_FSANITIZE_SAFE_STACK
AND RVO_LINKER_SUPPORTS_FSANITIZE_SAFE_STACK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=safe-stack")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -fsanitize=safe-stack")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=safe-stack")
endif()
if(RVO_LINKER_SUPPORTS_Z_DEFS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,defs")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
endif()
if(RVO_LINKER_SUPPORTS_Z_NOEXECHEAP)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecheap")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecheap")
endif()
if(RVO_LINKER_SUPPORTS_Z_NOEXECSTACK)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
endif()
if(RVO_LINKER_SUPPORTS_Z_NOW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,now")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,now")
endif()
if(RVO_LINKER_SUPPORTS_Z_RELRO)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro")
endif()
endif()
endif()
if(MSVC)
check_cxx_compiler_flag(/W4 RVO_COMPILER_SUPPORTS_W4)
if(RVO_COMPILER_SUPPORTS_W4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
else()
check_cxx_compiler_flag(-Wall RVO_COMPILER_SUPPORTS_WALL)
check_cxx_compiler_flag(-Wformat-security
RVO_COMPILER_SUPPORTS_WFORMAT_SECURITY)
check_cxx_compiler_flag(-Werror=format-security
RVO_COMPILER_SUPPORTS_WERROR_FORMAT_SECURITY)
check_cxx_compiler_flag(-Wno-unused
RVO_COMPILER_SUPPORTS_WNO_UNUSED)
if(RVO_COMPILER_SUPPORTS_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
if(RVO_COMPILER_SUPPORTS_WFORMAT_SECURITY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-security")
endif()
if(RVO_COMPILER_SUPPORTS_WERROR_FORMAT_SECURITY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
endif()
if(RVO_COMPILER_SUPPORTS_WNO_UNUSED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused")
endif()
endif()
if(NOT MSVC)
check_cxx_linker_flag(-Wl,--as-needed RVO_LINKER_SUPPORTS__AS_NEEDED)
if(RVO_LINKER_SUPPORTS__AS_NEEDED)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
endif()
endif()
option(WARNINGS_AS_ERRORS "Turn compiler warnings into errors" OFF)
if(WARNINGS_AS_ERRORS)
if(MSVC)
check_cxx_compiler_flag(/WX RVO_COMPILER_SUPPORTS_WX)
if(RVO_COMPILER_SUPPORTS_WX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
endif()
else()
check_cxx_compiler_flag(-Werror RVO_COMPILER_SUPPORTS_WERROR)
if(RVO_COMPILER_SUPPORTS_WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
endif()
endif()
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(doc)
install(FILES LICENSE
COMPONENT runtime
DESTINATION ${CMAKE_INSTALL_DOCDIR})
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_NAME}Config.cmake.in ${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${RVO_DIR}
PATH_VARS RVO_INCLUDE_DIR RVO_LIBRARY_DIR)
write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPONENT development
DESTINATION ${RVO_DIR})
find_package(PkgConfig MODULE)
if(PkgConfig_FOUND)
configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
COMPONENT development
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_CONTACT "Jamie Snape")
set(CPACK_PACKAGE_VENDOR "University of North Carolina at Chapel Hill")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_STRIP_FILES ON)
set(CPACK_SOURCE_IGNORE_FILES
_build/ \\\\.git/ \\\\.gitattributes \\\\.github/ \\\\.gitignore bazel-
Brewfile)
set(CPACK_SOURCE_STRIP_FILES ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_DEPENDS)
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PROJECT_HOMEPAGE_URL})
set(CPACK_DEBIAN_PACKAGE_SECTION contrib/devel)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_FREEBSD_PACKAGE_DEPS)
set(CPACK_FREEBSD_PACKAGE_LICENSE APACHE20)
set(CPACK_FREEBSD_PACKAGE_WWW ${PROJECT_HOMEPAGE_URL})
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_PACKAGE_AUTOREQPROV ON)
set(CPACK_RPM_PACKAGE_LICENSE "ASL 2.0")
set(CPACK_RPM_PACKAGE_REQUIRES)
set(CPACK_RPM_PACKAGE_URL ${PROJECT_HOMEPAGE_URL})
include(CPack)