From 7796ad3a3686694733b936076a3086f8d275f64b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 21 Dec 2014 17:23:56 +0100 Subject: [PATCH] Improve llvm libc++ detection The old detection did only work if CFLAGS contained -std=c++11, since ciso646 was only included for __cplusplus > 199711. Thanks to Koernel for the cmake part. --- config/lyxinclude.m4 | 4 ++++ development/cmake/ConfigureChecks.cmake | 28 ++++++++++++++++--------- development/cmake/config.h.cmake | 3 +++ src/support/debug.h | 2 +- src/support/strfwd.h | 10 +-------- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4 index 815abab3e3..33c5979416 100644 --- a/config/lyxinclude.m4 +++ b/config/lyxinclude.m4 @@ -185,6 +185,10 @@ AC_LANG_POP(C++) if test $lyx_cv_lib_stdcxx = "yes" ; then AC_DEFINE(STD_STRING_USES_COW, 1, [std::string uses copy-on-write]) +else + if test $lyx_cv_prog_clang = "yes" ; then + AC_DEFINE(USE_LLVM_LIBCPP, 1, [use libc++ provided by llvm instead of GNU libstdc++]) + fi fi ### We might want to get or shut warnings. diff --git a/development/cmake/ConfigureChecks.cmake b/development/cmake/ConfigureChecks.cmake index ab9c820eb8..0290c4d9e7 100644 --- a/development/cmake/ConfigureChecks.cmake +++ b/development/cmake/ConfigureChecks.cmake @@ -139,16 +139,24 @@ check_cxx_source_compiles( " STD_STRING_USES_COW) -#get_filename_component(cxx_base "${CMAKE_CXX_COMPILER}" NAME_WE) -#if(cxx_base MATCHES "^clang(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\+\\+)?$") -# set(STD_STRING_USES_COW) -#else() -# if("${MINGW}") -# set(STD_STRING_USES_COW) -# else() -# set(STD_STRING_USES_COW 1) -# endif() -#endif() +check_cxx_source_compiles( + " + #ifndef __clang__ + this is not clang + #endif + int main() { + return(0); + } + " +lyx_cv_prog_clang) + +set(USE_LLVM_LIBCPP) +if(NOT STD_STRING_USES_COW) + if(lyx_cv_prog_clang) + # use libc++ provided by llvm instead of GNU libstdc++ + set(USE_LLVM_LIBCPP 1) + endif() +endif() if(LYX_USE_QT MATCHES "QT5") if (Qt5X11Extras_FOUND) diff --git a/development/cmake/config.h.cmake b/development/cmake/config.h.cmake index d096be750b..ab95cfa4fb 100644 --- a/development/cmake/config.h.cmake +++ b/development/cmake/config.h.cmake @@ -63,6 +63,9 @@ // Define if std::string uses copy-on-write #cmakedefine STD_STRING_USES_COW 1 +// use libc++ provided by llvm instead of GNU libstdc++ +#cmakedefine USE_LLVM_LIBCPP 1 + #cmakedefine Z_PREFIX 1 ${Include_used_spellchecker} diff --git a/src/support/debug.h b/src/support/debug.h index 34258073b9..f8ee6591b1 100644 --- a/src/support/debug.h +++ b/src/support/debug.h @@ -20,7 +20,7 @@ // Forward definitions do not work with libc++ // but ios_base has already been defined in strfwd // if compiling with it -#ifndef _LIBCPP_VERSION +#ifndef USE_LLVM_LIBCPP namespace std { class ios_base; diff --git a/src/support/strfwd.h b/src/support/strfwd.h index 94f2136403..ee4888abd4 100644 --- a/src/support/strfwd.h +++ b/src/support/strfwd.h @@ -13,14 +13,6 @@ #ifndef STRFWD_H #define STRFWD_H -// This includes does nothing but defining _LIBCPP_VERSION -// if libc++ is used (rather than libstdc++) - we first -// check if we have at least a c++03 standard before -// including the file -#if (__cplusplus > 199711L) -#include -#endif - #ifdef USE_WCHAR_T // Prefer this if possible because GNU libstdc++ has usable @@ -37,7 +29,7 @@ namespace lyx { typedef boost::uint32_t char_type; } #endif // Forward definitions do not work with libc++ -#ifdef _LIBCPP_VERSION +#ifdef USE_LLVM_LIBCPP #include #else