Skip to content

Commit b829935

Browse files
committed
Fixed build error with g++14.
Fixed the Jenkins setup. Removed some old Linux versions and added newer ones Handled breaking change in cnake 3.30 with 'find boost' Fixed test cases that broke after the json backend changed 'id' datatype from int to string. Added 'fetchAndIgnore()' method to read the reply from a server without using it. Various fixes. Added support for C++20 as an option to cmake Added detection of C++ standard in cmake. If no standard is set via the compile time arguments, it will default to the best one available for the compiler
1 parent 5080fa4 commit b829935

23 files changed

+487
-206
lines changed

CMakeLists.txt

+72-23
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.10)
22

3-
if (UNIX)
4-
# Ninja creates too many problems while maintaining
5-
# compatibility with old and new versions of Linux/Cmake
6-
set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
7-
endif()
3+
# if (UNIX)
4+
# # Ninja creates too many problems while maintaining
5+
# # compatibility with old and new versions of Linux/Cmake
6+
# set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
7+
# endif()
88

99
if (DEFINED ENV{RESTC_CPP_VERSION})
1010
set(RESTC_CPP_VERSION $ENV{RESTC_CPP_VERSION})
1111
endif()
1212

1313
if (NOT DEFINED RESTC_CPP_VERSION)
14-
set(RESTC_CPP_VERSION 0.99.0)
14+
set(RESTC_CPP_VERSION 0.100.0)
1515
endif()
1616

1717
if(NOT DEFINED RESTC_BOOST_VERSION)
@@ -22,6 +22,12 @@ project (restc-cpp VERSION ${RESTC_CPP_VERSION})
2222

2323
message(STATUS "Building restc-cpp version ${PROJECT_VERSION}")
2424

