Skip to content

Commit f8c2a88

Browse files
authored
Merge pull request #1987 from joto/fmt-cpp20
Make it compile with C++20 and update CMake config
2 parents ea1feb2 + 5c02c62 commit f8c2a88

File tree

7 files changed

+56
-26
lines changed

7 files changed

+56
-26
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ on: [ push, pull_request ]
44

55
jobs:
66
macos:
7-
runs-on: macos-latest
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
os:
11+
- "macos-11"
12+
- "macos-12" # latest
13+
- "macos-13"
14+
runs-on: ${{ matrix.os }}
815

916
env:
1017
LUA_VERSION: 5.4
@@ -85,7 +92,6 @@ jobs:
8592
LUAJIT_OPTION: OFF
8693
POSTGRESQL_VERSION: 10
8794
POSTGIS_VERSION: 3
88-
CPP_VERSION: 17
8995
BUILD_TYPE: Debug
9096

9197
steps:
@@ -104,7 +110,6 @@ jobs:
104110
LUAJIT_OPTION: OFF
105111
POSTGRESQL_VERSION: 11
106112
POSTGIS_VERSION: 2.5
107-
CPP_VERSION: 17
108113
BUILD_TYPE: Debug
109114

110115
steps:
@@ -122,7 +127,6 @@ jobs:
122127
LUAJIT_OPTION: ON
123128
POSTGRESQL_VERSION: 12
124129
POSTGIS_VERSION: 2.5
125-
CPP_VERSION: 17
126130
BUILD_TYPE: Debug
127131

128132
steps:
@@ -141,7 +145,6 @@ jobs:
141145
LUAJIT_OPTION: ON
142146
POSTGRESQL_VERSION: 13
143147
POSTGIS_VERSION: 3
144-
CPP_VERSION: 17
145148
BUILD_TYPE: Debug
146149

147150
steps:
@@ -159,7 +162,6 @@ jobs:
159162
LUAJIT_OPTION: OFF
160163
POSTGRESQL_VERSION: 13
161164
POSTGIS_VERSION: 3
162-
CPP_VERSION: 17
163165
USE_PROJ_LIB: 6
164166
BUILD_TYPE: Debug
165167

@@ -178,7 +180,6 @@ jobs:
178180
LUAJIT_OPTION: OFF
179181
POSTGRESQL_VERSION: 13
180182
POSTGIS_VERSION: 3
181-
CPP_VERSION: 17
182183
USE_PROJ_LIB: off
183184
BUILD_TYPE: Debug
184185

@@ -197,7 +198,6 @@ jobs:
197198
LUAJIT_OPTION: OFF
198199
POSTGRESQL_VERSION: 14
199200
POSTGIS_VERSION: 3
200-
CPP_VERSION: 17
201201
USE_PROJ_LIB: 6
202202
BUILD_TYPE: Debug
203203

@@ -216,7 +216,6 @@ jobs:
216216
LUAJIT_OPTION: ON
217217
POSTGRESQL_VERSION: 13
218218
POSTGIS_VERSION: 2.5
219-
CPP_VERSION: 17
220219
BUILD_TYPE: Release
221220

222221
steps:
@@ -232,7 +231,6 @@ jobs:
232231
CXX: g++-10
233232
POSTGRESQL_VERSION: 13
234233
POSTGIS_VERSION: 2.5
235-
CPP_VERSION: 17
236234
BUILD_TYPE: Release
237235

238236
steps:
@@ -250,7 +248,6 @@ jobs:
250248
LUAJIT_OPTION: ON
251249
POSTGRESQL_VERSION: 14
252250
POSTGIS_VERSION: 3
253-
CPP_VERSION: 17
254251
BUILD_TYPE: Debug
255252

256253
steps:
@@ -268,7 +265,6 @@ jobs:
268265
LUAJIT_OPTION: OFF
269266
POSTGRESQL_VERSION: 14
270267
POSTGIS_VERSION: 3
271-
CPP_VERSION: 17
272268
USE_PROJ_LIB: 6
273269
BUILD_TYPE: Debug
274270

@@ -287,7 +283,6 @@ jobs:
287283
LUAJIT_OPTION: OFF
288284
POSTGRESQL_VERSION: 14
289285
POSTGIS_VERSION: 3
290-
CPP_VERSION: 17
291286
USE_PROJ_LIB: off
292287
BUILD_TYPE: Debug
293288

@@ -306,7 +301,6 @@ jobs:
306301
LUAJIT_OPTION: OFF
307302
POSTGRESQL_VERSION: 14
308303
POSTGIS_VERSION: 3
309-
CPP_VERSION: 17
310304
USE_PROJ_LIB: 6
311305
BUILD_TYPE: Debug
312306

@@ -326,7 +320,6 @@ jobs:
326320
LUAJIT_OPTION: ON
327321
POSTGRESQL_VERSION: 14
328322
POSTGIS_VERSION: 3
329-
CPP_VERSION: 17
330323
BUILD_TYPE: Release
331324

