Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 69 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#-----------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

#-----------------------------------------------------------------------------
Expand All @@ -21,17 +21,20 @@ project(mod_tile

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 14 CACHE STRING "Sets the C++ standard (C++14 minimum; Catch2 v3 requires it).")
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)")
option(ENABLE_MAN "Build man pages" ON)
option(ENABLE_TESTS "Build test suite" OFF)
option(ENABLE_WARNINGS "Compile with extra warnings (-Wall -Wextra)" OFF)
option(ENABLE_WERROR "Treat compiler warnings as errors (requires ENABLE_WARNINGS)" OFF)
set(ENABLE_SANITIZERS "" CACHE STRING "Comma-separated sanitizers to build with, e.g. 'address,undefined' or 'thread'")
option(USE_CAIRO "Add cairo support if available (for `store_ro_composite.c` backend)" ON)
option(USE_CURL "Add curl support if available (for `store_ro_http_proxy.c` backend)" ON)
option(USE_MEMCACHED "Add memcached support if available (for `store_memcached.c` backend)" ON)
option(USE_RADOS "Add rados support if available (for `store_rados.c` backend)" ON)
set(MALLOC_LIB "libc" CACHE STRING "Memory Management Library for `renderd`")
set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcmalloc")

Expand All @@ -41,9 +44,11 @@ set_property(CACHE MALLOC_LIB PROPERTY STRINGS "libc" "jemalloc" "mimalloc" "tcm
#
#-----------------------------------------------------------------------------

include(FeatureSummary)
include(GNUInstallDirs)

# Packages
find_package(PkgConfig REQUIRED)
find_package(ICU REQUIRED uc)
find_package(Threads REQUIRED)

Expand All @@ -55,6 +60,10 @@ find_package(LIBMAPNIK 3 REQUIRED)

if(LIBMAPNIK_VERSION VERSION_GREATER_EQUAL 4)
set(CMAKE_CXX_STANDARD 17)
elseif(CMAKE_CXX_STANDARD LESS 14)
# e.g. an existing build directory whose cache still holds the old default of 11
message(WARNING "CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} is too old (Catch2 v3 needs C++14), using 14")
set(CMAKE_CXX_STANDARD 14)
endif()

if(USE_CURL)
Expand Down Expand Up @@ -171,8 +180,12 @@ 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")
if(NOT DEFINED CACHE{TILE_LOAD_DIRECTORY})
set(TILE_LOAD_DIRECTORY "${HTTPD_SYSCONFDIR}")
endif()
if(NOT DEFINED CACHE{TILE_LOAD_FILENAME})
set(TILE_LOAD_FILENAME "tile.load")
endif()
set(VERSION "${PROJECT_VERSION}")

#-----------------------------------------------------------------------------
Expand All @@ -182,9 +195,10 @@ set(VERSION "${PROJECT_VERSION}")
#-----------------------------------------------------------------------------

# include/config.h.in
# (generated into the build tree so that multiple build directories do not clobber each other)
configure_file(
${PROJECT_SOURCE_DIR}/includes/config.h.in
${PROJECT_SOURCE_DIR}/includes/config.h
${PROJECT_BINARY_DIR}/includes/config.h
)

# etc/apache2/tile.load.in
Expand All @@ -199,6 +213,32 @@ configure_file(
${PROJECT_BINARY_DIR}/renderd.conf
)

#-----------------------------------------------------------------------------
#
# Compiler flags
#
#-----------------------------------------------------------------------------

if(ENABLE_WARNINGS)
add_compile_options(-Wall -Wextra -Wno-unused-parameter)
# Log messages and storage IDs are deliberately truncated to PATH_MAX-sized buffers,
# so GCC's -Wformat-truncation heuristic only produces false positives here.
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wformat-truncation HAVE_WFORMAT_TRUNCATION)
if(HAVE_WFORMAT_TRUNCATION)
add_compile_options(-Wno-format-truncation)
endif()
if(ENABLE_WERROR)
add_compile_options(-Werror)
endif()
endif()

if(ENABLE_SANITIZERS)
message(STATUS "Building with sanitizers: ${ENABLE_SANITIZERS}")
add_compile_options(-fsanitize=${ENABLE_SANITIZERS} -fno-omit-frame-pointer)
add_link_options(-fsanitize=${ENABLE_SANITIZERS})
endif()

#-----------------------------------------------------------------------------
#
# Build
Expand All @@ -214,7 +254,11 @@ add_subdirectory(src)
#-----------------------------------------------------------------------------

