-
-
Notifications
You must be signed in to change notification settings - Fork 474
/
CMakeLists.txt
335 lines (264 loc) · 10.7 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
cmake_minimum_required(VERSION 3.8.0)
project(osm2pgsql VERSION 2.0.0 LANGUAGES CXX C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Do not create install targets when run as a subproject.
# Currently used by Nominatim which cannot yet rely on installed versions
# of osm2pgsql.
if (${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
set(ENABLE_INSTALL ON)
else()
set(ENABLE_INSTALL OFF)
endif()
if (NOT ${CMAKE_SIZEOF_VOID_P} EQUAL 8)
message(FATAL_ERROR "osm2pgsql needs a 64 bit architecture")
endif()
if (WIN32)
set(DEFAULT_STYLE "default.style" CACHE STRING "Default style used unless one is given on the command line")
else()
set(DEFAULT_STYLE "${CMAKE_INSTALL_PREFIX}/share/osm2pgsql/default.style" CACHE STRING "Default style used unless one is given on the command line")
endif()
option(BUILD_TESTS "Build test suite" OFF)
option(BUILD_COVERAGE "Build with coverage" OFF)
option(WITH_LUAJIT "Build with LuaJIT support" OFF)
option(WITH_PROJ "Build with Projection support" ON)
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed, please use a separate build directory like `mkdir build && cd build && cmake ..`")
endif()
message(STATUS "Building osm2pgsql ${PROJECT_VERSION}")
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
# We don't want to use special compiler extensions because we want portability
set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOMINMAX)
add_compile_options(-wd4996 -utf-8)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099")
else()
add_compile_options(-Wall)
endif()
option(EXTERNAL_LIBOSMIUM "Do not use the bundled libosmium" OFF)
option(EXTERNAL_PROTOZERO "Do not use the bundled protozero" OFF)
option(EXTERNAL_FMT "Do not use the bundled fmt" OFF)
option(EXTERNAL_CLI11 "Do not use the bundled CLI11" OFF)
if (NOT WIN32 AND NOT APPLE)
# No need for this path, just a workaround to make cmake work on all systems.
# Without this we need the PostgreSQL server libraries installed.
# https://stackoverflow.com/questions/13920383/findpostgresql-cmake-wont-work-on-ubuntu
set(PostgreSQL_TYPE_INCLUDE_DIR /usr/include)
endif()
set(MINIMUM_POSTGRESQL_SERVER_VERSION "9.6")
set(MINIMUM_POSTGRESQL_SERVER_VERSION_NUM "90600")
set(PostgreSQL_ADDITIONAL_VERSIONS "17" "16" "15" "14" "13" "12" "11" "10" "9.6")
#############################################################
# Version
#############################################################
find_package(Git)
if (GIT_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty=-changed
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE VERSION_FROM_GIT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (VERSION_FROM_GIT)
set(VERSION_FROM_GIT " (${VERSION_FROM_GIT})")
endif()
endif()
configure_file(
${PROJECT_SOURCE_DIR}/src/version.cpp.in
${PROJECT_BINARY_DIR}/src/version.cpp
)
#############################################################
# Coverage
#############################################################
if (BUILD_COVERAGE)
if (NOT BUILD_TESTS)
message(WARNING "Coverage build enabled, but tests not enabled!")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
string(REGEX REPLACE "^([0-9]+).*$" "llvm-cov-\\1"
gcov_ ${CMAKE_CXX_COMPILER_VERSION})
set(gcov_param_ " gcov")
else()
set(gcov_ "gcov")
set(gcov_param_ "")
endif()
message(STATUS "Looking for coverage tool: ${gcov_}")
find_program(GCOV ${gcov_} DOC "Coverage tool")
if (GCOV STREQUAL "GCOV-NOTFOUND")
message(STATUS " coverage tool not found - coverage disabled")
else()
message(STATUS " found")
message(STATUS "Looking von gcovr")
find_program(GCOVR "gcovr" DOC "Coverage report tool")
if (GCOVR STREQUAL "GCOVR-NOTFOUND")
message(WARNING " gcovr not found - coverage will not work")
else()
message(STATUS " found")
endif()
add_compile_options(-g -O0 -fno-inline-functions -fno-inline --coverage)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage"
CACHE
STRING "Flags used by the linker during all build types."
FORCE)
set(coverage_report_dir "${CMAKE_BINARY_DIR}/coverage")
file(MAKE_DIRECTORY ${coverage_report_dir})
add_custom_target(coverage
${GCOVR}
${CMAKE_BINARY_DIR}
--root=${CMAKE_SOURCE_DIR}
--html-details
--html-title "osm2pgsql coverage report"
#--verbose
#--keep
--delete
'--exclude=.*contrib.*'
--sort-percentage
--gcov-executable=${GCOV}${gcov_param_}
--output=${coverage_report_dir}/index.html)
endif()
endif()
#############################################################
# Detect available headers and set global compiler options
#############################################################
include(CheckIncludeFiles)
add_definitions(-DDEFAULT_STYLE=\"${DEFAULT_STYLE}\")
#############################################################
# Find necessary libraries
#############################################################
if (NOT EXTERNAL_LIBOSMIUM)
set(OSMIUM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/libosmium/include")
endif()
if (NOT EXTERNAL_PROTOZERO)
set(PROTOZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/protozero/include")
endif()
if (NOT EXTERNAL_FMT)
set(FMT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/fmt/include")
endif()
if (NOT EXTERNAL_CLI11)
set(CLI11_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/contrib/CLI11/include")
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR})
find_package(Osmium 2.17.3 REQUIRED COMPONENTS io)
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR} ${CLI11_INCLUDE_DIR})
if (WITH_LUAJIT)
message(STATUS "Building with LuaJIT support")
find_package(LuaJIT REQUIRED)
include_directories(SYSTEM ${LUAJIT_INCLUDE_DIR})
add_definitions(-DHAVE_LUAJIT=1)
else()
message(STATUS "Building with Lua (but not LuaJIT) support")
find_package(Lua REQUIRED)
include_directories(SYSTEM ${LUA_INCLUDE_DIR})
endif()
find_program(LUA_EXE NAMES lua lua5.4 lua5.3 lua5.2 lua5.1)
find_package(Boost 1.50 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
find_package(PostgreSQL REQUIRED)
include_directories(SYSTEM ${PostgreSQL_INCLUDE_DIRS})
find_package(Threads)
find_path(NLOHMANN_INCLUDE_DIR nlohmann/json.hpp)
include_directories(SYSTEM ${NLOHMANN_INCLUDE_DIR})
find_path(POTRACE_INCLUDE_DIR potracelib.h)
find_library(POTRACE_LIBRARY NAMES potrace)
find_package(OpenCV QUIET OPTIONAL_COMPONENTS core imgcodecs imgproc)
############### Libraries are found now ########################
set(LIBS ${Boost_LIBRARIES} ${PostgreSQL_LIBRARY} ${OSMIUM_LIBRARIES})
if (WITH_PROJ)
find_path(PROJ6_INCLUDE_DIR proj.h)
find_library(PROJ_LIBRARY NAMES proj)
if (PROJ_LIBRARY)
message(STATUS "Found Proj ${PROJ_LIBRARY}")
add_definitions(-DHAVE_GENERIC_PROJ=6)
set(HAVE_PROJ6 1)
list(APPEND LIBS ${PROJ_LIBRARY})
include_directories(SYSTEM ${PROJ6_INCLUDE_DIR})
endif()
endif()
if (LUAJIT_FOUND)
list(APPEND LIBS ${LUAJIT_LIBRARIES})
else()
list(APPEND LIBS ${LUA_LIBRARIES})
endif()
if (WIN32)
list(APPEND LIBS ws2_32)
endif()
message(STATUS "Libraries used to build: ${LIBS}")
#############################################################
# Build the library and executable file
#############################################################
add_subdirectory(src)
add_executable(osm2pgsql src/osm2pgsql.cpp)
target_link_libraries(osm2pgsql osm2pgsql_lib ${LIBS})
if (${POTRACE_LIBRARY} STREQUAL "POTRACE_LIBRARY-NOTFOUND" OR NOT OPENCV_CORE_FOUND)
message(STATUS "Did not find opencv and/or potrace library. Not building osm2pgsql-gen.")
else()
message(STATUS "Found opencv and potrace library. Building osm2pgsql-gen.")
set(BUILD_GEN 1)
include_directories(SYSTEM ${POTRACE_INCLUDE_DIR})
add_executable(osm2pgsql-gen src/gen/osm2pgsql-gen.cpp
src/gen/canvas.cpp
src/gen/gen-base.cpp
src/gen/gen-create.cpp
src/gen/gen-discrete-isolation.cpp
src/gen/gen-rivers.cpp
src/gen/gen-tile-builtup.cpp
src/gen/gen-tile-raster.cpp
src/gen/gen-tile-sql.cpp
src/gen/gen-tile-vector.cpp
src/gen/gen-tile.cpp
src/gen/params.cpp
src/gen/raster.cpp
src/gen/tracer.cpp)
target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS})
endif()
#############################################################
# Optional "clang-tidy" target
#############################################################
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY
NAMES clang-tidy clang-tidy-19 clang-tidy-18 clang-tidy-17 clang-tidy-16 clang-tidy-15)
if (CLANG_TIDY)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
file(GLOB CT_CHECK_FILES src/*.cpp src/*/*.cpp tests/*cpp)
add_custom_target(clang-tidy
${CLANG_TIDY}
-p ${CMAKE_BINARY_DIR}
${CT_CHECK_FILES}
)
else()
message(STATUS "Looking for clang-tidy - not found")
message(STATUS " Build target 'clang-tidy' will not be available.")
endif()
#############################################################
# Build tests
#############################################################
if (BUILD_TESTS)
enable_testing()
if (NOT TESTING_TIMEOUT)
set(TESTING_TIMEOUT 1200)
endif()
add_subdirectory(tests)
configure_file(
${PROJECT_SOURCE_DIR}/tests/run-behave.in
${PROJECT_BINARY_DIR}/run-behave
)
else()
message(STATUS "Tests disabled. Set BUILD_TESTS=ON to enable tests.")
endif()
#############################################################
# Man page
#############################################################
add_subdirectory(man)
#############################################################
# Install
#############################################################
include(GNUInstallDirs)
if (ENABLE_INSTALL)
install(TARGETS osm2pgsql DESTINATION bin)
install(FILES default.style empty.style DESTINATION share/osm2pgsql)
install(PROGRAMS scripts/osm2pgsql-replication DESTINATION bin)
if (BUILD_GEN)
install(TARGETS osm2pgsql-gen DESTINATION bin)
endif()
endif()