diff options
author | Andrei Pavel <andrei@isc.org> | 2022-10-05 16:18:35 +0200 |
---|---|---|
committer | Andrei Pavel <andrei@isc.org> | 2022-10-21 16:45:24 +0200 |
commit | 38c7b0f4e74e49d5808bf9fc4c79333ee6b3291a (patch) | |
tree | 9e67f638e6e400c2ffe3f42ab2dfb7226093787f | |
parent | [#2311] migrate autoconf to libyang2 and sysrepo2 (diff) | |
download | kea-38c7b0f4e74e49d5808bf9fc4c79333ee6b3291a.tar.xz kea-38c7b0f4e74e49d5808bf9fc4c79333ee6b3291a.zip |
[#2311] detect C++20 in autoconf
And enforce -std=c++20 when building
--with-libyang-cpp or --with-sysrepo-cpp.
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | m4macros/ax_cpp20.m4 | 33 | ||||
-rw-r--r-- | m4macros/ax_netconf.m4 | 10 |
3 files changed, 46 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 9f9336a83c..99d38edf48 100644 --- a/configure.ac +++ b/configure.ac @@ -161,6 +161,9 @@ AM_CONDITIONAL(USE_CLANGPP, test "X${CLANGPP}" = "Xyes") # Check for C++11 features support AX_ISC_CPP11 +# Check for C++20 compiler support. +AX_ISC_CPP20 + # Check for std::is_base_of support AC_MSG_CHECKING([for std::is_base_of]) AC_COMPILE_IFELSE( diff --git a/m4macros/ax_cpp20.m4 b/m4macros/ax_cpp20.m4 new file mode 100644 index 0000000000..da116c9dd4 --- /dev/null +++ b/m4macros/ax_cpp20.m4 @@ -0,0 +1,33 @@ +AC_DEFUN([AX_ISC_CPP20], [ + AC_MSG_CHECKING(c++20 support) + + # Save flags. + CPPFLAGS_SAVED="${CPPFLAGS}" + LIBS_SAVED="${LIBS}" + + # Provide -std=c++20 flag temporarily. + CPPFLAGS="${CPPFLAGS} -std=c++20" + + # Simulate the definition of std::derived_from. + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [#include <concepts> + template<class Derived, class Base> + concept derived_from = + std::is_base_of_v<Base, Derived> && + std::is_convertible_v<const volatile Derived*, const volatile Base*>; + + struct BaseClass {}; + struct DerivedClass : BaseClass {}; + ], + [static_assert(std::derived_from<BaseClass, DerivedClass> == false); + static_assert(std::derived_from<DerivedClass, BaseClass> == true);] + )], + [AC_MSG_RESULT([yes]) + CPP20_SUPPORTED=true], + [AC_MSG_RESULT([no]) + CPP20_SUPPORTED=false]) + + # Restore flags. + CPPFLAGS="${CPPFLAGS_SAVED}" +]) diff --git a/m4macros/ax_netconf.m4 b/m4macros/ax_netconf.m4 index 23b0b42c1a..7708cd03fa 100644 --- a/m4macros/ax_netconf.m4 +++ b/m4macros/ax_netconf.m4 @@ -88,6 +88,11 @@ $(cat conftest.err)])] LIBYANGCPP_PREFIX="${LIBRARY_PREFIX}" LIBYANGCPP_VERSION="${LIBRARY_VERSION}" + if ! "${CPP20_SUPPORTED}"; then + AC_MSG_RESULT([no]) + AC_MSG_ERROR([You need a compiler with C++20 support to enable libyang-cpp.]) + fi + # Save flags. CPPFLAGS_SAVED="${CPPFLAGS}" LIBS_SAVED="${LIBS}" @@ -199,6 +204,11 @@ $(cat conftest.err)])] SYSREPOCPP_PREFIX="${LIBRARY_PREFIX}" SYSREPOCPP_VERSION="${LIBRARY_VERSION}" + if ! "${CPP20_SUPPORTED}"; then + AC_MSG_RESULT([no]) + AC_MSG_ERROR([You need a compiler with C++20 support to enable sysrepo-cpp.]) + fi + # Save flags. CPPFLAGS_SAVED="${CPPFLAGS}" LIBS_SAVED="${LIBS}" |