[PATCH] [libc++] Add a script which guesses the correct set of libsupc++ include paths.

Peter Collingbourne peter at pcc.me.uk
Thu Oct 17 22:29:33 PDT 2013


The script attempts to guess a reasonable set of libsupc++ include paths
by examining the default header search paths of the executable named g++.
Any path containing a component named 'c++' is included.  I think this
approach is reasonable for a couple of reasons:

 1) Mainline GCC installs its headers to a path containing a component
    named 'c++'.  This should therefore work on any system which has left
    this aspect of the installation alone.

 2) libsupc++ has a stable ABI so any set of paths should do.

With this change (and the corresponding Clang changes), libc++ should build
and be usable 'out of the box' when built as part of the LLVM project with
CMake on Linux.

http://llvm-reviews.chandlerc.com/D1970

Files:
  CMakeLists.txt
  scripts/guess_libsupcxx_include_paths.sh

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -153,6 +153,12 @@
     set(_LIBSUPCXX_DEFINES "")
     set(_LIBSUPCXX_LIBNAME supc++)
   endif()
+  if (NOT DEFINED LIBCXX_LIBSUPCXX_INCLUDE_PATHS)
+    # Call a shell script which attempts to guess the correct paths.
+    exec_program(
+      ${CMAKE_CURRENT_SOURCE_DIR}/scripts/guess_libsupcxx_include_paths.sh
+      OUTPUT_VARIABLE LIBCXX_LIBSUPCXX_INCLUDE_PATHS)
+  endif()
   setup_abi_lib("LIBCXX_LIBSUPCXX_INCLUDE_PATHS"
     "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
     "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
Index: scripts/guess_libsupcxx_include_paths.sh
===================================================================
--- /dev/null
+++ scripts/guess_libsupcxx_include_paths.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# This script attempts to guess a reasonable set of libsupc++ include paths by
+# examining the default header search paths of the executable named g++.  Any
+# path containing a component named 'c++' is included.
+
+CXX=${1:-g++}
+
+first=true
+for path in `echo | $CXX -Wp,-v -x c++ - -fsyntax-only 2>&1 | \
+             grep '^ ' | fgrep /c++/`; do
+  if $first; then
+    first=false
+  else
+    echo -n ';'
+  fi
+  echo -n $path
+done
+
+echo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1970.1.patch
Type: text/x-patch
Size: 1326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131017/c3a21e95/attachment.bin>


More information about the cfe-commits mailing list