diff options
author | Michał Górny <mgorny@gentoo.org> | 2022-10-07 17:02:28 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2022-10-10 22:52:34 +0200 |
commit | 2170307e8e09491f88b0c5f41d42aa096d1b3632 (patch) | |
tree | 0efac14aa0c744ce277b77bcbd1f1cf30025822a /eclass/toolchain-funcs.eclass | |
parent | dev-cpp/tbb: drop 2021.4.0, 2021.6.0 (diff) | |
download | gentoo-2170307e8e09491f88b0c5f41d42aa096d1b3632.tar.gz gentoo-2170307e8e09491f88b0c5f41d42aa096d1b3632.tar.bz2 gentoo-2170307e8e09491f88b0c5f41d42aa096d1b3632.zip |
toolchain-funcs.eclass: Add tc-get-cxx-stdlib() to get C++ stdlib
Add a new tc-get-cxx-stdlib() that attempts to get the C++ stdlib
variant used by the current C++ compiler. Currently it supports libc++
and libstdc++ (GCC's stdlib).
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/toolchain-funcs.eclass')
-rw-r--r-- | eclass/toolchain-funcs.eclass | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index 48bf11606c4a..92494158201e 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -1173,4 +1173,40 @@ gen_usr_ldscript() { done } +# @FUNCTION: tc-get-cxx-stdlib +# @DESCRIPTION: +# Attempt to identify the C++ standard library used by the compiler. +# If the library is identified, the function returns 0 and prints one +# of the following: +# +# - ``libc++`` for ``sys-libs/libcxx`` +# - ``libstdc++`` for ``sys-devel/gcc``'s libstdc++ +# +# If the library is not recognized, the function returns 1. +tc-get-cxx-stdlib() { + local code='#include <ciso646> + +#if defined(_LIBCPP_VERSION) + HAVE_LIBCXX +#elif defined(__GLIBCXX__) + HAVE_LIBSTDCPP +#endif +' + local res=$( + $(tc-getCXX) ${CXXFLAGS} ${CPPFLAGS} -x c++ -E -P - \ + <<<"${code}" 2>/dev/null + ) + + case ${res} in + *HAVE_LIBCXX*) + echo libc++;; + *HAVE_LIBSTDCPP*) + echo libstdc++;; + *) + return 1;; + esac + + return 0 +} + fi |