# Determine install destination for 'etc/apache2/tile.load.in'
if(EXISTS "/etc/os-release")
# (auto-detected from the build host unless TILE_LOAD_DIRECTORY / TILE_LOAD_FILENAME are set explicitly,
# which packagers and cross-compilers should do)
if(DEFINED CACHE{TILE_LOAD_DIRECTORY} OR DEFINED CACHE{TILE_LOAD_FILENAME})
message(STATUS "Using user-supplied TILE_LOAD_DIRECTORY / TILE_LOAD_FILENAME")
elseif(EXISTS "/etc/os-release")
execute_process(COMMAND sh -c ". /etc/os-release && echo $ID"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE DISTRO_ID
Expand Down Expand Up @@ -320,3 +364,16 @@ if(ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

#-----------------------------------------------------------------------------
#
# Summary
#
#-----------------------------------------------------------------------------

add_feature_info(cairo CAIRO_FOUND "store_ro_composite backend")
add_feature_info(curl CURL_FOUND "store_ro_http_proxy backend")
add_feature_info(memcached LIBMEMCACHED_FOUND "store_memcached backend")
add_feature_info(rados LIBRADOS_FOUND "store_rados backend")
add_feature_info(tests ENABLE_TESTS "Catch2 test suite")
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
84 changes: 84 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Release",
"description": "Release build installed under /usr with FHS paths",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_INSTALL_LOCALSTATEDIR": "/var",
"CMAKE_INSTALL_PREFIX": "/usr",
"CMAKE_INSTALL_RUNSTATEDIR": "/run",
"CMAKE_INSTALL_SYSCONFDIR": "/etc"
}
},
{
"name": "dev",
"displayName": "Development",
"description": "Debug build with tests and extra warnings",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"ENABLE_TESTS": "ON",
"ENABLE_WARNINGS": "ON"
}
},
{
"name": "asan",
"displayName": "AddressSanitizer + UBSan",
"description": "Debug build with tests, instrumented with ASan and UBSan",
"inherits": "dev",
"cacheVariables": {
"ENABLE_SANITIZERS": "address,undefined"
}
},
{
"name": "tsan",
"displayName": "ThreadSanitizer",
"description": "Debug build with tests, instrumented with TSan (for renderd threading)",
"inherits": "dev",
"cacheVariables": {
"ENABLE_SANITIZERS": "thread"
}
}
],
"buildPresets": [
{ "name": "default", "configurePreset": "default" },
{ "name": "dev", "configurePreset": "dev" },
{ "name": "asan", "configurePreset": "asan" },
{ "name": "tsan", "configurePreset": "tsan" }
],
"testPresets": [
{
"name": "dev",
"configurePreset": "dev",
"output": { "outputOnFailure": true }
},
{
"name": "asan",
"configurePreset": "asan",
"output": { "outputOnFailure": true },
"environment": {
"ASAN_OPTIONS": "detect_leaks=0",
"UBSAN_OPTIONS": "halt_on_error=1:print_stacktrace=1"
}
},
{
"name": "tsan",
"configurePreset": "tsan",
"output": { "outputOnFailure": true },
"filter": { "include": { "name": "_test$|^unit_tests$" } },
"environment": {
"TSAN_OPTIONS": "suppressions=${sourceDir}/tests/tsan.supp"
}
}
]
}
20 changes: 11 additions & 9 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = foreign

ACLOCAL_AMFLAGS = -I m4

AM_CPPFLAGS = $(PTHREAD_CFLAGS) $(GLIB_CFLAGS)
AM_CPPFLAGS = $(PTHREAD_CFLAGS) $(GLIB_CFLAGS) $(INIPARSER_CFLAGS)

STORE_SOURCES = \
src/g_logger.c \
Expand Down Expand Up @@ -98,7 +98,9 @@ render_speedtest_LDADD = $(PTHREAD_CFLAGS) $(GLIB_LIBS) $(INIPARSER_LDFLAGS)

#convert_meta_SOURCES = src/dir_utils.c src/store.c src/convert_meta.c

noinst_LIBRARIES = catch_main.o catch_test_common.o
noinst_LIBRARIES = catch2.o catch_main.o catch_test_common.o
catch2_o_SOURCES = tests/catch/catch_amalgamated.cpp
catch2_o_CPPFLAGS = -DCATCH_AMALGAMATED_CUSTOM_MAIN
catch_main_o_SOURCES = tests/catch_main.cpp
catch_test_common_o_SOURCES = tests/catch_test_common.cpp

