forked from Fields2Cover/Fields2Cover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
344 lines (280 loc) · 9.83 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
set(FIELDS2COVER_MAJOR_VERSION "1")
set(FIELDS2COVER_MINOR_VERSION "2")
set(FIELDS2COVER_PATCH_VERSION "1")
set(FIELDS2COVER_VERSION_STRING
"${FIELDS2COVER_MAJOR_VERSION}.${FIELDS2COVER_MINOR_VERSION}.${FIELDS2COVER_PATCH_VERSION}"
)
set(FIELDS2COVER_VERSION
${FIELDS2COVER_MAJOR_VERSION}.${FIELDS2COVER_MINOR_VERSION}.${FIELDS2COVER_PATCH_VERSION}
)
set(PACKAGE_NAME "Fields2Cover")
set(PACKAGE_DESCRIPTION
"Fields2Cover is a complete coverage path planning package for autonomous robots"
)
set(PACKAGE_AUTHOR "Wageningen University")
set(PACKAGE_MAINTAINER "Gonzalo Mier")
set(PACKAGE_URL "http://fields2cover.github.io")
option(ALLOW_PARALLELIZATION "Allow parallel algorithms" OFF)
option(BUILD_TUTORIALS "Build tutorials" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_PYTHON "Build Python SWIG module" OFF)
option(BUILD_DOC "Build Documentation" OFF)
option(BUILD_SHARED_LIBS "Build shared library(.so)" ON)
if (BUILD_PYTHON)
cmake_minimum_required(VERSION 3.12.4)
else(BUILD_PYTHON)
cmake_minimum_required(VERSION 3.11)
endif(BUILD_PYTHON)
if(${CMAKE_VERSION} VERSION_LESS 3.22)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else(${CMAKE_VERSION} VERSION_LESS 3.22)
cmake_policy(VERSION 3.22)
endif(${CMAKE_VERSION} VERSION_LESS 3.22)
if(POLICY CMP0094)
cmake_policy(SET CMP0094 NEW)
endif(POLICY CMP0094)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif(POLICY CMP0135)
project(Fields2Cover
LANGUAGES CXX
VERSION "${FIELDS2COVER_VERSION_STRING}"
DESCRIPTION "${PACKAGE_DESCRIPTION}"
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
# set(CMAKE_BUILD_TYPE Testing)
# set(CMAKE_BUILD_TYPE Debug)
endif(NOT CMAKE_BUILD_TYPE)
if (WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif(WIN32)
set(INSTALL_CMAKE_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Fields2Cover)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
include(FetchContent)
if(${CMAKE_VERSION} VERSION_LESS 3.14)
macro(FetchContent_MakeAvailable NAME)
FetchContent_GetProperties(${NAME})
if(NOT ${NAME}_POPULATED)
FetchContent_Populate(${NAME})
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
endif(NOT ${NAME}_POPULATED)
endmacro(FetchContent_MakeAvailable)
endif(${CMAKE_VERSION} VERSION_LESS 3.14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_Declare(json FETCHCONTENT_UPDATES_DISCONNECTED
URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz
)
FetchContent_Declare(tinyxml2 FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
GIT_TAG c2d30872e20621955ca7feb9168bad996d591a19
)
FetchContent_Declare(steering_functions FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/steering_functions.git
GIT_TAG 33fc010017efa1ef2c8a2d4779fcda94b4b30d20
)
FetchContent_Declare(spline FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/spline.git
GIT_TAG 1b5d4bad29082997076b264de84ca6d46c2ae6ab
)
FetchContent_Declare(matplotlib_cpp FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/matplotlib-cpp.git
GIT_TAG 75c15d0c907a4b68bca5ef97032302bd14ccab8e
)
FetchContent_MakeAvailable(
json
tinyxml2
steering_functions
spline
matplotlib_cpp
)
find_package(GDAL 3.0 REQUIRED)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH
"Installation directory for header files"
)
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif(NOT IS_ABSOLUTE "${${var}}")
endforeach()
file(GLOB_RECURSE fields2cover_src
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*/*/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*/*/*/*.cpp"
)
list(REMOVE_ITEM fields2cover_src
"${CMAKE_CURRENT_SOURCE_DIR}/.*"
"${CMAKE_CURRENT_SOURCE_DIR}/src/.*"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*/.*"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*/*/.*"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*/*/*/.*.cpp"
)
if(BUILD_SHARED_LIBS)
add_library(Fields2Cover SHARED ${fields2cover_src})
else(BUILD_SHARED_LIBS)
add_library(Fields2Cover STATIC ${fields2cover_src})
endif(BUILD_SHARED_LIBS)
target_compile_features(Fields2Cover PUBLIC cxx_std_17)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
target_compile_options(Fields2Cover PRIVATE
-pedantic -Wall -Wfatal-errors
-Werror -Wno-dev -Wextra -Wno-unused-parameter -Wno-sign-compare
-Wno-attributes -Wl,--no-undefined -Wshadow
)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE /W4)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "^(Apple)?Clang$")
endif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
include(cmake/Modules/CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
target_compile_options(Fields2Cover PRIVATE
-g --coverage -fprofile-arcs -ftest-coverage -fno-inline
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE /O0)
else(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE -O0)
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
else (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE /O2)
else(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE -O2)
endif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_include_directories(Fields2Cover PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${EIGEN3_INCLUDE_DIRS}
)
target_link_libraries(Fields2Cover
PUBLIC
${GDAL_LIBRARIES}
-lpthread
-lgeos_c
PRIVATE
nlohmann_json::nlohmann_json
tinyxml2::tinyxml2
steering_functions
spline
matplotlib_cpp
)
if(ALLOW_PARALLELIZATION)
target_link_libraries(Fields2Cover PRIVATE tbb)
endif(ALLOW_PARALLELIZATION)
set_target_properties(Fields2Cover
PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE
PUBLIC_HEADER "include/fields2cover.h"
)
install(
TARGETS
Fields2Cover
tinyxml2
steering_functions
nlohmann_json
EXPORT Fields2Cover-targets
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(Fields2CoverConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
if(BUILD_SHARED_LIBS)
set(type shared)
else(BUILD_SHARED_LIBS)
set(type static)
endif(BUILD_SHARED_LIBS)
install(
EXPORT Fields2Cover-targets
FILE Fields2Cover-${type}-Targets.cmake
DESTINATION ${INSTALL_CMAKE_DIR}/cmake/fields2cover
)
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(cmake/Fields2CoverConfig.cmake.in
"Fields2CoverConfig.cmake" @ONLY)
configure_file(cmake/Fields2CoverConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/Fields2CoverConfigVersion.cmake" @ONLY
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/Fields2CoverConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Fields2CoverConfigVersion.cmake"
DESTINATION
${INSTALL_CMAKE_DIR}/cmake/fields2cover
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
)
export(
TARGETS
Fields2Cover
tinyxml2
steering_functions
nlohmann_json
FILE
Fields2Cover-${type}-Targets.cmake
)
# Copy public headers during `make install`
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(PACKAGE Fields2Cover)
# Packaging support
set(CPACK_PACKAGE_VENDOR "Wageningen University & Research")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PACKAGE_DESCRIPTION})
set(CPACK_PACKAGE_VERSION_MAJOR ${FIELDS2COVER_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${FIELDS2COVER_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${FIELDS2COVER_VERSION_PATCH})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.rst")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Gonzalo Mier<${CPACK_PACKAGE_CONTACT}>")
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set(CPACK_SOURCE_IGNORE_FILES .git dist .*build.* \\\\.DS_Store .dockerignore)
include(CPack)
#####################################################
#################### tutorials ######################
#####################################################
if (BUILD_TUTORIALS)
add_subdirectory(tutorials)
endif(BUILD_TUTORIALS)
#####################################################
######################### swig ######################
#####################################################
if (BUILD_PYTHON)
add_subdirectory(swig)
endif(BUILD_PYTHON)
#####################################################
######################### test ######################
#####################################################
if(BUILD_TESTS)
find_package(GTest REQUIRED)
include(CTest)
enable_testing()
add_custom_target(check COMMAND
GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND} --verbose --test-dir tests/
)
add_subdirectory(tests)
endif(BUILD_TESTS)
#####################################################
######################### docs ######################
#####################################################
if(BUILD_DOC)
add_subdirectory(docs)
endif(BUILD_DOC)