From c05664d3f3c9143e8c56b65377635b5b8a4210c6 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 11 Jul 2024 18:24:13 -0700 Subject: [PATCH] meson: Keep cpp23_args for clang --- .github/workflows/main.yml | 2 +- meson.build | 60 +++++++++++++++++++------------------- src/meson.build | 6 ++-- src/utils.h | 2 +- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0b42548..78b157c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -170,7 +170,7 @@ jobs: - if: ${{ matrix.flavor == 'windows' }} name: Configure Windows Latest run: | - meson setup --warnlevel 3 --buildtype release --default-library static -Dcpp_std=vc++latest -Dcpp_eh=a -Dlibxml2:warning_level=0 -Dminiz:warning_level=0 -Dlibjpeg-turbo:warning_level=0 -Dcpp-httplib:cpp-httplib_openssl=disabled -Dlibxmlpp:build-tests=false -Dlibxml2:python=disabled -Dlibxml2:iconv=disabled --force-fallback-for libpng build + meson setup --warnlevel 3 --buildtype release -Dcpp_std=vc++latest --default-library static -Dcpp_eh=a -Dlibxml2:warning_level=0 -Dminiz:warning_level=0 -Dlibjpeg-turbo:warning_level=0 -Dcpp-httplib:cpp-httplib_openssl=disabled -Dlibxmlpp:build-tests=false -Dlibxml2:python=disabled -Dlibxml2:iconv=disabled --force-fallback-for libpng build - name: Compile run: ninja -C build diff --git a/meson.build b/meson.build index 9dd35ad..395fad9 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('dregarnuhr', ['c', 'cpp'], license : 'GPLv3+', version : '1.5.10.0', - default_options : ['c_std=gnu17', + default_options : ['c_std=c17', 'cpp_std=c++23', 'buildtype=release', 'default_library=static', @@ -12,37 +12,37 @@ if host_machine.system() == 'linux' endif cpp_compiler = meson.get_compiler('cpp') -if cpp_compiler.get_argument_syntax() == 'msvc' -else - if cpp_compiler.get_id() == 'clang' - cpp23_args += '-stdlib=libc++' - cpp23_args += '-fexperimental-library' - add_global_link_arguments('-stdlib=libc++', language: 'cpp') - - if get_option('buildtype') == 'debug' - cpp23_args += '-gdwarf-4' - add_global_arguments('-gdwarf-4', language: 'c') - endif - endif +cpp23_args = [] +if cpp_compiler.get_id() == 'clang' + cpp23_args += '-stdlib=libc++' + cpp23_args += '-fexperimental-library' + add_global_link_arguments('-stdlib=libc++', language: 'cpp') + if get_option('buildtype') == 'debug' + cpp23_args += '-gdwarf-4' + add_global_arguments('-gdwarf-4', language: 'c') + endif endif -cpp_compiler.has_header_symbol('version', '__cpp_lib_filesystem', required: true) -cpp_compiler.has_header_symbol('version', '__cpp_lib_string_view', required: true) -cpp_compiler.has_header_symbol('version', '__cpp_lib_ranges', required: true) -cpp_compiler.has_header_symbol('version', '__cpp_lib_source_location', required: true) -cpp_compiler.has_header_symbol('version', '__cpp_concepts', required: true) -cpp_compiler.compute_int('__cpp_concepts', prefix: '#include') -cpp_compiler.has_header_symbol('version', '__cpp_lib_integer_comparison_functions', required: true) -cpp_compiler.has_header_symbol('version', '__cpp_lib_expected', required: true) -cpp_compiler.has_header_symbol('version', '__cpp_size_t_suffix') -cpp_compiler.has_header_symbol('version', '__cpp_lib_ranges_zip') -cpp_compiler.has_header_symbol('version', '__cpp_lib_stacktrace') -cpp_compiler.has_header_symbol('version', '__cpp_lib_spanstream') -cpp_compiler.has_header_symbol('version', '__cpp_lib_flat_map') -cpp_compiler.has_header_symbol('version', '__cpp_lib_format') - -has_chrono = 1 == cpp_compiler.compute_int('__cpp_lib_chrono >= 201907L', prefix: '#include') +message('Adding cpp23 args: ', cpp23_args) +add_global_arguments(cpp23_args, language: 'cpp') + +cpp_compiler.has_header_symbol('version', '__cpp_lib_filesystem', required: true, args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_string_view', required: true, args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_ranges', required: true, args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_source_location', required: true, args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_concepts', required: true, args: cpp23_args) +cpp_compiler.compute_int('__cpp_concepts', prefix: '#include', args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_integer_comparison_functions', required: true, args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_expected', required: true, args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_size_t_suffix', args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_ranges_zip', args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_stacktrace', args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_spanstream', args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_flat_map', args: cpp23_args) +cpp_compiler.has_header_symbol('version', '__cpp_lib_format', args: cpp23_args) + +has_chrono = 1 == cpp_compiler.compute_int('__cpp_lib_chrono >= 201907L', prefix: '#include', args: cpp23_args) # Fedora libxml++-devel. Ubuntu doesn't have a -5.0 package. libxmlpp_dep = dependency('libxml++-5.0', @@ -70,7 +70,7 @@ if not miniz_dep.found() endif # Unpackaged -if not cpp_compiler.has_header('outcome/outcome.hpp') +if not cpp_compiler.has_header('outcome/outcome.hpp', args: cpp23_args) outcome_dep = dependency('outcome-2.0', fallback: ['outcome']) else outcome_dep = dependency('', required: false) diff --git a/src/meson.build b/src/meson.build index 4fbec6d..f2520d0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,11 +4,11 @@ conf_data = configuration_data() conf_data.set('IS_WINDOWS', host_machine.system() == 'windows' ? 'true' : 'false') conf_data.set10('HAVE_CHRONO', has_chrono) -if cpp_compiler.has_header_symbol('ios', 'std::ios_base::noreplace') +if cpp_compiler.has_header_symbol('ios', 'std::ios_base::noreplace', args: cpp23_args) conf_data.set('NOREPLACE', 'std::ios_base::noreplace') -elif cpp_compiler.has_header_symbol('ios', 'std::ios_base::__noreplace') +elif cpp_compiler.has_header_symbol('ios', 'std::ios_base::__noreplace', args: cpp23_args) conf_data.set('NOREPLACE', 'std::ios_base::__noreplace') -elif cpp_compiler.has_header_symbol('ios', 'std::ios_base::_Noreplace') +elif cpp_compiler.has_header_symbol('ios', 'std::ios_base::_Noreplace', args: cpp23_args) conf_data.set('NOREPLACE', 'std::ios_base::_Noreplace') else conf_data.set('NOREPLACE', 'std::ios_base::binary') diff --git a/src/utils.h b/src/utils.h index 5619b06..5953ac2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -240,7 +240,7 @@ namespace utils [[nodiscard]] auto safe_int_cast(From from) -> std::remove_cvref_t { using namespace std::string_view_literals; auto res = static_cast>(from); - if (!std::in_range(from)) { + if (std::cmp_not_equal(res, from)) [[unlikely]] { std::string error_message = utils::strcat("Trying to cast from ", from, " to a type that would become ", res); if (std::cmp_greater(from, res)) { throw std::overflow_error(error_message);