Expand All @@ -107,32 +109,32 @@ gen_tile_test_SOURCES = \
$(renderd_SOURCES)
gen_tile_test_CFLAGS = -DMAIN_ALREADY_DEFINED
gen_tile_test_CXXFLAGS = $(renderd_CXXFLAGS)
gen_tile_test_LDADD = $(renderd_LDADD) catch_test_common.o
gen_tile_test_LDADD = $(renderd_LDADD) catch_test_common.o catch2.o

renderd_test_SOURCES = \
tests/renderd_test.cpp
renderd_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
renderd_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o catch2.o

render_expired_test_SOURCES = \
tests/render_expired_test.cpp
render_expired_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
render_expired_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o catch2.o

render_list_test_SOURCES = \
tests/render_list_test.cpp
render_list_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
render_list_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o catch2.o

render_old_test_SOURCES = \
tests/render_old_test.cpp
render_old_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
render_old_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o catch2.o

render_speedtest_test_SOURCES = \
tests/render_speedtest_test.cpp
render_speedtest_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
render_speedtest_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o catch2.o

unit_tests_SOURCES = \
tests/unit_tests.cpp
unit_tests_CXXFLAGS = -Isrc
unit_tests_LDADD = $(GLIB_LIBS) $(INIPARSER_LDFLAGS) $(MAPNIK_LDFLAGS) $(PTHREAD_CFLAGS) catch_main.o catch_test_common.o
unit_tests_LDADD = $(GLIB_LIBS) $(INIPARSER_LDFLAGS) $(MAPNIK_LDFLAGS) $(PTHREAD_CFLAGS) catch_main.o catch_test_common.o catch2.o

CLEANFILES=*.slo mod_tile.la stderr.out src/*.slo src/*.lo src/.libs/* src/*.la

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Dependencies
* `macOS`
* `Supported Build Systems`
* `CMake <https://cmake.org/>`__
* `GNU Autotools <https://www.gnu.org/software/software.html>`__
* `GNU Autotools <https://www.gnu.org/software/software.html>`__ (deprecated, use CMake)
* `Runtime/Build Dependencies`
* `Apache 2 HTTP webserver <https://httpd.apache.org/>`__
* `Cairo 2D graphics library (optional) <https://cairographics.org/>`__
Expand Down
27 changes: 21 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

# Define mod_tile version number
m4_define([mod_tile_version], [0.8.1])
# NOTE: The Autotools build is deprecated; CMake is the supported build system.

# mod_tile version number, taken from CMakeLists.txt so it is only defined in one place
m4_define([mod_tile_version],
m4_esyscmd_s([sed -n 's/^ VERSION \([0-9][0-9.]*\)$/\1/p' CMakeLists.txt]))
m4_if(mod_tile_version, [], [m4_fatal([Could not read the project version from CMakeLists.txt])])

AC_PREREQ([2.61])
AX_CONFIG_NICE
AC_INIT([mod_tile],
[mod_tile_version],
[http://trac.openstreetmap.org])
[https://github.com/openstreetmap/mod_tile/issues])
AM_INIT_AUTOMAKE([subdir-objects])
LT_INIT
AC_CONFIG_SRCDIR([src/mod_tile.c])
Expand Down Expand Up @@ -64,10 +68,15 @@ AC_CHECK_LIB(rados, rados_version, [
LIBRADOS_LDFLAGS='-lrados'
AC_SUBST(LIBRADOS_LDFLAGS)
][])
AC_CHECK_LIB(iniparser, iniparser_load, [
INIPARSER_LDFLAGS='-liniparser'
PKG_CHECK_MODULES([INIPARSER], [iniparser], [
INIPARSER_LDFLAGS="${INIPARSER_LIBS}"
AC_SUBST(INIPARSER_LDFLAGS)
], [AC_MSG_ERROR([Unable to find libiniparser])])
], [
AC_CHECK_LIB(iniparser, iniparser_load, [
INIPARSER_LDFLAGS='-liniparser'
AC_SUBST(INIPARSER_LDFLAGS)
], [AC_MSG_ERROR([Unable to find libiniparser])])
])

AC_CHECK_FUNCS([bzero gethostbyname gettimeofday inet_ntoa memset mkdir pow select socket strchr strdup strerror strrchr strstr strtol strtoul utime],[],[AC_MSG_ERROR([One of the required functions was not found])])
AC_CHECK_FUNCS([daemon getloadavg],[],[])
Expand All @@ -91,3 +100,9 @@ fi

AC_CONFIG_FILES(Makefile)
AC_OUTPUT

AC_MSG_WARN([
The Autotools build of mod_tile is deprecated and may be removed in a future
release. Please use CMake instead, e.g.:
cmake -B build -S . && cmake --build build
or one of the presets listed by: cmake --list-presets])
Loading
Loading