From bd8ca5891ae7c3dec33e4e91811d98e3809506c9 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Sun, 25 Sep 2022 17:52:40 +0200 Subject: [PATCH] enh(cmake): A work to accept C++17 compilation --- CMakeLists.txt | 8 ++++- .../inc/com/centreon/broker/config/parser.hh | 2 +- broker/core/src/config/parser.cc | 2 +- cmake.sh | 30 +++++++++++++++---- .../com/centreon/engine/retention/parser.hh | 8 ++--- .../com/centreon/engine/retention/state.hh | 4 ++- engine/src/retention/parser.cc | 8 ++--- engine/src/retention/state.cc | 2 +- 8 files changed, 45 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bafb603b58f..d9b7d3973bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,13 @@ endif() # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++") # set(CMAKE_CXX_COMPILER "clang++") add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1") -set(CMAKE_CXX_STANDARD 14) +option(NG "C++17 build." OFF) +if (NG) + set(CMAKE_CXX_STANDARD 17) +else () + set(CMAKE_CXX_STANDARD 14) +endif () + set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/broker/core/inc/com/centreon/broker/config/parser.hh b/broker/core/inc/com/centreon/broker/config/parser.hh index aafc0b01efc..0981acdcc3d 100644 --- a/broker/core/inc/com/centreon/broker/config/parser.hh +++ b/broker/core/inc/com/centreon/broker/config/parser.hh @@ -65,7 +65,7 @@ class parser { return {ret}; else if (ret.is_string()) { T tmp; - if (!absl::SimpleAtoi(ret, &tmp)) + if (!absl::SimpleAtoi(ret.get(), &tmp)) throw exceptions::msg_fmt( "config parser: cannot parse key '{}': " "the string value must contain an integer", diff --git a/broker/core/src/config/parser.cc b/broker/core/src/config/parser.cc index cdf2a6bb01e..7e82a06c581 100644 --- a/broker/core/src/config/parser.cc +++ b/broker/core/src/config/parser.cc @@ -100,7 +100,7 @@ absl::optional parser::check_and_read(const nlohmann::json& elem, return {ret}; else if (ret.is_string()) { bool tmp; - if (!absl::SimpleAtob(ret, &tmp)) + if (!absl::SimpleAtob(ret.get(), &tmp)) throw msg_fmt( "config parser: cannot parse key '{}': the string value must " "contain a boolean (1/0, yes/no, true/false)", diff --git a/cmake.sh b/cmake.sh index 10f8d9d696c..4f16c740f7e 100755 --- a/cmake.sh +++ b/cmake.sh @@ -9,6 +9,7 @@ This program build Centreon-broker -f|--force : force rebuild -r|--release : Build on release mode -fcr|--force-conan-rebuild : rebuild conan data + -ng : C++17 standard -h|--help : help EOF } @@ -24,19 +25,30 @@ for i in $(cat conanfile.txt) ; do fi done +STD=14 + for i in "$@" do case "$i" in -f|--force) + echo "Forced rebuild" force=1 shift ;; + -ng) + echo "C++17 applied on this compilation" + STD="17" + shift + ;; -r|--release) + echo "Release build" BUILD_TYPE="Release" shift ;; -fcr|--force-conan-rebuild) + echo "Forced conan rebuild" CONAN_REBUILD="1" + shift ;; -h|--help) show_help @@ -247,18 +259,24 @@ cd build if [[ "$maj" == "centos7" ]] ; then rm -rf ~/.conan/profiles/default if [[ "$CONAN_REBUILD" == "1" ]] ; then - $conan install .. -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build="*" + $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build="*" else - $conan install .. -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build=missing + $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build=missing fi else - $conan install .. -s compiler.cppstd=14 -s compiler.libcxx=libstdc++11 --build=missing + $conan install .. -s compiler.cppstd=$STD -s compiler.libcxx=libstdc++11 --build=missing +fi + +if [[ $STD -eq 17 ]] ; then + NG="-DNG=ON" +else + NG="-DNG=OFF" fi if [[ "$maj" == "Raspbian" ]] ; then - CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* .. elif [[ "$maj" == "Debian" ]] ; then - CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* .. else - CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $* .. + CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* .. fi diff --git a/engine/inc/com/centreon/engine/retention/parser.hh b/engine/inc/com/centreon/engine/retention/parser.hh index cfd951c6932..349e394d98d 100644 --- a/engine/inc/com/centreon/engine/retention/parser.hh +++ b/engine/inc/com/centreon/engine/retention/parser.hh @@ -36,10 +36,10 @@ class parser { private: typedef void (parser::*store)(state&, object_ptr obj); - template - void _store_into_list(state& retention, object_ptr obj); - template - void _store_object(state& retention, object_ptr obj); + template + void _store_into_list(state& retention, object_ptr obj) noexcept; + template + void _store_object(state& retention, object_ptr obj) noexcept; static store _store[]; }; diff --git a/engine/inc/com/centreon/engine/retention/state.hh b/engine/inc/com/centreon/engine/retention/state.hh index 39192d98d8c..a951b531080 100644 --- a/engine/inc/com/centreon/engine/retention/state.hh +++ b/engine/inc/com/centreon/engine/retention/state.hh @@ -54,7 +54,9 @@ class state { info const& informations() const throw(); list_service& services() throw(); list_service const& services() const throw(); - list_anomalydetection& anomalydetection() { return _anomalydetection; } + list_anomalydetection& anomalydetection() noexcept { + return _anomalydetection; + } list_anomalydetection const& anomalydetection() const { return _anomalydetection; } diff --git a/engine/src/retention/parser.cc b/engine/src/retention/parser.cc index d72ff8e3348..95a392eff32 100644 --- a/engine/src/retention/parser.cc +++ b/engine/src/retention/parser.cc @@ -106,8 +106,8 @@ void parser::parse(std::string const& path, state& retention) { * @param[in] retention The state to fill. * @param[in] obj The object to store. */ -template -void parser::_store_into_list(state& retention, object_ptr obj) { +template +void parser::_store_into_list(state& retention, object_ptr obj) noexcept { (retention.*ptr)().push_back(std::static_pointer_cast(obj)); } @@ -117,7 +117,7 @@ void parser::_store_into_list(state& retention, object_ptr obj) { * @param[in] retention The state to fill. * @param[in] obj The object to store. */ -template -void parser::_store_object(state& retention, object_ptr obj) { +template +void parser::_store_object(state& retention, object_ptr obj) noexcept { (retention.*ptr)() = *std::static_pointer_cast(obj); } diff --git a/engine/src/retention/state.cc b/engine/src/retention/state.cc index 277def52d35..d79a82b32b5 100644 --- a/engine/src/retention/state.cc +++ b/engine/src/retention/state.cc @@ -209,6 +209,6 @@ list_service& state::services() throw() { * * @return The service list. */ -list_service const& state::services() const throw() { +list_service const& state::services() const noexcept { return (_services); }