Skip to content

Commit

Permalink
enh(cmake): A work to accept C++17 compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
bouda1 committed Sep 25, 2022
1 parent 887bcf2 commit bd8ca58
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion broker/core/inc/com/centreon/broker/config/parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<absl::string_view>(), &tmp))
throw exceptions::msg_fmt(
"config parser: cannot parse key '{}': "
"the string value must contain an integer",
Expand Down
2 changes: 1 addition & 1 deletion broker/core/src/config/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ absl::optional<bool> parser::check_and_read<bool>(const nlohmann::json& elem,
return {ret};
else if (ret.is_string()) {
bool tmp;
if (!absl::SimpleAtob(ret, &tmp))
if (!absl::SimpleAtob(ret.get<absl::string_view>(), &tmp))
throw msg_fmt(
"config parser: cannot parse key '{}': the string value must "
"contain a boolean (1/0, yes/no, true/false)",
Expand Down
30 changes: 24 additions & 6 deletions cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions engine/inc/com/centreon/engine/retention/parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class parser {
private:
typedef void (parser::*store)(state&, object_ptr obj);

template <typename T, typename T2, T& (state::*ptr)() throw()>
void _store_into_list(state& retention, object_ptr obj);
template <typename T, T& (state::*ptr)() throw()>
void _store_object(state& retention, object_ptr obj);
template <typename T, typename T2, T& (state::*ptr)() noexcept>
void _store_into_list(state& retention, object_ptr obj) noexcept;
template <typename T, T& (state::*ptr)() noexcept>
void _store_object(state& retention, object_ptr obj) noexcept;

static store _store[];
};
Expand Down
4 changes: 3 additions & 1 deletion engine/inc/com/centreon/engine/retention/state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions engine/src/retention/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename T2, T& (state::*ptr)() throw()>
void parser::_store_into_list(state& retention, object_ptr obj) {
template <typename T, typename T2, T& (state::*ptr)() noexcept>
void parser::_store_into_list(state& retention, object_ptr obj) noexcept {
(retention.*ptr)().push_back(std::static_pointer_cast<T2>(obj));
}

Expand All @@ -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 <typename T, T& (state::*ptr)() throw()>
void parser::_store_object(state& retention, object_ptr obj) {
template <typename T, T& (state::*ptr)() noexcept>
void parser::_store_object(state& retention, object_ptr obj) noexcept {
(retention.*ptr)() = *std::static_pointer_cast<T>(obj);
}
2 changes: 1 addition & 1 deletion engine/src/retention/state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit bd8ca58

Please sign in to comment.