forked from Fields2Cover/Fields2Cover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
274 lines (212 loc) · 8.64 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
set(FIELDS2COVER_MAJOR_VERSION "1")
set(FIELDS2COVER_MINOR_VERSION "2")
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")
option(BUILD_CPP "Build Cpp package" ON)
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" OFF)
option(BUILD_DOC "Build Documentation" OFF)
if (BUILD_PYTHON)
cmake_minimum_required(VERSION 3.12.4)
else()
cmake_minimum_required(VERSION 3.11)
endif()
if(${CMAKE_VERSION} VERSION_LESS 3.22)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.22)
endif()
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
project(Fields2Cover
LANGUAGES CXX
VERSION "${FIELDS2COVER_VERSION_STRING}"
DESCRIPTION "${PACKAGE_DESCRIPTION}")
if(BUILD_CPP)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
# set(CMAKE_BUILD_TYPE Testing)
# set(CMAKE_BUILD_TYPE Coverage)
endif()
if (WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
endif ()
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()
endmacro()
endif()
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
URL https://github.com/leethomason/tinyxml2/archive/refs/tags/9.0.0.tar.gz)
FetchContent_Declare(steering_functions FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/steering_functions.git)
FetchContent_Declare(spline FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/spline.git)
FetchContent_Declare(matplotlib_cpp FETCHCONTENT_UPDATES_DISCONNECTED
GIT_REPOSITORY https://github.com/Fields2Cover/matplotlib-cpp.git)
FetchContent_MakeAvailable(json tinyxml2 steering_functions spline)
FetchContent_MakeAvailable(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()
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"
)
add_library(Fields2Cover SHARED ${fields2cover_src})
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()
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
include(cmake/Modules/CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
target_compile_options(Fields2Cover PRIVATE -g --coverage -fprofile-arcs -ftest-coverage -fno-inline)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE /O0)
else()
target_compile_options(Fields2Cover PRIVATE -O0)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
else ()
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
target_compile_options(Fields2Cover PRIVATE /O2)
else()
target_compile_options(Fields2Cover PRIVATE -O2)
endif()
endif()
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
PRIVATE
nlohmann_json::nlohmann_json
tinyxml2::tinyxml2
steering_functions
spline
matplotlib_cpp
)
if (ALLOW_PARALLELIZATION)
target_link_libraries(Fields2Cover PRIVATE tbb)
endif()
set_target_properties(Fields2Cover PROPERTIES
INTERPROCEDURAL_OPTIMIZATION TRUE PUBLIC_HEADER "include/fields2cover.h")
install(TARGETS Fields2Cover
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)
install(EXPORT Fields2Cover-targets FILE Fields2CoverTargets.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
FILE Fields2CoverTargets.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()
#####################################################
######################### swig ######################
#####################################################
if (BUILD_PYTHON)
add_subdirectory(swig)
endif()
#####################################################
######################### 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()
endif() # BUILD_CPP
#####################################################
######################### docs ######################
#####################################################
if(BUILD_DOC)
add_subdirectory(docs)
endif()