Skip to content

Commit 6e20fba

Browse files
authored
Generate config files and directories with CMake (#316)
* Generate config files and directories with CMake CMake >= 3.13 required due to 'https://cmake.org/Bug/view.php?id=14444' * Update CI pipeline
1 parent fbf4c7e commit 6e20fba

20 files changed

Lines changed: 201 additions & 91 deletions

.github/actions/cmake/install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ runs:
33
using: composite
44
steps:
55
- name: Install `mod_tile`
6-
run: cmake --install build
6+
run: ${{ !matrix.image && 'sudo' || '' }} cmake --install build
77
shell: bash --noprofile --norc -euxo pipefail {0}

.github/actions/cmake/test/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ runs:
1717
- name: Archive test artifacts on failure
1818
if: failure()
1919
run: |
20-
TAR_FILENAME=${{ matrix.image }}-${{ matrix.compiler }}.tar.gz
20+
TAR_FILENAME=${{ matrix.image || matrix.os }}-${{ matrix.compiler }}.tar.gz
2121
TAR_FILENAME=$(echo "${TAR_FILENAME}" | sed 's/:/-/g')
2222
tar -zcf /tmp/${TAR_FILENAME} tests
2323
shell: bash --noprofile --norc -euxo pipefail {0}

.github/workflows/build-and-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ jobs:
9090
CFLAGS: -Wno-implicit-function-declaration
9191
LDFLAGS: -undefined dynamic_lookup
9292
LIBRARY_PATH: /usr/local/lib
93-
name: ${{ matrix.image }} (${{ matrix.build_system }}) (${{ matrix.compiler }})
94-
runs-on: ${{ matrix.image }}
93+
name: ${{ matrix.os }} (${{ matrix.build_system }}) (${{ matrix.compiler }})
94+
runs-on: ${{ matrix.os }}
9595
strategy:
9696
fail-fast: false
9797
matrix:
98-
image:
98+
os:
9999
- macos-11
100100
- macos-12
101101
build_system:
@@ -105,10 +105,10 @@ jobs:
105105
on_default_branch:
106106
- ${{ contains(github.ref, 'master') || contains(github.ref, 'develop') }}
107107
include:
108-
- image: macos-13
108+
- os: macos-13
109109
build_system: Autotools
110110
compiler: LLVM
111-
- image: macos-13
111+
- os: macos-13
112112
build_system: CMake
113113
compiler: LLVM
114114
exclude:

CMakeLists.txt

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
#-----------------------------------------------------------------------------
66

7-
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
7+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
88
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
99

1010
#-----------------------------------------------------------------------------
@@ -101,13 +101,33 @@ check_include_file(sys/loadavg.h HAVE_SYS_LOADAVG_H)
101101
#
102102
#-----------------------------------------------------------------------------
103103

104-
execute_process(COMMAND ${APXS_EXECUTABLE} -q exp_libexecdir
105-
OUTPUT_VARIABLE HTTPD_MODULES_DIR
104+
execute_process(COMMAND ${APXS_EXECUTABLE} -q libexecdir
105+
OUTPUT_VARIABLE HTTPD_LIBEXECDIR
106106
OUTPUT_STRIP_TRAILING_WHITESPACE
107107
)
108108

109+
execute_process(COMMAND ${APXS_EXECUTABLE} -q sysconfdir
110+
OUTPUT_VARIABLE HTTPD_SYSCONFDIR
111+
OUTPUT_STRIP_TRAILING_WHITESPACE
112+
)
113+
114+
if(LibMapnik_VERSION STRLESS "4")
115+
find_program(MAPNIK_CONFIG_EXECUTABLE NAMES mapnik-config REQUIRED)
116+
execute_process(COMMAND ${MAPNIK_CONFIG_EXECUTABLE} --fonts
117+
OUTPUT_STRIP_TRAILING_WHITESPACE
118+
OUTPUT_VARIABLE MAPNIK_FONTS_DIR
119+
)
120+
execute_process(COMMAND ${MAPNIK_CONFIG_EXECUTABLE} --input-plugins
121+
OUTPUT_STRIP_TRAILING_WHITESPACE
122+
OUTPUT_VARIABLE MAPNIK_PLUGINS_DIR
123+
)
124+
elseif(LibMapnik_VERSION STRGREATER_EQUAL "4")
125+
pkg_get_variable(MAPNIK_FONTS_DIR libmapnik fonts_dir)
126+
pkg_get_variable(MAPNIK_PLUGINS_DIR libmapnik plugins_dir)
127+
endif()
128+
109129
if(NOT CMAKE_INSTALL_MODULESDIR)
110-
set(CMAKE_INSTALL_MODULESDIR ${HTTPD_MODULES_DIR})
130+
set(CMAKE_INSTALL_MODULESDIR ${HTTPD_LIBEXECDIR})
111131
endif()
112132

113133
if(Cairo_FOUND)
@@ -130,19 +150,44 @@ if(CMAKE_HAVE_PTHREAD_H)
130150
set(HAVE_PTHREAD 1)
131151
endif()
132152

133-
set(VERSION ${PROJECT_VERSION})
153+
set(MAPNIK_FONTS_DIR "${MAPNIK_FONTS_DIR}")
154+
set(MAPNIK_FONTS_DIR_RECURSE 0)
155+
set(MAPNIK_PLUGINS_DIR "${MAPNIK_PLUGINS_DIR}")
156+
set(RENDERD_CONFIG "/${CMAKE_INSTALL_SYSCONFDIR}/renderd.conf")
157+
set(RENDERD_RUN_DIR "/${CMAKE_INSTALL_RUNSTATEDIR}/renderd")
158+
set(RENDERD_TILE_DIR "/${CMAKE_INSTALL_LOCALSTATEDIR}/cache/renderd/tiles")
159+
160+
set(RENDERD_PIDFILE "${RENDERD_RUN_DIR}/renderd.pid")
161+
set(RENDERD_SOCKET "${RENDERD_RUN_DIR}/renderd.sock")
162+
163+
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}")
164+
set(TILE_LOAD_FILENAME "tile.load")
165+
set(VERSION "${PROJECT_VERSION}")
134166

135167
#-----------------------------------------------------------------------------
136168
#
137-
# config.h
169+
# Configure
138170
#
139171
#-----------------------------------------------------------------------------
140172

173+
# include/config.h.in
141174
configure_file(
142175
${PROJECT_SOURCE_DIR}/includes/config.h.in
143176
${PROJECT_SOURCE_DIR}/includes/config.h
144177
)
145178

179+
# etc/apache2/tile.load.in
180+
configure_file(
181+
${PROJECT_SOURCE_DIR}/etc/apache2/tile.load.in
182+
${PROJECT_BINARY_DIR}/tile.load
183+
)
184+
185+
# etc/renderd/renderd.conf.in
186+
configure_file(
187+
${PROJECT_SOURCE_DIR}/etc/renderd/renderd.conf.in
188+
${PROJECT_BINARY_DIR}/renderd.conf
189+
)
190+
146191
#-----------------------------------------------------------------------------
147192
#
148193
# Build
@@ -157,6 +202,57 @@ add_subdirectory(src)
157202
#
158203
#-----------------------------------------------------------------------------
159204

205+
# Determine install destination for 'etc/apache2/tile.load.in'
206+
if(EXISTS "/etc/os-release")
207+
execute_process(COMMAND sh -c ". /etc/os-release && echo $ID"
208+
OUTPUT_STRIP_TRAILING_WHITESPACE
209+
OUTPUT_VARIABLE DISTRO_ID
210+
)
211+
message(STATUS "Found ID='${DISTRO_ID}' in '/etc/os-release'")
212+
if(DISTRO_ID MATCHES "arch")
213+
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/extra")
214+
set(TILE_LOAD_FILENAME "httpd-tile.conf")
215+
elseif(DISTRO_ID MATCHES "centos|fedora|rhel")
216+
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}.modules.d")
217+
set(TILE_LOAD_FILENAME "11-tile.conf")
218+
elseif(DISTRO_ID MATCHES "debian|ubuntu")
219+
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/mods-available")
220+
elseif(DISTRO_ID MATCHES "freebsd")
221+
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/modules.d")
222+
set(TILE_LOAD_FILENAME "080_tile.conf")
223+
endif()
224+
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
225+
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}/extra")
226+
set(TILE_LOAD_FILENAME "httpd-tile.conf")
227+
endif()
228+
message(STATUS "File 'etc/apache2/tile.load.in' will be installed to '${TILE_LOAD_DIRECTORY}/${TILE_LOAD_FILENAME}'")
229+
230+
# Directories
231+
install(
232+
DIRECTORY
233+
DESTINATION ${RENDERD_TILE_DIR}
234+
)
235+
236+
install(
237+
DIRECTORY
238+
DESTINATION ${RENDERD_RUN_DIR}
239+
)
240+
241+
# Configuration files
242+
install(
243+
FILES
244+
${PROJECT_BINARY_DIR}/tile.load
245+
DESTINATION ${TILE_LOAD_DIRECTORY}
246+
RENAME ${TILE_LOAD_FILENAME}
247+
)
248+
249+
install(
250+
FILES
251+
${PROJECT_BINARY_DIR}/renderd.conf
252+
DESTINATION /${CMAKE_INSTALL_SYSCONFDIR}
253+
)
254+
255+
# Targets
160256
install(
161257
TARGETS
162258
mod_tile
@@ -169,6 +265,7 @@ install(
169265
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
170266
)
171267

268+
# Man files
172269
if (ENABLE_MAN)
173270
install(
174271
FILES

etc/apache2/tile.load.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LoadModule tile_module @CMAKE_INSTALL_MODULESDIR@/mod_tile.so

etc/renderd/renderd.conf.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[renderd]
2+
pid_file=@RENDERD_PIDFILE@
3+
socketname=@RENDERD_SOCKET@
4+
stats_file=@RENDERD_RUN_DIR@/renderd.stats
5+
tile_dir=@RENDERD_TILE_DIR@
6+
7+
[mapnik]
8+
font_dir=@MAPNIK_FONTS_DIR@
9+
font_dir_recurse=@MAPNIK_FONTS_DIR_RECURSE@
10+
plugins_dir=@MAPNIK_PLUGINS_DIR@

includes/config.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,14 @@
1414
#cmakedefine HAVE_LIBMEMCACHED @HAVE_LIBMEMCACHED@
1515
#cmakedefine HAVE_LIBRADOS @HAVE_LIBRADOS@
1616

17+
/* Define configuration options. */
18+
#cmakedefine MAPNIK_FONTS_DIR "@MAPNIK_FONTS_DIR@"
19+
#cmakedefine MAPNIK_FONTS_DIR_RECURSE "@MAPNIK_FONTS_DIR_RECURSE@"
20+
#cmakedefine MAPNIK_PLUGINS_DIR "@MAPNIK_PLUGINS_DIR@"
21+
#cmakedefine RENDERD_CONFIG "@RENDERD_CONFIG@"
22+
#cmakedefine RENDERD_PIDFILE "@RENDERD_PIDFILE@"
23+
#cmakedefine RENDERD_SOCKET "@RENDERD_SOCKET@"
24+
#cmakedefine RENDERD_TILE_DIR "@RENDERD_TILE_DIR@"
25+
1726
/* Version number of project */
1827
#cmakedefine VERSION "@VERSION@"

includes/protocol.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef PROTOCOL_H
1919
#define PROTOCOL_H
2020

21+
#include "config.h"
22+
2123
#ifdef __cplusplus
2224
extern "C" {
2325
#endif
@@ -34,9 +36,15 @@ extern "C" {
3436
*/
3537
#define TILE_PATH_MAX (256)
3638
#define PROTO_VER (3)
37-
#define RENDER_SOCKET "/run/renderd/renderd.sock"
38-
#define RENDER_HOST "localhost"
39-
#define RENDER_PORT 7654
39+
#ifndef RENDERD_SOCKET
40+
#define RENDERD_SOCKET "/run/renderd/renderd.sock"
41+
#endif
42+
#ifndef RENDERD_HOST
43+
#define RENDERD_HOST "localhost"
44+
#endif
45+
#ifndef RENDERD_PORT
46+
#define RENDERD_PORT 7654
47+
#endif
4048
#define XMLCONFIG_MAX 41
4149

4250
enum protoCmd { cmdIgnore, cmdRender, cmdDirty, cmdDone, cmdNotDone, cmdRenderPrio, cmdRenderBulk, cmdRenderLow };

includes/render_config.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
#ifndef RENDER_CONFIG_H
1919
#define RENDER_CONFIG_H
2020

21+
#include "config.h"
22+
2123
#define MAX_ZOOM 20
2224

2325
// MAX_SIZE is the biggest file which we will return to the user
2426
#define MAX_SIZE (1 * 1024 * 1024)
2527

2628
// With directory hashing enabled we rewrite the path so that tiles are really stored here instead
2729
#define DIRECTORY_HASH
28-
#define HASH_PATH "/var/cache/renderd/tiles"
30+
#ifndef RENDERD_TILE_DIR
31+
#define RENDERD_TILE_DIR "/var/cache/renderd/tiles"
32+
#endif
2933

3034
// TILE_PATH is where Openlayers with try to fetch the "z/x/y.png" tiles from
3135
// this is now only used if DIRECTORY_HASH is undefined
@@ -45,20 +49,34 @@
4549
#define VERYOLD_THRESHOLD 31536000000000
4650

4751
// Location of osm.xml file
52+
#ifndef RENDERD_CONFIG
4853
#define RENDERD_CONFIG "/etc/renderd.conf"
54+
#endif
4955
// The XML configuration used if one is not provided
56+
#ifndef XMLCONFIG_DEFAULT
5057
#define XMLCONFIG_DEFAULT "default"
58+
#endif
5159
// Maximum number of configurations that mod tile will allow
60+
#ifndef XMLCONFIGS_MAX
5261
#define XMLCONFIGS_MAX 10
62+
#endif
5363
// Default PID file path
54-
#define PIDFILE "/run/renderd/renderd.pid"
64+
#ifndef RENDERD_PIDFILE
65+
#define RENDERD_PIDFILE "/run/renderd/renderd.pid"
66+
#endif
5567

5668
// Mapnik input plugins (will need to adjust for 32 bit libs)
57-
#define MAPNIK_PLUGINS "/usr/local/lib64/mapnik/input"
69+
#ifndef MAPNIK_PLUGINS_DIR
70+
#define MAPNIK_PLUGINS_DIR "/usr/local/lib64/mapnik/input"
71+
#endif
5872

5973
// Default directory to search for fonts. Recursion can be enabled if desired.
60-
#define FONT_DIR "/usr/local/lib64/mapnik/fonts"
61-
#define FONT_RECURSE 0
74+
#ifndef MAPNIK_FONTS_DIR
75+
#define MAPNIK_FONTS_DIR "/usr/local/lib64/mapnik/fonts"
76+
#endif
77+
#ifndef MAPNIK_FONTS_DIR_RECURSE
78+
#define MAPNIK_FONTS_DIR_RECURSE 0
79+
#endif
6280

6381
// Typical interval between planet imports, used as basis for tile expiry times
6482
#define PLANET_INTERVAL (7 * 24 * 60 * 60)

src/convert_meta.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "dir_utils.h"
4141
#include "store.h"
4242

43-
char *tile_dir = HASH_PATH;
43+
char *tile_dir = RENDERD_TILE_DIR;
4444

4545
#ifndef METATILE
4646
#warning("convert_meta not implemented for non-metatile mode. Feel free to submit fix")
@@ -188,7 +188,7 @@ int main(int argc, char **argv)
188188
fprintf(stderr, "Usage: convert_meta [OPTION] ...\n");
189189
fprintf(stderr, "Convert the rendered PNGs into the more efficient .meta format\n");
190190
fprintf(stderr, " -m, --map convert tiles in this map (default is 'default')\n");
191-
fprintf(stderr, " -t, --tile-dir tile cache directory (default is '" HASH_PATH "')\n");
191+
fprintf(stderr, " -t, --tile-dir tile cache directory (default is '" RENDERD_TILE_DIR "')\n");
192192
fprintf(stderr, " -u, --unpack unpack the .meta files back to PNGs\n");
193193
fprintf(stderr, " -z, --min-zoom only process tiles greater or equal to this zoom level (default is 0)\n");
194194
fprintf(stderr, " -Z, --max-zoom only process tiles less than or equal to this zoom level (default is %d)\n", MAX_ZOOM);

0 commit comments

Comments
 (0)