llvm-config: Add --has-rtti option
authorTom Stellard <thomas.stellard@amd.com>
Wed, 4 Nov 2015 20:57:43 +0000 (20:57 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Wed, 4 Nov 2015 20:57:43 +0000 (20:57 +0000)
Summary:
This prints NO if LLVM was built with -fno-rtti or an equivalent flag
and YES otherwise.  The reasons to add -has-rtti rather than adding -fno-rtti
to --cxxflags are:

1. Building LLVM with -fno-rtti does not always mean that client
applications need this flag.

2. Some compilers have a different flag for disabling rtti, and the
compiler being used to build LLVM may not be the compiler being used to
build the application.

Reviewers: echristo, chandlerc, beanz

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11849

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252075 91177308-0d34-0410-b5e6-96231b3b80d8

cmake/modules/AddLLVM.cmake
tools/llvm-config/BuildVariables.inc.in
tools/llvm-config/CMakeLists.txt
tools/llvm-config/Makefile
tools/llvm-config/llvm-config.cpp

index c3e1679bdb5dfca444c33101a079bb94ec010358..8d0cf7c561574e6d3e00677db9b6858322c51eb9 100644 (file)
@@ -26,7 +26,9 @@ function(llvm_update_compile_flags name)
 
   # LLVM_REQUIRES_RTTI is an internal flag that individual
   # targets can use to force RTTI
 
   # LLVM_REQUIRES_RTTI is an internal flag that individual
   # targets can use to force RTTI
+  set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "")
   if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
   if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
+    set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "")
     list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
       list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
     list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
       list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
index 0f28fad31709877d396c260073d6ed884fa54323..38465f60d070dd44dc15524ad5f0e6c0a7cd8fe8 100644 (file)
@@ -27,3 +27,4 @@
 #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
 #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
 #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
 #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
 #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
 #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
+#define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@"
index dd534600e8fed72086b3239b8bff5925cfa17887..d1f8706496219c35b9e4b2e96802ff0a31403a12 100644 (file)
@@ -25,6 +25,7 @@ set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_
 set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
 set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
 set(LLVM_BUILD_SYSTEM cmake)
 set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
 set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
 set(LLVM_BUILD_SYSTEM cmake)
+set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
 
 # Use the C++ link flags, since they should be a superset of C link flags.
 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
 
 # Use the C++ link flags, since they should be a superset of C link flags.
 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
index c2b5e8f9b9e624fd2fd4a898791c219f03eddc80..03d910bb03f05bd6c74bb0549ca788fec5504479 100644 (file)
@@ -38,6 +38,12 @@ else
   LLVM_SYSTEM_LIBS := $(LIBS)
 endif
 
   LLVM_SYSTEM_LIBS := $(LIBS)
 endif
 
+ifneq ($(REQUIRES_RTTI), 1)
+  LLVM_HAS_RTTI := NO
+else
+  LLVM_HAS_RTTI := YES
+endif
+
 # This is blank for now.  We need to be careful about adding stuff here:
 # LDFLAGS tend not to be portable, and we don't currently require the
 # user to use libtool when linking against LLVM.
 # This is blank for now.  We need to be careful about adding stuff here:
 # LDFLAGS tend not to be portable, and we don't currently require the
 # user to use libtool when linking against LLVM.
@@ -67,6 +73,8 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) Makefile $(ObjDir)/.dir
          >> temp.sed
        $(Verb) $(ECHO) 's/@LLVM_BUILD_SYSTEM@/autoconf/' \
          >> temp.sed
          >> temp.sed
        $(Verb) $(ECHO) 's/@LLVM_BUILD_SYSTEM@/autoconf/' \
          >> temp.sed
+       $(Verb) $(ECHO) 's/@LLVM_HAS_RTTI@/$(LLVM_HAS_RTTI)/' \
+         >> temp.sed
        $(Verb) $(SED) -f temp.sed < $< > $@
        $(Verb) $(RM) temp.sed
 
        $(Verb) $(SED) -f temp.sed < $< > $@
        $(Verb) $(RM) temp.sed
 
index 4ce8f1002adc73b5761ca6e21cc0cc63b669f455..8bf2680d3918b32ef457396d19853041c6eda7fd 100644 (file)
@@ -158,6 +158,7 @@ Options:\n\
   --build-mode      Print build mode of LLVM tree (e.g. Debug or Release).\n\
   --assertion-mode  Print assertion mode of LLVM tree (ON or OFF).\n\
   --build-system    Print the build system used to build LLVM (autoconf or cmake).\n\
   --build-mode      Print build mode of LLVM tree (e.g. Debug or Release).\n\
   --assertion-mode  Print assertion mode of LLVM tree (ON or OFF).\n\
   --build-system    Print the build system used to build LLVM (autoconf or cmake).\n\
+  --has-rtti        Print whether or not LLVM was built with rtti (YES or NO).\n\
 Typical components:\n\
   all               All LLVM libraries (default).\n\
   engine            Either a native JIT or a bitcode interpreter.\n";
 Typical components:\n\
   all               All LLVM libraries (default).\n\
   engine            Either a native JIT or a bitcode interpreter.\n";
@@ -326,6 +327,8 @@ int main(int argc, char **argv) {
 #endif
       } else if (Arg == "--build-system") {
         OS << LLVM_BUILD_SYSTEM << '\n';
 #endif
       } else if (Arg == "--build-system") {
         OS << LLVM_BUILD_SYSTEM << '\n';
+      } else if (Arg == "--has-rtti") {
+        OS << LLVM_HAS_RTTI << '\n';
       } else if (Arg == "--obj-root") {
         OS << ActivePrefix << '\n';
       } else if (Arg == "--src-root") {
       } else if (Arg == "--obj-root") {
         OS << ActivePrefix << '\n';
       } else if (Arg == "--src-root") {