-
Notifications
You must be signed in to change notification settings - Fork 38
/
CMakeLists.txt
262 lines (208 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
cmake_minimum_required(VERSION 3.14)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
################
# openstreetmap-cgimap project
################
string(TIMESTAMP CURRENT_TIMESTAMP %y%m%d%H%M UTC)
project(openstreetmap-cgimap
LANGUAGES CXX
VERSION "2.0.1"
DESCRIPTION "CGImap is a C++ implementation of some parts of the OpenStreetMap API as a FastCGI process."
HOMEPAGE_URL "https://github.com/zerebubuth/openstreetmap-cgimap")
set(CMAKE_PROJECT_BUGREPORT_URL "https://github.com/zerebubuth/openstreetmap-cgimap/issues")
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()
# copy final library files to binary dir root
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# default to release build
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
###############
# build options
###############
option(ENABLE_YAJL "Enable JSON output with the YAJL library" ON)
option(ENABLE_BROTLI "Enable Brotli library" ON)
option(ENABLE_FMT_HEADER "Enable FMT header only mode" ON)
option(ENABLE_COVERAGE "Compile with coverage info collection" OFF)
option(ENABLE_PROFILING "Compile with profiling" OFF)
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
option(ENABLE_INSTALL "Enable installation" ON)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
option(BUILD_TESTING "Compile test suite" ON)
else()
option(BUILD_TESTING "Compile test suite" OFF)
endif()
include(CTest)
include(AutotoolsCompatibilityDefinitions)
include(BuildLint)
#########################
# common compiler options
#########################
add_library(cgimap_common_compiler_options INTERFACE)
target_compile_features(cgimap_common_compiler_options INTERFACE cxx_std_17)
target_compile_definitions(cgimap_common_compiler_options INTERFACE CMAKE=1
BOOST_BIND_GLOBAL_PLACEHOLDERS)
target_add_autotools_compatibility_definitions(cgimap_common_compiler_options)
if(ENABLE_COVERAGE)
include(CodeCoverage)
target_add_code_coverage(cgimap_common_compiler_options)
endif()
if(ENABLE_PROFILING)
include(Profiling)
target_add_profiling(cgimap_common_compiler_options)
endif()
##############
# dependencies
##############
find_package(Threads REQUIRED)
find_package(PQXX 6.0 REQUIRED)
find_package(LibXml2 2.6.31 REQUIRED)
find_package(Libmemcached REQUIRED)
find_package(Boost 1.43 REQUIRED COMPONENTS program_options)
target_compile_definitions(cgimap_common_compiler_options INTERFACE
HAVE_BOOST=$<BOOL:${Boost_FOUND}>
HAVE_BOOST_PROGRAM_OPTIONS=$<BOOL:${Boost_PROGRAM_OPTIONS_FOUND}>)
find_package(ZLIB REQUIRED)
target_compile_definitions(cgimap_common_compiler_options INTERFACE
HAVE_LIBZ=$<BOOL:${ZLIB_FOUND}>)
find_package(CryptoPP REQUIRED)
target_compile_definitions(cgimap_common_compiler_options INTERFACE
HAVE_CRYPTOPP=$<BOOL:${CryptoPP_FOUND}>)
if(ENABLE_YAJL)
find_package(YAJL 2 REQUIRED)
endif()
target_compile_definitions(cgimap_common_compiler_options INTERFACE
HAVE_YAJL=$<BOOL:${YAJL_FOUND}>)
if(ENABLE_BROTLI)
find_package(Brotli COMPONENTS encoder decoder common REQUIRED)
endif()
target_compile_definitions(cgimap_common_compiler_options INTERFACE
HAVE_BROTLI=$<BOOL:${Brotli_FOUND}>)
find_package(Fcgi REQUIRED)
target_compile_definitions(cgimap_common_compiler_options INTERFACE
HAVE_FCGI=$<BOOL:${Fcgi_FOUND}>)
find_package(fmt 6.0 REQUIRED)
target_link_libraries(cgimap_common_compiler_options INTERFACE
$<IF:$<BOOL:${ENABLE_FMT_HEADER}>,fmt::fmt-header-only,fmt::fmt>)
###########################
# source subdirectories
###########################
add_subdirectory(contrib)
add_subdirectory(src)
add_subdirectory(test)
#################################
# openstreetmap-cgimap executable
#################################
add_executable(openstreetmap_cgimap)
set_target_properties(openstreetmap_cgimap PROPERTIES
OUTPUT_NAME "openstreetmap-cgimap")
target_sources(openstreetmap_cgimap PRIVATE
src/main.cpp)
target_link_libraries(openstreetmap_cgimap
cgimap_common_compiler_options
cgimap_core
cgimap_fcgi
cgimap_apidb
Boost::program_options
PQXX::PQXX)
#############################################################
# Optional "clang-tidy" target
#############################################################
# BuildLint module already checks for clang-tidy
if(CLANG_TIDY)
file(GLOB CT_CHECK_FILES src/*.cpp src/api06/*.cpp src/api06/changeset_upload/*.cpp src/api07/*.cpp
src/backend/apidb/*.cpp src/backend/apidb/changeset_upload/*.cpp
test/*.cpp test/*.hpp)
add_custom_target(clang-tidy
${CLANG_TIDY}
-extra-arg=-std=c++17
-p ${CMAKE_BINARY_DIR}
${CT_CHECK_FILES}
)
endif()
#############################################################
# Install
#############################################################
if(ENABLE_INSTALL)
include(GNUInstallDirs)
set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
set(CGIMAP_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
if(BUILD_SHARED_LIBS)
set(CGIMAP_LIBS cgimap_core cgimap_fcgi cgimap_apidb cgimap_libxml++)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.23.0)
set(CGIMAP_HEADER_FILE_SET_INSTALL_ARTIFACTS
FILE_SET HEADERS
COMPONENT Development
DESTINATION ${CGIMAP_INSTALL_INCLUDEDIR}
EXCLUDE_FROM_ALL)
endif()
install(TARGETS openstreetmap_cgimap ${CGIMAP_LIBS}
RUNTIME
COMPONENT Runtime
LIBRARY
COMPONENT Libraries
PUBLIC_HEADER
COMPONENT Development
DESTINATION ${CGIMAP_INSTALL_INCLUDEDIR}
EXCLUDE_FROM_ALL
PRIVATE_HEADER
COMPONENT Development
DESTINATION ${CGIMAP_INSTALL_INCLUDEDIR}
EXCLUDE_FROM_ALL
${CGIMAP_HEADER_FILE_SET_INSTALL_ARTIFACTS})
install(DIRECTORY doc/man1
TYPE MAN
COMPONENT Runtime)
install(FILES README TYPE DOC
COMPONENT Runtime)
endif()
#############################################################
# Debian packaging
#############################################################
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_DESCRIPTION "A comprehensive list of supported endpoints can be found at https://github.com/zerebubuth/openstreetmap-cgimap")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenStreetMap CGImap - Performance optimized implementation of selected parts of the OSM API")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(CPACK_STRIP_FILES "TRUE")
set(CPACK_VERBATIM_VARIABLES YES)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "mmd <${CPACK_PACKAGE_CONTACT}>")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS YES)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
# Set to YES to create individual packages for components instead of everything in one package
set(CPACK_DEB_COMPONENT_INSTALL NO)
set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "${PROJECT_NAME}-libs")
set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "${PROJECT_NAME}-dev")
include(CPack)
cpack_add_component(Libraries
DISPLAY_NAME "openstreetmap-cgimap libraries"
DESCRIPTION "Libraries required to run openstreetmap-cgimap")
if(BUILD_SHARED_LIBS)
set(CGIMAP_RUNTIME_COMPONENT_DEPENDENCIES Libraries)
endif()
cpack_add_component(Runtime
DISPLAY_NAME "openstreetmap-cgimap runtime binary"
DEPENDS ${CGIMAP_RUNTIME_COMPONENT_DEPENDENCIES})
cpack_add_component(Development
DISPLAY_NAME "openstreetmap-cgimap development headers"
DESCRIPTION "Header files required for development using openstreetmap-cgimap libraries"
DEPENDS Libraries)