forked from Fields2Cover/Fields2Cover
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
397 lines (333 loc) · 12.2 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
set(FIELDS2COVER_MAJOR_VERSION "2")
set(FIELDS2COVER_MINOR_VERSION "0")
set(FIELDS2COVER_PATCH_VERSION "0")
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" ON)
option(BUILD_TUTORIALS "Build tutorials" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_PYTHON "Build Python SWIG module" ON)
option(BUILD_DOC "Build Documentation" OFF)
option(BUILD_SHARED_LIBS "Build shared library(.so)" ON)
option(USE_ORTOOLS_RELEASE "Get or-tools from release tarball" OFF)
option(USE_ORTOOLS_FETCH_SRC "Get or-tools from source" OFF)
option(USE_ORTOOLS_VENDOR "Get or-tools from ortools_vendor" OFF)
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)
include(GNUInstallDirs)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
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(steering_functions FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/steering_functions.git
GIT_TAG 13e3f5658144b3832fb1eb31a0e2f5a3cbf57db9
)
FetchContent_Declare(matplot FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/alandefreitas/matplotplusplus
)
FetchContent_Declare(json FETCHCONTENT_UPDATES_DISCONNECTED
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
)
FetchContent_MakeAvailable(
steering_functions
matplot
json
)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(TinyXML2 REQUIRED)
find_package(Threads REQUIRED)
find_package(Gnuplot)
find_package(GDAL 3.0 REQUIRED)
find_package(Eigen3 REQUIRED)
find_library(MATH_LIBRARY m)
set(ORTOOLS_TARGET "")
if(USE_ORTOOLS_FETCH_SRC)
message(STATUS "or-tools -- Downloading and building from source")
set(BUILD_DEPS ON)
set(BUILD_SAMPLES OFF)
set(BUILD_EXAMPLES OFF)
FetchContent_Declare(ortools FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG v9.9
CMAKE_ARGS
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
-DBUILD_DEPS:BOOL=ON
-DBUILD_SAMPLES:BOOL=OFF
-DBUILD_EXAMPLES:BOOL=OFF
)
FetchContent_MakeAvailable(ortools)
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
include(CTest)
set(ORTOOLS_TARGET "ortools")
elseif(USE_ORTOOLS_VENDOR)
find_package(ortools_vendor REQUIRED)
elseif(NOT USE_ORTOOLS_RELEASE)
find_package(ortools_vendor QUIET)
find_package(ortools CONFIG QUIET)
endif()
if(USE_ORTOOLS_RELEASE OR (NOT ortools_FOUND))
message(STATUS "or-tools -- Downloading and installing from release tarball")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
message(STATUS "Target architecture is AMD64")
FetchContent_Declare(ortools FETCHCONTENT_UPDATES_DISCONNECTED
URL https://github.com/google/or-tools/releases/download/v9.9/or-tools_amd64_ubuntu-22.04_cpp_v9.9.3963.tar.gz
URL_HASH SHA256=a611133f4e9b75661c637347ebadff79539807cf8966eb9c176c2c560aad0a84
)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
message(STATUS "Target architecture is ARM64")
FetchContent_Declare(ortools FETCHCONTENT_UPDATES_DISCONNECTED
URL https://github.com/google/or-tools/releases/download/v9.9/or-tools_arm64_debian-11_cpp_v9.9.3963.tar.gz
URL_HASH SHA256=f308a06d89dce060f74e6fec4936b43f4bdf4874d18c131798697756200f4e7a
)
else()
message(FATAL_ERROR "Unknown/Unhandled target architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
#NOTE: FetchContent_GetProperties variables only available in called scope
FetchContent_GetProperties(ortools)
if(NOT ortools_POPULATED)
FetchContent_Populate(ortools)
endif()
list(INSERT CMAKE_PREFIX_PATH 0 "${ortools_SOURCE_DIR}")
find_package(ortools CONFIG REQUIRED)
if(NOT ortools_FOUND)
message(FATAL_ERROR "Failed to find ortools in release tarball")
endif()
#NOTE: in CMAKE 3.21 introduces IMPORTED_RUNTIME_ARTIFACTS
# https://cmake.org/cmake/help/v3.21/command/install.html#imported-runtime-artifacts
# Which would allow creation of an ortools target with IMPORTED_LOCATION
# and then install with IMPORTED_RUNTIME_ARTIFACTS
# Just brute force install the contents of the directories for now.
install(
DIRECTORY "${ortools_SOURCE_DIR}/"
DESTINATION opt/f2c_ortools/
)
endif(USE_ORTOOLS_RELEASE OR (NOT ortools_FOUND))
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
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
-Wall -Wfatal-errors
-Wno-dev -Wextra -Wno-unused-parameter -Wno-sign-compare
-Wno-attributes -Wl,--no-undefined
)
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()
#if(NOT USE_ORTOOLS_FETCH_SRC)
# target_compile_options(Fields2Cover PRIVATE -pedantic -Werror)
#endif()
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>
$<INSTALL_INTERFACE:include/fields2cover>
${EIGEN3_INCLUDE_DIRS}
)
target_link_libraries(Fields2Cover
PUBLIC
${GDAL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
-lgeos_c
${MATH_LIBRARY}
PRIVATE
ortools::ortools
nlohmann_json::nlohmann_json
tinyxml2::tinyxml2
steering_functions
matplot
)
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
steering_functions
matplot
${ORTOOLS_TARGET}
EXPORT Fields2Cover-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
#https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html
include(CMakePackageConfigHelpers)
write_basic_package_version_file(Fields2CoverConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
EXPORT Fields2Cover-targets
FILE Fields2Cover-Targets.cmake
DESTINATION "lib/cmake/fields2cover"
)
# generate the config file that includes the exports
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Fields2CoverConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/Fields2CoverConfig.cmake"
INSTALL_DESTINATION "lib/cmake/fields2cover"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/Fields2CoverConfigVersion.cmake"
VERSION "${Tutorial_VERSION_MAJOR}.${Tutorial_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/Fields2CoverConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/Fields2CoverConfigVersion.cmake
DESTINATION "lib/cmake/fields2cover"
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/fields2cover
)
export(
TARGETS
Fields2Cover
steering_functions
matplot
${ORTOOLS_TARGET}
FILE
Fields2Cover-${type}-Targets.cmake
)
# Copy public headers during `make install`
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fields2cover
)
#####################################################
#################### tutorials ######################
#####################################################
if (BUILD_TUTORIALS)
add_subdirectory(tutorials)
endif(BUILD_TUTORIALS)
#####################################################
######################### swig ######################
#####################################################
if (BUILD_PYTHON)
add_subdirectory(swig)
endif(BUILD_PYTHON)
#####################################################
######################### test ######################
#####################################################
if(BUILD_TESTS AND GNUPLOT_FOUND)
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 AND GNUPLOT_FOUND)
#####################################################
######################### docs ######################
#####################################################
if(BUILD_DOC)
add_subdirectory(docs)
endif(BUILD_DOC)
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)