Skip to content

Commit 3e27257

Browse files
authored
Merge branch 'master' into patch/basicauth_removal
2 parents 439e845 + 649370d commit 3e27257

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1087
-359
lines changed

.clang-tidy

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
Checks: '-*,cppcoreguidelines-*,bugprone-*,performance*,modernize-*,-modernize-use-trailing-return-type'
3+
...

.iwyu_mappings.imp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{ include: ["@<libmemcached-.*/.*>", "public", "<libmemcached/memcached.h>", "public"] },
3+
{ include: ["@<boost/algorithm/string/.*>", "public", "<boost/algorithm/string.hpp>", "public"] },
4+
{ include: ["@<boost/program_options/.*>", "public", "<boost/program_options.hpp>", "public"] },
5+
{ include: ["@<boost/lexical_cast/.*>", "public", "<boost/lexical_cast.hpp>", "public"] },
6+
{ include: ["@<pqxx/.*\\.h.*>", "private", "<pqxx/pqxx>", "public"] },
7+
{ include: ["<cryptopp/config_int.h>", "private", "<cryptopp/config.h>", "public"] },
8+
{ include: ["<bits/chrono.h>", "private", "<chrono>", "public"] },
9+
{ include: ["<bits/local_lim.h>", "private", "<limits.h>", "public"] },
10+
]

CMakeLists.txt

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
1212
string(TIMESTAMP CURRENT_TIMESTAMP %y%m%d%H%M UTC)
1313

1414
project(CGImap LANGUAGES CXX
15-
VERSION "0.9.0"
15+
VERSION "0.10.0.${CURRENT_TIMESTAMP}"
1616
DESCRIPTION "CGImap is a C++ implementation of some parts of the OpenStreetMap API as a FastCGI process."
1717
HOMEPAGE_URL "https://github.com/zerebubuth/openstreetmap-cgimap")
1818
set(CMAKE_PROJECT_BUGREPORT_URL "https://github.com/zerebubuth/openstreetmap-cgimap/issues")
@@ -37,6 +37,7 @@ endif()
3737
###############
3838
option(ENABLE_APIDB "Enable APIDB backend, as used by the OSM servers" ON)
3939
option(ENABLE_YAJL "Enable JSON output with the YAJL library" ON)
40+
option(ENABLE_BROTLI "Enable Brotli library" ON)
4041
option(ENABLE_FMT_HEADER "Enable FMT header only mode" ON)
4142
option(ENABLE_COVERAGE "Compile with coverage info collection" OFF)
4243
option(ENABLE_PROFILING "Compile with profiling" OFF)
@@ -52,6 +53,7 @@ endif()
5253

5354
include(CTest)
5455
include(AutotoolsCompatibilityDefinitions)
56+
include(BuildLint)
5557

5658
#########################
5759
# common compiler options
@@ -101,6 +103,12 @@ endif()
101103
target_compile_definitions(cgimap_common_compiler_options INTERFACE
102104
HAVE_YAJL=$<BOOL:${YAJL_FOUND}>)
103105

106+
if(ENABLE_BROTLI)
107+
find_package(Brotli COMPONENTS encoder decoder common REQUIRED)
108+
endif()
109+
target_compile_definitions(cgimap_common_compiler_options INTERFACE
110+
HAVE_BROTLI=$<BOOL:${Brotli_FOUND}>)
111+
104112
find_package(Fcgi REQUIRED)
105113
target_compile_definitions(cgimap_common_compiler_options INTERFACE
106114
HAVE_FCGI=$<BOOL:${Fcgi_FOUND}>)
@@ -137,17 +145,12 @@ target_link_libraries(openstreetmap_cgimap
137145
PQXX::PQXX)
138146

139147

140-
141148
#############################################################
142149
# Optional "clang-tidy" target
143150
#############################################################
144151

