summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-04-27 15:10:05 -0400
committerMatthew Pickering <matthewtpickering@gmail.com>2022-06-17 10:05:17 +0100
commitec51453f46bd15f928e82a994784b0d88f128794 (patch)
tree87801eeecb6359f5ac37e97b357292f8a86748a2 /m4
parent367337710d144980f63ac7aa78a9c0929956224b (diff)
downloadhaskell-ec51453f46bd15f928e82a994784b0d88f128794.tar.gz
Introduce package to capture dependency on C++ stdlib
Here we introduce a new "virtual" package into the initial package database, `system-cxx-std-lib`. This gives users a convenient, platform agnostic way to link against C++ libraries, addressing #20010. Fixes #20010. (cherry picked from commit 0ef249aa26f653677c5368bb51af34f7577ba5b9)
Diffstat (limited to 'm4')
-rw-r--r--m4/fp_find_cxx_std_lib.m458
1 files changed, 58 insertions, 0 deletions
diff --git a/m4/fp_find_cxx_std_lib.m4 b/m4/fp_find_cxx_std_lib.m4
new file mode 100644
index 0000000000..d0bb3195c6
--- /dev/null
+++ b/m4/fp_find_cxx_std_lib.m4
@@ -0,0 +1,58 @@
+# FP_FIND_CXX_STD_LIB
+# -------------------
+#
+# Identify which C++ standard library implementation the C++ toolchain links
+# against.
+AC_DEFUN([FP_FIND_CXX_STD_LIB],[
+ # If this is non-empty then assume that the user has specified these
+ # manually.
+ if test -z "$CXX_STD_LIB_LIBS"; then
+ cat >actest.cpp <<-EOF
+#include <iostream>
+#if defined(_LIBCPP_VERSION)
+libc++
+#elif defined(__GLIBCXX__)
+libstdc++
+#else
+unknown
+#endif
+EOF
+ AC_MSG_CHECKING([C++ standard library flavour])
+ if "$CXX" -E actest.cpp -o actest.out; then
+ if grep "libc++" actest.out; then
+ CXX_STD_LIB_LIBS="c++ c++abi"
+ p="`"$CXX" --print-file-name libc++.so`"
+ d="`dirname "$p"`"
+ dnl On some platforms (e.g. Windows) the C++ standard library
+ dnl can be found in the system search path. In this case $CXX
+ dnl --print-file-name will simply print the filename without a
+ dnl directory part. Consequently, dirname will return `.`. However,
+ dnl we don't want to include such paths in the package database.
+ if test "$d" = "."; then d=""; fi
+ CXX_STD_LIB_LIB_DIRS="$d"
+ CXX_STD_LIB_DYN_LIB_DIRS="$d"
+ AC_MSG_RESULT([libc++])
+ elif grep "libstdc++" actest.out; then
+ CXX_STD_LIB_LIBS="stdc++"
+ p="`"$CXX" --print-file-name libstdc++.so`"
+ d="`dirname "$p"`"
+ if test "$d" = "."; then d=""; fi
+ CXX_STD_LIB_LIB_DIRS="$d"
+ CXX_STD_LIB_DYN_LIB_DIRS="$d"
+ AC_MSG_RESULT([libstdc++])
+ else
+ rm -f actest.cpp actest.out
+ AC_MSG_ERROR([Unknown C++ standard library implementation.])
+ fi
+ rm -f actest.cpp actest.out
+ else
+ rm -f actest.cpp actest.out
+ AC_MSG_ERROR([Failed to compile test program])
+ fi
+ fi
+
+ AC_SUBST([CXX_STD_LIB_LIBS])
+ AC_SUBST([CXX_STD_LIB_LIB_DIRS])
+ AC_SUBST([CXX_STD_LIB_DYN_LIB_DIRS])
+])
+