25+
include(CheckCXXCompilerFlag)
26+
27+
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
28+
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
29+
30+
2531
if (NOT DEFINED INSTALL_RAPIDJSON_HEADERS)
2632
option(INSTALL_RAPIDJSON_HEADERS "Install rapidjson headers when make install is executed" ON)
2733
endif()
@@ -32,6 +38,28 @@ option(RESTC_CPP_AUTORUN_UNIT_TESTS "Run Unit Tests automatically after build" O
3238

3339
option(RESTC_CPP_WITH_FUNCTIONALT_TESTS "Enable Functional Testing" ON)
3440

41+
set(GTEST_TAG "main" CACHE STRING "Gtest branch to use. Required on older Linux versions because newer gtest requure newer cmake!")
42+
set(LOGFAULT_TAG "master" CACHE STRING "Logfault branch to use. Required on older Linux versions because newer gtest requure newer cmake!")
43+
44+
find_package(RapidJSON QUIET)
45+
46+
if (NOT RapidJSON_FOUND AND INSTALL_RAPIDJSON_HEADERS)
47+
message(STATUS "Rapidjson not found. Adding it as an external project.")
48+
set(RESTC_CPP_EXTERNAL_DEPS ${RESTC_CPP_EXTERNAL_DEPS} externalRapidJson)
49+
set(restc_cpp_add_rapidjson ON)
50+
endif()
51+
52+
if (RESTC_CPP_LOG_WITH_LOGFAULT)
53+
find_path(LOGFAULT logfault/logfault.h)
54+
if (LOGFAULT)
55+
message ("Using existing logfault")
56+
else()
57+
message ("Embedding logfault header only library")
58+
set(RESTC_CPP_EXTERNAL_DEPS ${RESTC_CPP_EXTERNAL_DEPS} externalLogfault)
59+
set(restc_cpp_add_logfault ON)
60+
endif()
61+
endif()
62+
3563
include(cmake_scripts/external-projects.cmake)
3664

3765
if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
@@ -68,7 +96,26 @@ option(RESTC_CPP_LOG_JSON_SERIALIZATION "Enable trace logging for json serializa
6896

6997
option(RESTC_CPP_WITH_ZLIB "Use zlib" ON)
7098

71-
option(RESTC_CPP_USE_CPP17 "Use the C++17 standard" ON)
99+
option(RESTC_CPP_USE_CPP14 "Use the C++14 standard" OFF)
100+
101+
option(RESTC_CPP_USE_CPP17 "Use the C++17 standard" OFF)
102+
103+
option(RESTC_CPP_USE_CPP20 "Use the C++20 standard" OFF)
104+
105+
if (NOT RESTC_CPP_USE_CPP14 AND NOT RESTC_CPP_USE_CPP17 AND NOT RESTC_CPP_USE_CPP20)
106+
# Check if GCC 12 is being used and default it to C++17
107+
# https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1887728.html
108+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
109+
message(STATUS "GCC 12 detected, defaulting to C++17")
110+
set(RESTC_CPP_USE_CPP17 ON)
111+
elseif (COMPILER_SUPPORTS_CXX20)
112+
set(RESTC_CPP_USE_CPP20 ON)
113+
elseif (COMPILER_SUPPORTS_CXX17)
114+
set(RESTC_CPP_USE_CPP17 ON)
115+
else ()
116+
set(RESTC_CPP_USE_CPP14 ON)
117+
endif()
118+
endif()
72119

73120
option(RESTC_CPP_THREADED_CTX "Allow asio contextx with multiple therads. Enables thread-safe internal access." OFF)
74121

@@ -139,7 +186,10 @@ endif()
139186
message(STATUS "Using ${CMAKE_CXX_COMPILER}")
140187

141188
macro(SET_CPP_STANDARD target)
142-
if (RESTC_CPP_USE_CPP17)
189+
if (RESTC_CPP_USE_CPP20)
190+
message(STATUS "Using C++ 20 for ${target}")
191+
set_property(TARGET ${target} PROPERTY CXX_STANDARD 20)
192+
elseif (RESTC_CPP_USE_CPP17)
143193
message(STATUS "Using C++ 17 for ${target}")
144194
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17)
145195
else()
@@ -182,7 +232,6 @@ endif()
182232
if (WIN32)
183233
include(cmake_scripts/pch.cmake)
184234
ADD_MSVC_PRECOMPILED_HEADER(restc-cpp/restc-cpp.h src/pch.cpp ACTUAL_SOURCES)
185-
add_definitions(-DWAR_PCH)
186235
set(SOURCES ${ACTUAL_SOURCES} src/pch.cpp ${HEADERS} ${RESFILES})
187236
else()
188237
set(SOURCES ${ACTUAL_SOURCES})
@@ -199,21 +248,18 @@ target_include_directories(${PROJECT_NAME}
199248

200249
SET_CPP_STANDARD(${PROJECT_NAME})
201250

202-
if (RESTC_CPP_LOG_WITH_LOGFAULT)
203-
find_path(LOGFAULT logfault/logfault.h)
204-
if (LOGFAULT)
205-
message ("Using existing logfault")
206-
else()
207-
message ("Embedding logfault header only library")
208-
set(RESTC_CPP_EXTERNAL_DEPS ${RESTC_CPP_EXTERNAL_DEPS} externalLogfault)
209-
endif()
251+
if(NOT "${RESTC_CPP_EXTERNAL_DEPS}" STREQUAL "")
252+
add_dependencies(${PROJECT_NAME} ${RESTC_CPP_EXTERNAL_DEPS})
210253
endif()
211254

212-
add_dependencies(${PROJECT_NAME} externalRapidJson ${RESTC_CPP_EXTERNAL_DEPS})
213-
214255
if (NOT EMBEDDED_RESTC_CPP)
215-
#set(Boost_USE_MULTITHREADED ON)
216-
find_package(Boost ${RESTC_BOOST_VERSION} REQUIRED COMPONENTS
256+
257+
if(CMAKE_VERSION VERSION_GREATER "3.28")
258+
set(restc_cpp_boost_find_config CONFIG)
259+
message("Using new Boost find config")
260+
endif()
261+
262+
find_package(Boost ${RESTC_BOOST_VERSION} REQUIRED ${restc_cpp_boost_find_config} COMPONENTS
217263
system
218264
program_options
219265
filesystem
@@ -223,6 +269,9 @@ if (NOT EMBEDDED_RESTC_CPP)
223269
chrono
224270
${BOOST_LOG_DEP}
225271
)
272+
273+
message(STATUS "Boost version found: ${Boost_VERSION}")
274+
226275
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
227276
target_link_libraries(${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES})
228277
target_compile_definitions(${PROJECT_NAME} PUBLIC -DBOOST_COROUTINE_NO_DEPRECATION_WARNING=1)
@@ -264,7 +313,7 @@ if (NOT EMBEDDED_RESTC_CPP)
264313
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
265314
endif()
266315

267-
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib CACHE PATH "Destination location")
316+
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE PATH "Destination location")
268317
link_directories(${LIBRARY_OUTPUT_PATH})
269318

270319
include(cmake_scripts/doxygen.cmake)

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@ These are the operating systems where my Continues Integration (Jenkins) servers
259259
- Debian Bullseye
260260
- Debian Buster
261261
- Windows 10 / Microsoft Visual Studio 2019, Community version using vcpkg for dependencies
262-
- Ubuntu Xenial (LTS)
262+
- Ubunti Noble
263263
- Ubuntu Jammy (LTS)
264+
- Ubuntu Bionic (LTS)
265+
- Fedora (latest)
264266

265267
Support for MacOS has been removed after Apples announcement that their love for privacy was just
266268
a marketing gimmick.

ci/jenkins/Dockefile.debian-buster

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN DEBIAN_FRONTEND="noninteractive" apt-get -q update &&\
88
DEBIAN_FRONTEND="noninteractive" apt-get install -y -q \
99
openssh-server g++ git \
1010
build-essential \
11-
zlib1g-dev g++ cmake make libboost-all-dev libssl-dev \
11+
zlib1g-dev g++ cmake make libboost-all-dev libssl-dev libgtest-dev \
1212
default-jdk &&\
1313
apt-get -y -q autoremove &&\
1414
apt-get -y -q clean

ci/jenkins/Dockefile.ubuntu-xenial

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apt-get -q update &&\
99
apt-get -y -q --no-install-recommends upgrade &&\
1010
apt-get -y -q install openssh-server g++ git \
1111
automake autoconf build-essential \
12-
zlib1g-dev g++ cmake make libboost-all-dev libssl-dev \
12+
zlib1g-dev g++ cmake make libboost-all-dev libssl-dev libgtest-dev \
1313
openjdk-8-jdk &&\
1414
apt-get -y -q autoremove &&\
1515
apt-get -y -q clean

ci/jenkins/Dockerfile.fedora

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
FROM fedora:33
1+
FROM fedora:latest
22

33
MAINTAINER Jarle Aase <jgaa@jgaa.com>
44

5-
RUN echo "root:password" | chpasswd
6-
RUN useradd jenkins
7-
RUN echo "jenkins:jenkins" | chpasswd
5+
RUN dnf -q update -y &&\
6+
dnf -q upgrade -y &&\
7+
dnf -q install -y openssh-server gcc-c++ git gnupg2 \
8+
automake autoconf make \
9+
zlib-devel gcc-c++ cmake boost-devel openssl-devel \
10+
java-11-openjdk-devel &&\
11+
dnf -q autoremove -y &&\
12+
dnf clean all &&\
13+
ssh-keygen -A
814

9-
RUN dnf -y update &&\
10-
dnf -y install @development-tools git jre-openjdk zlib-devel openssl-devel boost-devel cmake gcc-c++ openssh-server
15+
# Set user jenkins to the image
16+
RUN useradd -m -d /home/jenkins -s /bin/bash jenkins &&\
17+
chmod 0777 /home/jenkins &&\
18+
echo "jenkins:jenkins" | chpasswd &&\
19+
mkdir -p /run/sshd
1120

12-
# expose the ssh port
21+
# Standard SSH port
1322
EXPOSE 22
1423

15-
# entrypoint by starting sshd
24+
# Default command
1625
CMD ["/usr/sbin/sshd", "-D"]
17-

ci/jenkins/Dockerfile.ubuntu-bionic

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ubuntu:18.04
2+
3+
MAINTAINER Jarle Aase <jgaa@jgaa.com>
4+
5+
RUN DEBIAN_FRONTEND="noninteractive" apt-get -q update &&\
6+
DEBIAN_FRONTEND="noninteractive" apt-get -y -q --no-install-recommends upgrade &&\
7+
DEBIAN_FRONTEND="noninteractive" apt-get install -y -q openssh-server g++ git gpgv \
8+
automake autoconf build-essential \
9+
zlib1g-dev g++ cmake make libboost-all-dev libssl-dev \
10+
default-jdk &&\
11+
apt-get -y -q autoremove &&\
12+
apt-get -y -q clean
13+
14+
# Set user jenkins to the image
15+
RUN useradd -m -d /home/jenkins -s /bin/sh jenkins &&\
16+
echo "jenkins:jenkins" | chpasswd &&\
17+
mkdir -p /home/jenkins/build/workspace/restc-staging &&\
18+
mkdir -p /run/sshd
19+
20+
# Standard SSH port
21+
EXPOSE 22
22+
23+
# Default command
24+
CMD ["/usr/sbin/sshd", "-D"]

ci/jenkins/Dockerfile.ubuntu-noble

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM ubuntu:24.04
2+
3+
MAINTAINER Jarle Aase <jgaa@jgaa.com>
4+
5+
RUN DEBIAN_FRONTEND="noninteractive" apt-get -q update &&\
6+
DEBIAN_FRONTEND="noninteractive" apt-get -y -q --no-install-recommends upgrade &&\
7+
DEBIAN_FRONTEND="noninteractive" apt-get install -y -q openssh-server g++ git gpgv \
8+
automake autoconf build-essential rapidjson-dev \
9+
zlib1g-dev g++ cmake make libboost-all-dev libssl-dev \
10+
default-jdk &&\
11+
apt-get -y -q autoremove &&\
12+
apt-get -y -q clean
13+
14+
# Set user jenkins to the image
15+
RUN useradd -m -d /home/jenkins -s /bin/sh jenkins &&\
16+
echo "jenkins:jenkins" | chpasswd &&\
17+
mkdir -p /run/sshd
18+
19+
# Standard SSH port
20+
EXPOSE 22
21+
22+
# Default command
23+
CMD ["/usr/sbin/sshd", "-D"]

0 commit comments

Comments
 (0)