332325
steps:
@@ -343,14 +336,49 @@ jobs:
343336
EXTRA_FLAGS: -Wno-stringop-overread
344337
POSTGRESQL_VERSION: 14
345338
POSTGIS_VERSION: 3
346-
CPP_VERSION: 17
347339
BUILD_TYPE: Release
348340

349341
steps:
350342
- uses: actions/checkout@v3
351343
- uses: ./.github/actions/ubuntu-prerequisites
352344
- uses: ./.github/actions/build-and-test
353345

346+
ubuntu22-pg14-clang14-cpp20:
347+
runs-on: ubuntu-22.04
348+
349+
env:
350+
CC: clang-14
351+
CXX: clang++-14
352+
LUA_VERSION: 5.3
353+
LUAJIT_OPTION: OFF
354+
POSTGRESQL_VERSION: 14
355+
POSTGIS_VERSION: 3
356+
CPP_VERSION: 20
357+
BUILD_TYPE: Debug
358+
359+
steps:
360+
- uses: actions/checkout@v2
361+
- uses: ./.github/actions/ubuntu-prerequisites
362+
- uses: ./.github/actions/build-and-test
363+
364+
ubuntu22-pg14-gcc12-cpp20:
365+
runs-on: ubuntu-22.04
366+
367+
env:
368+
CC: gcc-12
369+
CXX: g++-12
370+
LUA_VERSION: 5.3
371+
LUAJIT_OPTION: OFF
372+
POSTGRESQL_VERSION: 14
373+
POSTGIS_VERSION: 3
374+
CPP_VERSION: 20
375+
BUILD_TYPE: Debug
376+
377+
steps:
378+
- uses: actions/checkout@v2
379+
- uses: ./.github/actions/ubuntu-prerequisites
380+
- uses: ./.github/actions/build-and-test
381+
354382
windows:
355383
strategy:
356384
fail-fast: false

CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cmake_minimum_required(VERSION 3.5.0)
2+
cmake_minimum_required(VERSION 3.8.0)
33

44
project(osm2pgsql VERSION 1.8.1 LANGUAGES CXX C)
55

@@ -37,12 +37,8 @@ if (NOT CMAKE_BUILD_TYPE)
3737
set(CMAKE_BUILD_TYPE RelWithDebInfo)
3838
endif()
3939

40-
if (NOT "${CMAKE_CXX_STANDARD}")
41-
set(CMAKE_CXX_STANDARD 17)
42-
endif()
43-
message(STATUS "Building in C++${CMAKE_CXX_STANDARD} mode")
40+
# We don't want to use special compiler extensions because we want portability
4441
set(CMAKE_CXX_EXTENSIONS OFF)
45-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4642

4743
if (MSVC)
4844
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DNOMINMAX)

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
add_library(osm2pgsql_lib STATIC)
33

4+
# Set the minimum required C++ version for the library and hence for all
5+
# binaries that use it.
6+
target_compile_features(osm2pgsql_lib PUBLIC cxx_std_17)
7+
48
target_sources(osm2pgsql_lib PRIVATE
59
db-copy.cpp
610
debug-output.cpp

src/format.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
#include <stdexcept>
1717

18-
template <typename S, typename... TArgs>
19-
std::runtime_error fmt_error(S const &format_str, TArgs &&...args)
18+
template <typename... TArgs>
19+
std::runtime_error fmt_error(fmt::format_string<TArgs...> format_str,
20+
TArgs &&...args)
2021
{
2122
return std::runtime_error{
2223
fmt::format(format_str, std::forward<TArgs>(args)...)};

src/middle-pgsql.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static std::string build_sql(options_t const &options, std::string const &templ)
4545
: "USING INDEX TABLESPACE " +
4646
options.tblsslim_index};
4747
return fmt::format(
48-
templ, fmt::arg("prefix", options.prefix),
48+
fmt::runtime(templ), fmt::arg("prefix", options.prefix),
4949
fmt::arg("schema", options.middle_dbschema.empty()
5050
? ""
5151
: ("\"" + options.middle_dbschema + "\".")),

src/pgsql.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class pg_conn_t
171171
* status code PGRES_COMMAND_OK or PGRES_TUPLES_OK).
172172
*/
173173
template <typename... TArgs>
174-
pg_result_t exec(char const *sql, TArgs... params) const
174+
pg_result_t exec(fmt::format_string<TArgs...> sql, TArgs... params) const
175175
{
176176
return exec(fmt::format(sql, std::forward<TArgs>(params)...));
177177
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_definitions(-DTESTDATA_DIR=\"${osm2pgsql_SOURCE_DIR}/tests/data/\")
3636
add_definitions(-DOSM2PGSQLDATA_DIR=\"${osm2pgsql_SOURCE_DIR}/\")
3737

3838
add_library(catch_main_lib STATIC catch-main.cpp)
39+
target_compile_features(catch_main_lib PUBLIC cxx_std_17)
3940

4041
set_test(test-check-input LABELS NoDB)
4142
set_test(test-db-copy-thread)

0 commit comments

Comments
 (0)