-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
284 lines (235 loc) · 8.09 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
cmake_minimum_required(VERSION 3.8)
project(exactextract)
set(DEFAULT_BUILD_TYPE "Release")
set(LIB_NAME exactextract)
set(BIN_NAME exactextract_bin)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(CTest)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(VersionSource)
find_package(GEOS "3.5" REQUIRED)
if (GEOS_FOUND)
message(STATUS "GEOS version: " ${GEOS_VERSION})
else()
message(FATAL_ERROR "GEOS version 3.5 or later is required.")
endif()
message(STATUS "Source version: " ${EXACTEXTRACT_VERSION_SOURCE})
set(SRC_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/generated)
configure_file(src/version.h.in ${SRC_GENERATED}/version.h)
# Define coverage build type
set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-arcs -ftest-coverage")
# Make sure we know our build type
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
endif()
#Configure some options the various components this module can build
option(BUILD_BENCHMARKS "Build exactextract benchmarks" OFF)
option(BUILD_CLI "Build the exactextract cli binary" ON) #requires gdal, cli11
option(BUILD_TEST "Build the exactextract tests" ON) #requires catch
option(BUILD_PYTHON "Build the exactextract Python bindings" ON) # requires pybind11
option(BUILD_DOC "Build documentation" ON) #requires doxygen
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# workaround for MacOS 10.13 and below which does not fully support std::variant
add_compile_definitions(_LIBCPP_DISABLE_AVAILABILITY)
endif()
if(BUILD_BENCHMARKS)
add_subdirectory("benchmark")
endif()
if(BUILD_CLI)
# Create our main program, statically linked to our library
# Unlike the library, this depends on GDAL
find_package(GDAL)
if (GDAL_FOUND)
# Check GDAL version (requires CMake 3.14)
if (${CMAKE_VERSION} VERSION_LESS 3.14.0)
message(WARNING "GDAL 2.0+ is required but detected GDAL version is unknown.")
elseif(${GDAL_VERSION} VERSION_LESS 2.0)
unset(GDAL_FOUND)
endif()
endif() #GDAL_FOUND
if (NOT GDAL_FOUND)
message(FATAL_ERROR
"GDAL version >= 2.0 was not found. It is still possible to build and test libexactextract using -DBUILD_CLI=NO, but the "
"exactextract executable cannot be built or installed.")
endif() #NOT GDAL_FOUND
# Download CLI11 (header-only library)
set(CLI11_INCLUDE_DIR ${CMAKE_BINARY_DIR}/CLI11)
set(CLI11_INCLUDE ${CLI11_INCLUDE_DIR}/CLI11.hpp)
if (NOT EXISTS ${CLI11_INCLUDE})
file(DOWNLOAD https://github.com/CLIUtils/CLI11/releases/download/v2.3.2/CLI11.hpp
${CLI11_INCLUDE}
SHOW_PROGRESS)
endif()
#Configure the exactextract CLI target
add_library(exactextract_gdal OBJECT
src/deferred_gdal_writer.h
src/deferred_gdal_writer.cpp
src/gdal_raster_wrapper.h
src/gdal_raster_wrapper.cpp
src/gdal_dataset_wrapper.h
src/gdal_dataset_wrapper.cpp
src/gdal_feature.h
src/gdal_feature_unnester.h
src/gdal_writer.h
src/gdal_writer.cpp
src/utils_cli.h
src/utils_cli.cpp
)
target_link_libraries(exactextract_gdal
PRIVATE ${GDAL_LIBRARY})
target_include_directories(exactextract_gdal
PUBLIC ${GDAL_INCLUDE_DIR})
add_executable(${BIN_NAME} src/exactextract.cpp)
set_target_properties(${BIN_NAME} PROPERTIES OUTPUT_NAME "exactextract")
add_executable(subdivide src/subdivide.cpp)
set_target_properties(subdivide PROPERTIES OUTPUT_NAME "subdivide")
target_link_libraries(
subdivide
PRIVATE ${GDAL_LIBRARY} ${LIB_NAME})
target_include_directories(
subdivide
PRIVATE
${GDAL_INCLUDE_DIR}
${SRC_GENERATED}
)
target_link_libraries(
${BIN_NAME}
PRIVATE
${LIB_NAME}
exactextract_gdal
)
target_include_directories(
${BIN_NAME}
PRIVATE
${SRC_GENERATED}
${CMAKE_SOURCE_DIR}/src
)
# Include CLI11 as a system include so that -Wshadow warnings are suppressed.
target_include_directories(
${BIN_NAME}
SYSTEM PRIVATE ${CLI11_INCLUDE_DIR}
)
target_include_directories(
subdivide
SYSTEM PRIVATE ${CLI11_INCLUDE_DIR})
target_compile_options(
${BIN_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall -Wextra -Wshadow>
$<$<CXX_COMPILER_ID:Clang>:-Werror -Wall -Wextra -Wshadow -Wdouble-promotion>)
install(TARGETS ${BIN_NAME}
RUNTIME
DESTINATION bin)
add_test(NAME "cli_tests"
COMMAND pytest ${CMAKE_CURRENT_LIST_DIR}/test)
endif() #BUILD_CLI
if(BUILD_TEST)
#Build the test suite
add_subdirectory(test)
endif() #BUILD_TEST
set(PROJECT_SOURCES
src/measures.cpp
src/measures.h
src/box.h
src/box.cpp
src/cell.cpp
src/cell.h
src/coordinate.cpp
src/coordinate.h
src/crossing.h
src/feature.h
src/feature.cpp
src/feature_sequential_processor.cpp
src/feature_sequential_processor.h
src/feature_source.h
src/floodfill.cpp
src/floodfill.h
src/geos_utils.cpp
src/geos_utils.h
src/grid.h
src/grid.cpp
src/matrix.h
src/map_feature.h
src/memory_raster_source.h
src/perimeter_distance.cpp
src/perimeter_distance.h
src/processor.h
src/raster.h
src/raster_area.h
src/raster_cell_intersection.cpp
src/raster_cell_intersection.h
src/raster_sequential_processor.cpp
src/raster_sequential_processor.h
src/raster_stats.h
src/raster_coverage_iterator.h
src/side.cpp
src/side.h
src/traversal.cpp
src/traversal.h
src/traversal_areas.cpp
src/traversal_areas.h
src/output_writer.h
src/output_writer.cpp
src/operation.h
src/operation.cpp
src/raster_source.h
src/stats_registry.h
src/stats_registry.cpp
src/utils.h
src/utils.cpp
src/weighted_quantiles.h
src/weighted_quantiles.cpp
src/variance.h
${SRC_GENERATED}/version.h
)
add_library(${LIB_NAME} ${PROJECT_SOURCES})
# Check matrix bounds for debug builds
set_target_properties(${LIB_NAME}
PROPERTIES COMPILE_DEFINITIONS $<$<CONFIG:Debug>:MATRIX_CHECK_BOUNDS>)
target_compile_definitions(
${LIB_NAME}
PRIVATE
GEOS_USE_ONLY_R_API
)
target_compile_options(
${LIB_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall -Wextra -Wshadow -Wdouble-promotion>
$<$<CXX_COMPILER_ID:Clang>:-Werror -Wall -Wextra -Wshadow -Wdouble-promotion>
)
target_link_libraries(
${LIB_NAME}
PUBLIC
GEOS::geos_c
)
set_target_properties(${LIB_NAME} PROPERTIES OUTPUT_NAME ${LIB_NAME})
if (BUILD_PYTHON)
add_subdirectory(python)
endif() # BUILD_PYTHON
if(BUILD_DOC)
# Doxygen configuration from https://vicrucann.github.io/tutorials/quick-cmake-doxygen/
# check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html
DEPENDS ${LIB_NAME} $<$<BOOL:${BUILD_CLI}>:${BIN_NAME}>
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
)
add_custom_target(doxygen
ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html)
else (DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)
endif() #BUILD_DOC