summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
AgeCommit message (Collapse)Author
2024-10-04Fix C++ standard support for EmscriptenElliott Sales de Andrade
The first versions of Emscripten that correspond with the Clang version Meson uses to determine flag support don't actually support the expected flags. So I went through and picked the first version that actually worked with the expected flags. Fixes #13628
2024-07-21compilers: fix partial refactor of coredata optionsEli Schwartz
Fallout from the OptionStore refactor, and specifically commit 9a6fcd4d9a0c7bb248c5d0587632b741a3301e03. The `std` object was migrated from having an option itself, to having the value fetched and saved directly. In most cases, this also meant avoiding `.value`, but in a couple cases this refactor went overlooked, and crashed at runtime. Only affects Elbrus and Intel C++ compilers, seemingly. Fixes #13401
2024-07-17Remove language (AKA compiler) type from OptionKey.Jussi Pakkanen
2024-07-12Rename langopt methodJussi Pakkanen
The public facing name of language options is compiler option, so let's standardise on that.
2024-06-26compilers: Add support for OpenMP from homebrew with AppleClangDylan Baker
Which requires injecting some extra paths and the `-Xpreprocess` flag, as well as extra search paths for libomp and the headers. Fixes: #7435
2024-06-23compilers: cpp: fix header name and return value use in header checkBarnabás Pőcze
There are two issues: 1. has_header() wants just the header name without surrounding <> or similar; it fails otherwise. 2. has_header() returns a tuple of two bools, where the first element determines whether or not the header has been found. So use that element specifically, otherwise the tuple will always evaluate to true because it is not empty. Fixes: 675b47b0692131 ("compilers: cpp: improve libc++ vs libstdc++ detection (again)")
2024-06-14Fix mypy.Jussi Pakkanen
2024-06-14Replace direct indexing with named methods.Jussi Pakkanen
2024-06-08Use helper method in C++ compiler classes.Jussi Pakkanen
2024-05-23Refactor option classes to their own file.Jussi Pakkanen
2024-03-28compilers: cpp: reduce macro pollution for stdlib macrosSam James
Now that we have access to Environment in get_assert_args, we can check what the actual C++ stdlib provider is and only set relevant macros rather than all possibly-relevant ones based on the compiler. Also, while we're here, now that's sorted, wire up the GCC experimental libc++ support in the macro emission given it doesn't uglify anything for libstdc++ users now. Bug: https://github.com/mesonbuild/meson/issues/12962 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-28compilers: cpp: factor out C++ stdlib detectionSam James
We're going to use it in some more places in a minute (for controlling assertions). Bug: https://github.com/mesonbuild/meson/issues/12962 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-28Pass Environment down from BackendSam James
We'll need it in a moment for get_base_compile_args -> get_assert_args. Bug: https://github.com/mesonbuild/meson/issues/12962 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-28compilers: cpp: don't set stdlib assertion macros if already setSam James
Followup to 90098473d51e6f059e775f1833b0a2ea91c8f8f9. If the compiler already has one of these assertion macros [0] set, then don't interfere. e.g. a Linux distribution might be setting a stricter default than usual. This is a pitfall many fell into with _FORTIFY_SOURCE and it's why AX_ADD_FORTIFY_SOURCE [1] was contributed to autoconf-archive. [0] _GLIBCXX_ASSERTIONS, _LIBCPP_HARDENING_MODE, or _LIBCPP_ENABLE_ASSERTIONS. [1] https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html Bug: https://github.com/mesonbuild/meson/issues/12962 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-28compilers: cpp: relax assertion level for libc++Sam James
Followup to 90098473d51e6f059e775f1833b0a2ea91c8f8f9. I changed my mind on this a few times. libcxx's documentation describes [0] the hardening modes as: """ 1) Unchecked mode/none, which disables all hardening checks. 2) Fast mode, which contains a set of security-critical checks that can be done with relatively little overhead in constant time and are intended to be used in production. We recommend most projects adopt this. 3) Extensive mode, which contains all the checks from fast mode and some additional checks for undefined behavior that incur relatively little overhead but aren’t security-critical. Production builds requiring a broader set of checks than fast mode should consider enabling extensive mode. The additional rigour impacts performance more than fast mode: we recommend benchmarking to determine if that is acceptable for your program. 4) Debug mode, which enables all the available checks in the library, including internal assertions, some of which might be very expensive. This mode is intended to be used for testing, not in production. """ We chose 3) before because it felt like a better fit for what we're trying to do and the most equivalent option to libstdc++'s _GLIBCXX_ASSERTIONS, but on reflection, maybe we're better off picking a default with less overhead and more importantly guarantees constant time checks. [0] https://libcxx.llvm.org/Hardening.html#using-hardening-modes Bug: https://github.com/mesonbuild/meson/issues/12962 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-15Improve error messages for invalid option valuesCharles Brunet
By adding the option name to UserOption object, it is now possible to display the name of the affected option when the given option value is not valid. Fixes #12635
2024-03-15compilers: No need to pass exe_wrapper everywhereXavier Claessens
Places where compiler needs it already have access to Environment object and can use it directly. This fixes mypy complaining that not all compilers have self.exe_wrapper in run() method that got moved to base class.
2024-03-13compilers: cpp: improve libc++ vs libstdc++ detection (again)Sam James
The previous approach wasn't great because you couldn't control what the detected C++ stdlib impl was. We just had a preference list we tweaked the searched order for per OS. That doesn't work great for e.g. Gentoo with libc++ or Gentoo Prefix on macOS where we might be using libstdc++ even though the host is libc++. Jonathan Wakely, the libstdc++ maintainer, gave a helpful answer on how to best detect libc++ vs libstdc++ via macros on SO [0]. Implement it. TL;DR: Use <version> from C++20 if we can, use <ciso646> otherwise. Check for _LIBCPP_VERSION as libstdc++ doesn't always define a macro. [0] https://stackoverflow.com/a/31658120 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-12Added support for Texas Instruments C6000 compiler.Petr Machacek
2024-01-09compilers: cpp: wire up debugstl for ClangSam James
For Clang, we now pass -D_GLIBCXX_DEBUG=1 if debugstl is enabled, and we also pass -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG. Per https://discourse.llvm.org/t/building-a-program-with-d-libcpp-debug-1-against-a-libc-that-is-not-itself-built-with-that-define/59176/3, we can't use _LIBCPP_DEBUG for older Clang versions as it's unreliable unless libc++ was built with it. We choose MODE_DEBUG for stldebug while building with assertions will do MODE_EXTENSIVE. Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-01-09compilers: cpp: wire up stdlib assertionsSam James
None of the options set here affect ABI and are intended for detecting constraint violations. For GCC, we simply need to set -D_GLIBCXX_ASSERTIONS. For Clang, the situation is far more complicated: * LLVM 18 uses a 'hardened mode' (https://libcxx.llvm.org/Hardening.html). There are several levels of severity available here. I've chosen _LIBCPP_HARDENING_MODE_EXTENSIVE as the strongest-but-one. The strongest one (_DEBUG) doesn't affect ABI still but is reserved for stldebug. * LLVM 15 uses a similar approach to libstdc++ called '_LIBCPP_ENABLE_ASSERTIONS' Note that LLVM 17 while in development had fully deprecated _LIBCPP_ENABLE_ASSERTIONS in favour of hardened, but changed its mind last-minute: https://discourse.llvm.org/t/rfc-hardening-in-libc/73925/4. Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-10-12cpp: use -nostlib++ instead of -nostlib for custom cpp_stdlibMattijs Korpershoek
The <lang>_stdlib can be used in cross files to use a custom standard library for a given language. When cpp_stdlib is used in a cross file, meson passes * -nostdinc++ to the compiler * -nostlib to the linker According to [1] (gcc) and [2] (clang), we should pass -nostlib++ to the linker when we don't want to link to the standard C++ library. Currently, we pass -nostlib. Fix this by implementing a C++ specific get_no_stdlib_link_args() function. [1] https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#index-nostdlib_002b_002b [2] https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-nostdlib Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-10-09Allow c++23 in gcc-11.Benjamin Redelings
2023-09-24cpp: restore c++26 supportChristoph Reiter
c++26 support was added in #11986, but regressed in #10332 because the versions now get checked against the global _ALL_STDS list, and c++26 was missing there. Fix by adding c++26 to _ALL_STDS
2023-08-07c_std, cpp_std: Change to a list of desired versions in preference orderXavier Claessens
Projects that prefer GNU C but can fallback to ISO C can now set for example `default_options: 'c_std=gnu11,c11'` and it will use gnu11 when available, fallback to c11 otherwise. It is an error only if none of the values are supported by the current compiler. This allows to deprecate gnuXX values from MSVC compiler, that means that `default_options: 'c_std=gnu11'` will now print warning with MSVC but still fallback to 'c11' value. No warning is printed if at least one of the values is valid, i.e. `default_options: 'c_std=gnu11,c11'`. In the future that deprecation warning will become an hard error because `c_std=gnu11` should mean GNU is required, for projects that cannot be built with MSVC for example.
2023-07-31Merge pull request #11986 from williamspatrick/clang-enable-cpp23Jussi Pakkanen
add support for newer C++ -std= flags on Clang/GCC
2023-07-17Merge pull request #11976 from tristan957/cleanupsJussi Pakkanen
Some various type related cleanups
2023-07-14c++: add support for c++23/c++26 standard and aliasesSteven Noonan
GCC 12.3 and Clang 16 support -std flags for c++23/c++2b. The unreleased GCC 14 and Clang 17 will support -std flags for c++26/c++2c. Signed-off-by: Steven Noonan <steven@uplinklabs.net> Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-07-14c++: add fallback mappings for C++23 and C++26Steven Noonan
The c++23 mappings apply to current production compilers (GCC, Clang). None of the production c++ compilers support c++26 flags yet, but this mapping will be ready once they do. Signed-off-by: Steven Noonan <steven@uplinklabs.net> Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-07-12Match the method signatures of parent classesTristan Partin
Names and types of some methods did not match their parent methods.
2023-07-12Make CPPCompiler.get_display_language() a classmethodTristan Partin
This matches the parent declaration.
2023-07-12Annotate naked fundamental Python typesTristan Partin
Although mypy wasn't complaining, pyright was.
2023-07-12Use CompileCheckMode enumTristan Partin
There were a ton of naked strings with TODOs telling us to use the enum.
2023-07-11compilers/cpp: check libc++ vs libstdc++ harderDylan Baker
Instead of hardcoding any values, hardcode what we think the most likely implementation is, and check that first. It was pointed out that while for example, Apple only provides libc++ and supports that for xcode, a user could install a custom environment (such as homebrew) which uses it's own copy of libstdc++, and we need to account for that. This means that a library search will be done, but only once and the result will be cached, on all systems.
2023-06-29compilers/cpp: remove special libc++ handling from the AppleClangCPPCompilerDylan Baker
The base implementation handles this already, with the added bonuses of caching, and having one less code path to test.
2023-06-29compilers/cpp: try to do a better job of detecting libc++ vs libstdc++Dylan Baker
Currently, we hardcode libc++ for MacOS (and derivatives), and libstdc++ for all other cases. Clang had some hackery to make this work in many cases. However, this doesn't always work, namely if you try to to use Rust as the linker when libc++ is required. This implementation does, as an optimization, provide a hardcoded list of OSes we know always use libc++, and otherwise will attempt to detect it. As a second optimization, the detected values are cached, so the lookup is only done once fixes: #11921
2023-06-29compilers/cpp: use a Mixin to share the stdlib flags between clang++ and g++Dylan Baker
Which will make subsequent work easier
2023-06-29compilers/cpp: use a list comprehension instead of a for loopDylan Baker
It's slightly faster, and less code
2023-06-29compilers/cpp: Actually add the search dirs to for gccDylan Baker
We calculate them, but then don't use them. Clang does use them, so this looks like a simple oversight
2023-06-26linkers: delay implementations import until detect is runEli Schwartz
This saves on a 1500-line import at startup and may be skipped entirely if no compiled languages are used. In exchange, we move the implementation to a new file that is imported instead. Followup to commit ab20eb5bbc21ae855bcd211131132d2778602bcf.
2023-04-24Initial support for Metrowerks C/C++ compilerNomura
2023-04-17Add c++23 to the list of C++ standards.Jussi Pakkanen
2023-02-08compilers: Optimize the /Zc:__cplusplus codeDylan Baker
This could also be handled once, in the initializer
2023-01-04clang-cl: supports /std:c++20 now.Luke Elliott
See https://github.com/llvm/llvm-project/commit/a8f75d49
2023-01-03Add fatal=False to many mlog.warnings()Dylan Baker
There are lots of warnings that become fatal, that are simply unfixable by the end user. Things like using old versions of software (because they're using some kind of LTS release), warnings about compilers not supporting certain kinds of checks, or standards being upgraded due to skipped implementations (MSVC has c++98 and c++14, but not c++11). None of these should be fatal, they're informative, and too important to reduce to notices, but not important enough to stop meson if they're printed.
2023-01-03reformat some warnings for better code readabilityDylan Baker
2022-12-27emscripten: enforce version 1.39.19 or higherKleis Auke Wolthuizen
2022-11-27Add warning_level=everythingDavid Robillard
Adds a new maximum warning level that is roughly equivalent to "all warnings". This adds a way to use `/Wall` with MSVC (without the previous broken warning), `-Weverything` with clang, and almost all general warnings in GCC with strictness roughly equivalent to clang's `-Weverything`. The GCC case must be implemented by meson since GCC doesn't provide a similar option. To avoid maintenance headaches for meson, this warning level is defined objectively: all warnings are included except those that require specific values or are specific to particular language revisions. This warning level is mainly intended for new code, and it is expected (nearly guaranteed) that projects will need to add some suppressions to build cleanly with it. More commonly, it's just a handy way to occasionally take a look at what warnings are present with some compiler, in case anything interesting shows up you might want to enable in general. Since the warnings enabled at this level are inherently unstable with respect to compiler versions, it is intended for use by developers and not to be set as the default.
2022-11-22compilers: remove opinionated c++ warning flagEli Schwartz
-Wnon-virtual-dtor is not what people think of as a standard warning flag. It was previously removed from -Wall in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16190 on the grounds that people didn't like it and were refusing to use -Wall at all because it forced this warning. Instead, it is enabled by -Weffc++ which is typically not enabled and even comes with GCC documentation warnings stating that the standard library doesn't obey it, and you might need to `grep -v` and filter out warnings. (!!!) It doesn't fit into the typical semantics of Meson's warning_level option, which usually aligns with compiler standard warning levels rather than a niche ideological warning level. It was originally added in commit 22af56e05aa9cba4740d2ff303d876bb0c3cfb2b, but without any specific rationale included, and has gone unquestioned since then -- except by the Meson users who see it, assume there is a finely crafted design behind it, and quietly opt out by rolling their own warning options with `add_project_arguments('-Wall', ...)`. Furthermore a GCC component maintainer for the C++ standard library opened a Meson bug report specially to tell us that this warning flag is a "dumb option" and "broken by design" and "doesn't warn about the right thing anyway", thus it should not be used. This is a reasonably authoritative source that maybe, just maybe, this flag... is too opinionated to force upon Meson users without recourse. It's gone beyond opinionated and into the realm of compiler vendors seem to think that the state of the language would be better if the flag did not exist at all, whether default or not. Fixes #11096