From 0dc0c87cc991e6bacfd75612cb14a328bdc26748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislav=20Angelovi=C4=8D?= Date: Tue, 20 Feb 2024 16:27:42 +0100 Subject: [PATCH] chore: use C++20 standard (#410) As of now sdbus-c++ supports C++20 but does not require it, and the used C++20 features are conditionally compiled depending on whether they are available or not. --- .github/workflows/ci.yml | 37 ++++++++++++++++++++----------------- CMakeLists.txt | 2 +- ChangeLog | 1 + src/Message.cpp | 6 +++++- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fb3a1c..f79e3df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,38 +44,41 @@ jobs: sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 10 sudo update-alternatives --remove-all c++ sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 10 - - name: install-googletest - if: matrix.os == 'ubuntu-22.04' - run: | - sudo apt-get install -y libgmock-dev - - name: install-googletest - if: matrix.os == 'ubuntu-20.04' # On older ubuntus the libgmock-dev package is either unavailable or has faulty pkg-config file, so we build & install manually - run: | - git clone https://github.com/google/googletest.git - cd googletest - mkdir build - cd build - cmake .. - cmake --build . -j4 - sudo cmake --build . --target install + # We need to use libc++ with Clang because there is a bug in libstdc++ chrono headers that Clang has issues with + echo "SDBUSCPP_EXTRA_CXX_FLAGS=-stdlib=libc++" >> $GITHUB_ENV +# We don't install googletest but we let it be built within sdbus-c++ builds below, since it needs to be built against libc++ for Clang jobs to pass +# - name: install-googletest +# if: matrix.os == 'ubuntu-22.04' +# run: | +# sudo apt-get install -y libgmock-dev +# - name: install-googletest +# if: matrix.os == 'ubuntu-20.04' # On older ubuntus the libgmock-dev package is either unavailable or has faulty pkg-config file, so we build & install manually +# run: | +# git clone https://github.com/google/googletest.git +# cd googletest +# mkdir build +# cd build +# cmake .. -DCMAKE_CXX_FLAGS="$SDBUSCPP_EXTRA_CXX_FLAGS" +# cmake --build . -j4 +# sudo cmake --build . --target install - name: configure-debug if: matrix.build == 'shared-libsystemd' && matrix.os == 'ubuntu-20.04' run: | mkdir build cd build - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O0 -g -W -Wextra -Wall -Wnon-virtual-dtor -Werror" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON .. + cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O0 -g -W -Wextra -Wall -Wnon-virtual-dtor -Werror $SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON .. - name: configure-release if: matrix.build == 'shared-libsystemd' && matrix.os == 'ubuntu-22.04' run: | mkdir build cd build - cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O3 -DNDEBUG -W -Wextra -Wall -Wnon-virtual-dtor -Werror" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON .. + cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O3 -DNDEBUG -W -Wextra -Wall -Wnon-virtual-dtor -Werror $SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0 .. - name: configure-with-embedded-libsystemd if: matrix.build == 'embedded-static-libsystemd' run: | mkdir build cd build - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_BUILD_LIBSYSTEMD=ON -DSDBUSCPP_LIBSYSTEMD_VERSION=252 .. + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="$SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_BUILD_LIBSYSTEMD=ON -DSDBUSCPP_LIBSYSTEMD_VERSION=252 -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0 .. - name: make run: | cd build diff --git a/CMakeLists.txt b/CMakeLists.txt index d9597df..7bbd891 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,7 +184,7 @@ set(SDBUSCPP_SRCS ${SDBUSCPP_CPP_SRCS} ${SDBUSCPP_HDR_SRCS} ${SDBUSCPP_PUBLIC_HD # GENERAL COMPILER CONFIGURATION #------------------------------- -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) #---------------------------------- # LIBRARY BUILD INFORMATION diff --git a/ChangeLog b/ChangeLog index e79b6cf..fbc8b7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -264,4 +264,5 @@ v2.0.0 - Add method to get currently processed message also to `IConnection` - `[[nodiscard]]` attribute has been added to relevant API methods. - Add new `SDBUSCPP_SDBUS_LIB` CMake configuration variable determining which sd-bus library shall be picked +- Switch to C++20 standard (but C++20 is not required, and the used C++20 features are conditionally compiled) - Other simplifications, improvements and fixes springing out from the above refactoring diff --git a/src/Message.cpp b/src/Message.cpp index 3ac89ae..2222726 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -884,7 +884,11 @@ namespace { // Please note that the solution is NOT thread-safe. // Another common solution is global sdbus-c++ startup/shutdown functions, but that would be an intrusive change. -/*constinit (C++20 keyword) */ static bool pseudoConnectionDestroyed{}; +#ifdef __cpp_constinit +constinit static bool pseudoConnectionDestroyed{}; +#else +static bool pseudoConnectionDestroyed{}; +#endif std::unique_ptr createPseudoConnection() {