-
Notifications
You must be signed in to change notification settings - Fork 192
/
CMakeLists.txt
322 lines (274 loc) · 8.89 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
#-----------------------------------------------------------------------------
#
# CMake Config
#
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#-----------------------------------------------------------------------------
#
# Project version
#
#-----------------------------------------------------------------------------
project(mod_tile
DESCRIPTION "Renders map tiles with Mapnik and serves them using Apache HTTP Server"
HOMEPAGE_URL "https://github.com/openstreetmap/mod_tile"
VERSION 0.8.0
)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11 CACHE STRING "Sets the C++ standard.")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_INSTALL_MODULESDIR CACHE PATH "Apache HTTP Server module installation directory")
set(ENABLE_MAN ON CACHE BOOL "Build man pages")
set(ENABLE_TESTS OFF CACHE BOOL "Build test suite")
set(USE_CAIRO ON CACHE BOOL "Add cairo support if available (for `store_ro_composite.c` backend)")
set(USE_CURL ON CACHE BOOL "Add curl support if available (for `store_ro_http_proxy.c` backend)")
set(USE_MEMCACHED ON CACHE BOOL "Add memcached support if available (for `store_memcached.c` backend)")
set(USE_RADOS ON CACHE BOOL "Add rados support if available (for `store_rados.c` backend)")
set(MALLOC_LIB "libc" CACHE STRING "Memory Management Library for `renderd`")
set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcmalloc")
#-----------------------------------------------------------------------------
#
# Find external dependencies
#
#-----------------------------------------------------------------------------
include(GNUInstallDirs)
# Packages
find_package(ICU REQUIRED uc)
find_package(Threads REQUIRED)
find_package(APR REQUIRED)
find_package(GLIB 2.50 REQUIRED)
find_package(HTTPD 2.4 REQUIRED)
find_package(INIPARSER REQUIRED)
find_package(LIBMAPNIK 3 REQUIRED)
if(LIBMAPNIK_VERSION VERSION_GREATER_EQUAL 4)
set(CMAKE_CXX_STANDARD 17)
endif()
if(USE_CURL)
find_package(CURL)
endif()
if(USE_CAIRO)
find_package(CAIRO)
endif()
if(USE_MEMCACHED)
find_package(LIBMEMCACHED)
endif()
if(USE_RADOS)
find_package(LIBRADOS)
endif()
# Programs
find_program(APXS_EXECUTABLE apxs REQUIRED)
# Functions
include(CheckFunctionExists)
check_function_exists(daemon HAVE_DAEMON)
check_function_exists(getloadavg HAVE_GETLOADAVG)
check_function_exists(pow HAVE_POW)
# Include files
include(CheckIncludeFile)
check_include_file(paths.h HAVE_PATHS_H)
check_include_file(sys/cdefs.h HAVE_SYS_CDEFS_H)
check_include_file(sys/loadavg.h HAVE_SYS_LOADAVG_H)
# Libraries
include(CheckLibraryExists)
if(NOT HAVE_POW)
check_library_exists(m pow "" HAVE_LIB_M)
find_library(MATH_LIBRARY m REQUIRED)
endif()
if(NOT MALLOC_LIB STREQUAL "libc")
message(STATUS "Using '${MALLOC_LIB}' for memory managment")
if(MALLOC_LIB STREQUAL "jemalloc")
# jemalloc (http://jemalloc.net)
find_library(MALLOC_LIBRARY jemalloc REQUIRED)
elseif(MALLOC_LIB STREQUAL "mimalloc")
# mimalloc (https://github.com/microsoft/mimalloc)
find_library(MALLOC_LIBRARY mimalloc REQUIRED)
elseif(MALLOC_LIB STREQUAL "tcmalloc")
# tcmalloc (https://github.com/google/tcmalloc)
find_library(MALLOC_LIBRARY tcmalloc REQUIRED)
endif()
endif()
#-----------------------------------------------------------------------------
#
# Set variables
#
#-----------------------------------------------------------------------------
execute_process(COMMAND ${APXS_EXECUTABLE} -q libexecdir
OUTPUT_VARIABLE HTTPD_LIBEXECDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND ${APXS_EXECUTABLE} -q sysconfdir
OUTPUT_VARIABLE HTTPD_SYSCONFDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(LIBMAPNIK_VERSION VERSION_LESS 4)
find_program(MAPNIK_CONFIG_EXECUTABLE NAMES mapnik-config REQUIRED)
execute_process(COMMAND ${MAPNIK_CONFIG_EXECUTABLE} --fonts
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE MAPNIK_FONTS_DIR
)
execute_process(COMMAND ${MAPNIK_CONFIG_EXECUTABLE} --input-plugins
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE MAPNIK_PLUGINS_DIR
)
elseif(LIBMAPNIK_VERSION VERSION_GREATER_EQUAL 4)
pkg_get_variable(MAPNIK_FONTS_DIR libmapnik fonts_dir)
pkg_get_variable(MAPNIK_PLUGINS_DIR libmapnik plugins_dir)
endif()
if(NOT CMAKE_INSTALL_MODULESDIR)
set(CMAKE_INSTALL_MODULESDIR ${HTTPD_LIBEXECDIR})
endif()
if(CAIRO_FOUND)
set(HAVE_CAIRO 1)
endif()
if(CURL_FOUND)
set(HAVE_LIBCURL 1)
endif()
if(LIBMEMCACHED_FOUND)
set(HAVE_LIBMEMCACHED 1)
endif()
if(LIBRADOS_FOUND)
set(HAVE_LIBRADOS 1)
endif()
if(CMAKE_HAVE_PTHREAD_H)
set(HAVE_PTHREAD 1)
endif()
set(MAPNIK_FONTS_DIR "${MAPNIK_FONTS_DIR}")
set(MAPNIK_FONTS_DIR_RECURSE 0)
set(MAPNIK_PLUGINS_DIR "${MAPNIK_PLUGINS_DIR}")
set(RENDERD_CONFIG "${CMAKE_INSTALL_SYSCONFDIR}/renderd.conf")
set(RENDERD_RUN_DIR "${CMAKE_INSTALL_RUNSTATEDIR}/renderd")
set(RENDERD_TILE_DIR "${CMAKE_INSTALL_LOCALSTATEDIR}/cache/renderd/tiles")
set(RENDERD_PIDFILE "${RENDERD_RUN_DIR}/renderd.pid")
set(RENDERD_SOCKET "${RENDERD_RUN_DIR}/renderd.sock")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}")
set(TILE_LOAD_FILENAME "tile.load")
set(VERSION "${PROJECT_VERSION}")
#-----------------------------------------------------------------------------
#
# Configure
#
#-----------------------------------------------------------------------------
# include/config.h.in
configure_file(
${PROJECT_SOURCE_DIR}/includes/config.h.in
${PROJECT_SOURCE_DIR}/includes/config.h
)
# etc/apache2/tile.load.in
configure_file(
${PROJECT_SOURCE_DIR}/etc/apache2/tile.load.in
${PROJECT_BINARY_DIR}/tile.load
)
# etc/renderd/renderd.conf.in
configure_file(
${PROJECT_SOURCE_DIR}/etc/renderd/renderd.conf.in
${PROJECT_BINARY_DIR}/renderd.conf
)
#-----------------------------------------------------------------------------
#
# Build
#
#-----------------------------------------------------------------------------
add_subdirectory(src)
#-----------------------------------------------------------------------------
#
# Install
#
#-----------------------------------------------------------------------------
# Determine install destination for 'etc/apache2/tile.load.in'
if(EXISTS "/etc/os-release")
execute_process(COMMAND sh -c ". /etc/os-release && echo $ID"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE DISTRO_ID
)
message(STATUS "Found ID='${DISTRO_ID}' in '/etc/os-release'")
if(DISTRO_ID MATCHES "arch")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/extra")
set(TILE_LOAD_FILENAME "httpd-tile.conf")
elseif(DISTRO_ID MATCHES "centos|fedora|rhel")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}.modules.d")
set(TILE_LOAD_FILENAME "11-tile.conf")
elseif(DISTRO_ID MATCHES "debian|ubuntu")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/mods-available")
elseif(DISTRO_ID MATCHES "freebsd")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/modules.d")
set(TILE_LOAD_FILENAME "080_tile.conf")
elseif(DISTRO_ID MATCHES "opensuse-leap|opensuse-tumbleweed")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/conf.d")
set(TILE_LOAD_FILENAME "mod_tile.conf")
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/extra")
set(TILE_LOAD_FILENAME "httpd-tile.conf")
endif()
message(STATUS "File 'etc/apache2/tile.load.in' will be installed to '${TILE_LOAD_DIRECTORY}/${TILE_LOAD_FILENAME}'")
# Directories
install(
DIRECTORY
DESTINATION ${RENDERD_TILE_DIR}
)
install(
DIRECTORY
DESTINATION ${RENDERD_RUN_DIR}
)
# Configuration files
install(
FILES
${PROJECT_BINARY_DIR}/tile.load
DESTINATION ${TILE_LOAD_DIRECTORY}
RENAME ${TILE_LOAD_FILENAME}
)
install(
FILES
${PROJECT_BINARY_DIR}/renderd.conf
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
)
# Targets
install(
TARGETS
mod_tile
render_expired
render_list
render_old
render_speedtest
renderd
LIBRARY DESTINATION ${CMAKE_INSTALL_MODULESDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Man files
if(ENABLE_MAN)
install(
FILES
docs/man/render_expired.1
docs/man/render_list.1
docs/man/render_old.1
docs/man/render_speedtest.1
docs/man/renderd.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
)
install(
FILES
docs/man/renderd.conf.5
DESTINATION ${CMAKE_INSTALL_MANDIR}/man5
)
endif()
#-----------------------------------------------------------------------------
#
# Package
#
#-----------------------------------------------------------------------------
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_PACKAGE_CONTACT "OpenStreetMap")
set(CPACK_PACKAGE_VENDOR "OpenStreetMap")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
include(CPack)
#-----------------------------------------------------------------------------
#
# Test
#
#-----------------------------------------------------------------------------
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()