]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3785] Added C++ standard
authorFrancis Dupont <fdupont@isc.org>
Sat, 22 Mar 2025 08:40:33 +0000 (09:40 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 24 Mar 2025 14:54:17 +0000 (15:54 +0100)
meson.build
src/bin/netconf/meson.build
src/bin/netconf/tests/meson.build
src/lib/yang/meson.build
src/lib/yang/pretests/meson.build
src/lib/yang/tests/meson.build
src/lib/yang/testutils/meson.build

index 7b8b65f9c0237e1b987d25198a65060a76ba1d56..d8a70d7ecfb1b1a9367af52dfef5e2012178223a 100644 (file)
@@ -21,7 +21,12 @@ project(
     meson_version: '>=1.1.0',
     license: 'MPL-2.0',
     license_files: ['COPYING'],
-    default_options: ['b_asneeded=true', 'b_pch=false', 'b_pie=true'],
+    default_options: [
+        'b_asneeded=true',
+        'b_pch=false',
+        'b_pie=true',
+        'warning_level=2',
+    ],
 )
 
 cpp = meson.get_compiler('cpp')
@@ -283,6 +288,43 @@ conf_data.set('HAVE_PGSQL', POSTGRESQL_DEP.found())
 
 #### Compiler Checks
 
+# The required keyword in cpp.run() is an 1.5.0 feature.
+result = cpp.run(
+    fs.read('compiler-checks/get-cpp-standard.cc'),
+    name: 'Get cpp standard',
+)
+if result.returncode() == 0
+    cpp_standard = result.stdout().strip()
+else
+    error('C++ standard is unknown')
+endif
+message(f'Detected C++ standard (__cplusplus value) is @cpp_standard@.')
+cpp_std_opt = get_option('cpp_std')
+no_cpp_std_opt_msg = 'Please set a C++ standard by setting a CXX variable or by passing the -Dcpp_std argument to meson.'
+cpp_std_opt_msg = f'-Dcpp_std=@cpp_std_opt@ is not enough.'
+if cpp_standard.version_compare('<201100')
+    msgs = [
+        'Kea requires at least C++11 to build.',
+        'Recommended C++ standard is C++14 but some dependencies require at least C++20',
+    ]
+    if cpp_std_opt == 'none'
+        msgs += no_cpp_std_opt_msg
+    else
+        msgs += cpp_std_opt_msg
+    endif
+    error('\n'.join(msgs))
+endif
+# Add Botan 3 to this.
+if NETCONF_DEP.found() and cpp_standard.version_compare('<202000')
+    msgs = ['Netconf dependency requires at least C++20.']
+    if cpp_std_opt == 'none'
+        msgs += no_cpp_std_opt_msg
+    else
+        msgs += cpp_std_opt_msg
+    endif
+    error('\n'.join(msgs))
+endif
+
 result = cpp.run(
     fs.read('compiler-checks/boost-has-threads.cc'),
     dependencies: [boost_dep, threads_dep],
@@ -318,7 +360,7 @@ if cpp.has_link_argument('-Wl,--no-undefined')
         args: ['--shared', '-fPIC', '-Wl,--no-undefined'],
     )
     if not result
-        ENVIRON_SHLIB_FLAGS += ['b_lundef=false']
+        ENVIRON_SHLIB_FLAGS += 'b_lundef=false'
     endif
 endif
 
@@ -473,7 +515,7 @@ else
 endif
 conf_data.set('PACKAGE_VERSION_TYPE', f'"@package_version_type@"')
 
-#### Compiler Flags
+#### Compiler
 
 compile_args = []
 link_args = []
@@ -485,7 +527,7 @@ INSTALL_RPATH = PREFIX / LIBDIR
 BUILD_RPATH = TOP_BUILD_DIR / 'src/lib'
 
 if SYSTEM == 'darwin'
-    compile_args += ['-D__APPLE_USE_RFC_3542']
+    compile_args += '-D__APPLE_USE_RFC_3542'
     add_project_arguments('-D__APPLE_USE_RFC_3542', language: 'cpp')
 endif
 
@@ -505,7 +547,7 @@ no_warnings = ['-Wno-sign-compare']
 cxx_id = cpp.get_id()
 if cxx_id == 'clang' and cpp_args_opt.length() == 0
     add_project_arguments('-Qunused-arguments', language: 'cpp')
-    compile_args += ['-Qunused-arguments']
+    compile_args += '-Qunused-arguments'
     no_warnings += ['-Wno-unused-variable', '-Wno-unused-parameter']
 endif
 if werror_opt
@@ -515,7 +557,7 @@ if cpp_args_opt.length() == 0
     foreach warning : warnings
         if cpp.has_argument(warning)
             add_project_arguments(warning, language: 'cpp')
-            compile_args += [warning]
+            compile_args += warning
         else
             message(f'@warning@ is not supported by the compiler')
         endif
@@ -571,16 +613,7 @@ if result.returncode() == 0
 else
     report_conf_data.set('CXX_VERSION', 'unknown')
 endif
-# The required keyword in cpp.run() is an 1.5.0 feature.
-result = cpp.run(
-    fs.read('compiler-checks/get-cpp-standard.cc'),
-    name: 'Get cpp standard',
-)
-if result.returncode() == 0
-    report_conf_data.set('CXX_STANDARD', result.stdout().strip())
-else
-    error('Cpp standard is unknown')
-endif
+report_conf_data.set('CXX_STANDARD', cpp_standard)
 compile_args += cpp_args_opt
 report_conf_data.set('CXX_ARGS', ' '.join(compile_args))
 report_conf_data.set('LD_ID', cpp.get_linker_id())
index c822aa378cdbf82c6d624641289688420fec09df..ea624903bab576f9d07b1cf0358ea581725b36e4 100644 (file)
@@ -22,7 +22,6 @@ netconf_lib = static_library(
     dependencies: [NETCONF_DEP, CRYPTO_DEP],
     include_directories: [include_directories('.')] + INCLUDES,
     link_with: LIBS_BUILT_SO_FAR,
-    override_options: ['cpp_std=c++20'],
 )
 
 executable(
@@ -35,7 +34,6 @@ executable(
     install_rpath: INSTALL_RPATH,
     build_rpath: BUILD_RPATH,
     link_with: [netconf_lib] + LIBS_BUILT_SO_FAR,
-    override_options: ['cpp_std=c++20'],
 )
 
 subdir('tests')
index 92a36e7c5d557caf186673d5157354be99bbc569..7b2da850e17c6a4b3b7502fe566fded386ec2d31 100644 (file)
@@ -41,7 +41,6 @@ kea_netconf_tests = executable(
         kea_process_testutils_lib,
         kea_testutils_lib,
     ] + LIBS_BUILT_SO_FAR,
-    override_options: ['cpp_std=c++20'],
 )
 test(
     'kea-netconf-tests',
index 3fb6e51f0acecbf9f1aacb11b34f3604200f0ad8..fafea08339e88dc97f220e6c8f8caf978d170965 100644 (file)
@@ -31,7 +31,6 @@ kea_yang_lib = shared_library(
     build_rpath: BUILD_RPATH,
     link_with: LIBS_BUILT_SO_FAR,
     version: '72.0.0',
-    override_options: ['cpp_std=c++20'],
 )
 LIBS_BUILT_SO_FAR = [kea_yang_lib] + LIBS_BUILT_SO_FAR
 kea_yang_headers = [
index 7e53d904a61f65efbe60ae192e2f111f9712d86d..967e6bdd20c520ab7d3084ba2e79c5d8df0f44cc 100644 (file)
@@ -7,6 +7,5 @@ sysrepo_setup_tests = executable(
     'sysrepo_setup_tests.cc',
     dependencies: [NETCONF_DEP, GTEST_DEP],
     include_directories: [include_directories('.')] + INCLUDES,
-    override_options: ['cpp_std=c++20'],
 )
 test('kea-sysrepo-setup-tests', sysrepo_setup_tests)
index d6d03abe865cc98b352c2c54bd072233ce605adc..c5e6bb7f62aba7ebea9bd8c56513f1b304a23dc0 100644 (file)
@@ -34,7 +34,6 @@ kea_yang_tests = executable(
     dependencies: [NETCONF_DEP, GTEST_DEP],
     include_directories: [include_directories('.')] + INCLUDES,
     link_with: [kea_yang_tests_libs] + LIBS_BUILT_SO_FAR,
-    override_options: ['cpp_std=c++20'],
 )
 test(
     'kea-yang-tests',
index d58a0468b8b2ad48b37ee9f72fe9707bce3b3ff9..e16c3979bb779830fc402c8d47e2a40ba3f56baa 100644 (file)
@@ -5,7 +5,5 @@ endif
 kea_yang_testutils_lib = static_library(
     'kea-yang-testutils',
     'translator_test.cc',
-    dependencies: [NETCONF_DEP, GTEST_DEP],
     include_directories: [include_directories('.')] + INCLUDES,
-    override_options: ['cpp_std=c++20'],
 )