145-
find_program(CLANG_TIDY
146-
NAMES clang-tidy clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11)
147-
148-
if (CLANG_TIDY)
149-
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
150-
152+
# BuildLint module already checks for clang-tidy
153+
if(CLANG_TIDY)
151154
file(GLOB CT_CHECK_FILES src/*.cpp src/api06/*.cpp src/api06/changeset_upload/*.cpp src/api07/*.cpp
152155
src/backend/apidb/*.cpp src/backend/apidb/changeset_upload/*.cpp
153156
test/*.cpp test/*.hpp)
@@ -158,8 +161,6 @@ if (CLANG_TIDY)
158161
-p ${CMAKE_BINARY_DIR}
159162
${CT_CHECK_FILES}
160163
)
161-
else()
162-
message(STATUS "Looking for clang-tidy - not found")
163164
endif()
164165

165166

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CGImap uses a PostgreSQL server for the APIDB backend.
3333
If you're running a Debian or Ubuntu system these can be installed
3434
using the following command:
3535

36-
sudo apt-get install libxml2-dev libpqxx-dev libfcgi-dev zlib1g-dev \
36+
sudo apt-get install libxml2-dev libpqxx-dev libfcgi-dev zlib1g-dev libbrotli-dev \
3737
libboost-program-options-dev libfmt-dev libmemcached-dev libcrypto++-dev \
3838
libargon2-dev libyajl-dev
3939

cmake/BuildLint.cmake

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# CMAKE_CXX_<LINTER> variables need to be set before targets are created
2+
3+
############
4+
# clang-tidy
5+
############
6+
option(ENABLE_BUILD_LINT_CLANG_TIDY "Automatically check code with clang-tidy during compilation" OFF)
7+
8+
find_program(CLANG_TIDY
9+
NAMES clang-tidy clang-tidy-16 clang-tidy-15 clang-tidy-14 clang-tidy-13 clang-tidy-12 clang-tidy-11)
10+
11+
if(CLANG_TIDY)
12+
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
13+
14+
if(ENABLE_BUILD_LINT_CLANG_TIDY)
15+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}" -extra-arg=-std=c++17)
16+
endif()
17+
else()
18+
message(STATUS "Looking for clang-tidy - not found")
19+
endif()
20+
21+
##########
22+
# cppcheck
23+
##########
24+
option(ENABLE_BUILD_LINT_CPPCHECK "Automatically check code with cppcheck during compilation" OFF)
25+
26+
if(ENABLE_BUILD_LINT_CPPCHECK)
27+
find_program(CPPCHECK NAMES cppcheck)
28+
29+
if(CPPCHECK)
30+
message(STATUS "Looking for cppcheck - found ${CPPCHECK}")
31+
32+
set(CMAKE_CXX_CPPCHECK "${CPPCHECK}")
33+
else()
34+
message(STATUS "Looking for cppcheck - not found")
35+
endif()
36+
endif()
37+
38+
#########
39+
# cpplint
40+
#########
41+
option(ENABLE_BUILD_LINT_CPPLINT "Automatically check code with cpplint during compilation" OFF)
42+
43+
if(ENABLE_BUILD_LINT_CPPLINT)
44+
find_program(CPPLINT NAMES cpplint)
45+
46+
if(CPPLINT)
47+
message(STATUS "Looking for cpplint - found ${CPPLINT}")
48+
49+
set(CMAKE_CXX_CPPLINT "${CPPLINT}" --filter=-whitespace,-whitespace/braces,-whitespace/indent,-whitespace/line_length,-whitespace/comments,-readability/todo,-runtime/references,-build/c++11,-build/include_order)
50+
else()
51+
message(STATUS "Looking for cpplint - not found")
52+
endif()
53+
endif()
54+
55+
######################
56+
# include-what-you-use
57+
######################
58+
option(ENABLE_BUILD_LINT_IWYU "Automatically check code with include-what-you-use during compilation" OFF)
59+
60+
if(ENABLE_BUILD_LINT_IWYU)
61+
find_program(IWYU NAMES iwyu)
62+
63+
if(IWYU)
64+
message(STATUS "Looking for include-what-you-use - found ${IWYU}")
65+
66+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU}" -std=c++17 -Xiwyu --cxx17ns -Xiwyu --no_fwd_decls -Xiwyu "--mapping_file=${CMAKE_SOURCE_DIR}/.iwyu_mappings.imp")
67+
else()
68+
message(STATUS "Looking for include-what-you-use - not found")
69+
endif()
70+
endif()
71+
72+
73+
########################################################
74+
# Disable / save / restore lint config utility functions
75+
########################################################
76+
77+
set(BUILD_LINT_CONFIGS CMAKE_CXX_CLANG_TIDY CMAKE_CXX_CPPCHECK CMAKE_CXX_CPPLINT CMAKE_CXX_INCLUDE_WHAT_YOU_USE)
78+
79+
function(save_build_lint_config LINT_CONFIG_VAR)
80+
foreach(LINT_CONFIG IN LISTS BUILD_LINT_CONFIGS)
81+
string(REPLACE ";" "@SEMICOLON@" ${LINT_CONFIG} "${${LINT_CONFIG}}")
82+
list(APPEND LINT_CONFIGS_LIST "${${LINT_CONFIG}}")
83+
endforeach()
84+
85+
set(${LINT_CONFIG_VAR} ${LINT_CONFIGS_LIST} PARENT_SCOPE)
86+
endfunction()
87+
88+
89+
function(restore_build_lint_config LINT_CONFIG_VAR)
90+
foreach(LINT_CONFIG IN LISTS BUILD_LINT_CONFIGS)
91+
list(POP_FRONT ${LINT_CONFIG_VAR} ${LINT_CONFIG})
92+
string(REPLACE "@SEMICOLON@" ";" ${LINT_CONFIG} "${${LINT_CONFIG}}")
93+
set(${LINT_CONFIG} ${${LINT_CONFIG}} PARENT_SCOPE)
94+
endforeach()
95+
endfunction()
96+
97+
98+
macro(disable_build_lint)
99+
foreach(LINT_CONFIG IN LISTS BUILD_LINT_CONFIGS)
100+
unset(${LINT_CONFIG})
101+
endforeach()
102+
endmacro()
103+
104+
105+
function(print_build_lint_config)
106+
foreach(LINT_CONFIG IN LISTS BUILD_LINT_CONFIGS)
107+
message("lint config ${LINT_CONFIG}: ${${LINT_CONFIG}}")
108+
endforeach()
109+
endfunction()

cmake/FindBrotli.cmake

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# A simple FindBrotli package for Cmake's find_package function.
2+
# Note: This find package doesn't have version support, as the version file doesn't seem to be installed on most systems.
3+
#
4+
# If you want to find the static packages instead of shared (the default), define BROTLI_USE_STATIC_LIBS as TRUE.
5+
# The targets will have the same names, but it will use the static libs.
6+
#
7+
# Valid find_package COMPONENTS names: "decoder", "encoder", and "common"
8+
# Note that if you're requiring "decoder" or "encoder", then "common" will be automatically added as required.
9+
#
10+
# Defines the libraries (if found): Brotli::decoder, Brotli::encoder, Brotli::common
11+
# and the includes path variable: Brotli_INCLUDE_DIR
12+
#
13+
# If it's failing to find the libraries, try setting BROTLI_ROOT_DIR to the folder containing your library & include dir.
14+
15+
# If they asked for a specific version, warn/fail since we don't support it.
16+
# TODO: if they start distributing the version somewhere, implement finding it.
17+
# See https://github.com/google/brotli/issues/773#issuecomment-579133187
18+
if(Brotli_FIND_VERSION)
19+
set(_brotli_version_error_msg "FindBrotli.cmake doesn't have version support!")
20+
# If the package is required, throw a fatal error
21+
# Otherwise, if not running quietly, we throw a warning
22+
if(Brotli_FIND_REQUIRED)
23+
message(FATAL_ERROR "${_brotli_version_error_msg}")
24+
elseif(NOT Brotli_FIND_QUIETLY)
25+
message(WARNING "${_brotli_version_error_msg}")
26+
endif()
27+
endif()
28+
29+
# Since both decoder & encoder require the common lib, force its requirement..
30+
# if the user is requiring either of those other libs.
31+
if(Brotli_FIND_REQUIRED_decoder OR Brotli_FIND_REQUIRED_encoder)
32+
set(Brotli_FIND_REQUIRED_common TRUE)
33+
endif()
34+
35+
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
36+
# Credit to FindOpenSSL.cmake for this
37+
if(BROTLI_USE_STATIC_LIBS)
38+
set(_brotli_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
39+
if(WIN32)
40+
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
41+
else()
42+
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
43+
endif()
44+
endif()
45+
46+
# Make PkgConfig optional, since some users (mainly Windows) don't have it.
47+
# But it's a lot more clean than manually using find_library.
48+
find_package(PkgConfig QUIET)
49+
50+
# Only used if the PkgConfig libraries aren't used.
51+
find_path(Brotli_INCLUDE_DIR
52+
NAMES
53+
"brotli/decode.h"
54+
"brotli/encode.h"
55+
HINTS
56+
${BROTLI_ROOT_DIR}
57+
PATH_SUFFIXES
58+
"include"
59+
"includes"
60+
DOC "The path to Brotli's include directory."
61+
)
62+
# Hides this var from the GUI
63+
mark_as_advanced(Brotli_INCLUDE_DIR)
64+
65+
# Just used for PkgConfig stuff in the loop below
66+
set(_brotli_stat_str "")
67+
if(BROTLI_USE_STATIC_LIBS)
68+
set(_brotli_stat_str "_STATIC")
69+
endif()
70+
71+
# Each string here is "ComponentName;LiteralName" (the semi-colon is a delimiter)
72+
foreach(_listvar "common;common" "decoder;dec" "encoder;enc")
73+
# Split the component name and literal library name from the listvar
74+
list(GET _listvar 0 _component_name)
75+
list(GET _listvar 1 _libname)
76+
77+
# NOTE: We can't rely on PkgConf for static libs since the upstream static lib support is broken
78+
# See https://github.com/google/brotli/issues/795
79+
# TODO: whenever their issue is fixed upstream, remove this "AND NOT BROTLI_USE_STATIC_LIBS" check
80+
if(PKG_CONFIG_FOUND AND NOT BROTLI_USE_STATIC_LIBS)
81+
# These need to be GLOBAL for MinGW when making ALIAS libraries against them.
82+
# Have to postfix _STATIC on the name to tell PkgConfig to find the static libs.
83+
pkg_check_modules(Brotli_${_component_name}${_brotli_stat_str} QUIET GLOBAL IMPORTED_TARGET libbrotli${_libname})
84+
endif()
85+
86+
# Check if the target was already found by Pkgconf
87+
if(TARGET PkgConfig::Brotli_${_component_name}${_brotli_stat_str})
88+
# ALIAS since we don't want the PkgConfig namespace on the Cmake library (for end-users)
89+
add_library(Brotli::${_component_name} ALIAS PkgConfig::Brotli_${_component_name}${_brotli_stat_str})
90+
91+
# Tells HANDLE_COMPONENTS we found the component
92+
set(Brotli_${_component_name}_FOUND TRUE)
93+
if(Brotli_FIND_REQUIRED_${_component_name})
94+
# If the lib is required, we can add its literal path as a required var for FindPackageHandleStandardArgs
95+
# Since it won't accept the PkgConfig targets
96+
if(BROTLI_USE_STATIC_LIBS)
97+
list(APPEND _brotli_req_vars "Brotli_${_component_name}_STATIC_LIBRARIES")
98+
else()
99+
list(APPEND _brotli_req_vars "Brotli_${_component_name}_LINK_LIBRARIES")
100+
endif()
101+
endif()
102+
103+
# Skip searching for the libs with find_library since it was already found by Pkgconf
104+
continue()
105+
endif()
106+
107+
if(Brotli_FIND_REQUIRED_${_component_name})
108+
# If it's required, we can set the name used in find_library as a required var for FindPackageHandleStandardArgs
109+
list(APPEND _brotli_req_vars "Brotli_${_component_name}")
110+
endif()
111+
112+
list(APPEND _brotli_lib_names
113+
"brotli${_libname}"
114+
"libbrotli${_libname}"
115+
)
116+
if(BROTLI_USE_STATIC_LIBS)
117+
# Postfix "-static" to the libnames since we're looking for static libs
118+
list(TRANSFORM _brotli_lib_names APPEND "-static")
119+
endif()
120+
121+
find_library(Brotli_${_component_name}
122+
NAMES ${_brotli_lib_names}
123+
HINTS ${BROTLI_ROOT_DIR}
124+
PATH_SUFFIXES
125+
"lib"
126+
"lib64"
127+
"libs"
128+
"libs64"
129+
"lib/x86_64-linux-gnu"
130+
)
131+
# Hide the library variable from the Cmake GUI
132+
mark_as_advanced(Brotli_${_component_name})
133+
134+
# Unset since otherwise it'll stick around for the next loop and break things
135+
unset(_brotli_lib_names)
136+
137+
# Check if find_library found the library
138+
if(Brotli_${_component_name})
139+
# Tells HANDLE_COMPONENTS we found the component
140+
set(Brotli_${_component_name}_FOUND TRUE)
141+
142+
add_library("Brotli::${_component_name}" UNKNOWN IMPORTED)
143+
# Attach the literal library and include dir to the IMPORTED target for the end-user
144+
set_target_properties("Brotli::${_component_name}" PROPERTIES
145+
INTERFACE_INCLUDE_DIRECTORIES "${Brotli_INCLUDE_DIR}"
146+
IMPORTED_LOCATION "${Brotli_${_component_name}}"
147+
)
148+
else()
149+
# Tells HANDLE_COMPONENTS we found the component
150+
set(Brotli_${_component_name}_FOUND FALSE)
151+
endif()
152+
endforeach()
153+
154+
include(FindPackageHandleStandardArgs)
155+
# Sets Brotli_FOUND, and fails the find_package(Brotli) call if it was REQUIRED but missing libs.
156+
find_package_handle_standard_args(Brotli
157+
FOUND_VAR
158+
Brotli_FOUND
159+
REQUIRED_VARS
160+
Brotli_INCLUDE_DIR
161+
${_brotli_req_vars}
162+
HANDLE_COMPONENTS
163+
)
164+
165+
# Restore the original find library ordering
166+
if(BROTLI_USE_STATIC_LIBS)
167+
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_brotli_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
168+
endif()

contrib/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Disable linters during build of contrib libraries
2+
disable_build_lint()
3+
14
add_subdirectory(catch2)
25
add_subdirectory(libxml++)
36

docker/debian/Dockerfile_bookworm

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND=noninteractive
55

66
RUN apt-get update -qq && \
77
apt-get install -y gcc g++ make cmake \
8-
libfcgi-dev libxml2-dev libmemcached-dev \
8+
libfcgi-dev libxml2-dev libmemcached-dev libbrotli-dev \
99
libboost-program-options-dev libcrypto++-dev libyajl-dev \
1010
libpqxx-dev zlib1g-dev libfmt-dev \
1111
postgresql-15 postgresql-server-dev-all \

docker/debian/Dockerfile_trixie

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND=noninteractive
55

66
RUN apt-get update -qq && \
77
apt-get install -y gcc g++ make cmake \
8-
libfcgi-dev libxml2-dev libmemcached-dev \
8+
libfcgi-dev libxml2-dev libmemcached-dev libbrotli-dev \
99
libboost-program-options-dev libcrypto++-dev libyajl-dev \
1010
libpqxx-dev zlib1g-dev libfmt-dev \
1111
postgresql-16 postgresql-server-dev-all \

0 commit comments

Comments
 (0)