Skip to content

Commit 18bf626

Browse files
committedNov 4, 2015
llvm-config: Add --has-rtti option
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 llvm-svn: 252075
1 parent 7e6606f commit 18bf626

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed
 

‎llvm/cmake/modules/AddLLVM.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ function(llvm_update_compile_flags name)
2626

2727
# LLVM_REQUIRES_RTTI is an internal flag that individual
2828
# targets can use to force RTTI
29+
set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "")
2930
if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
31+
set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "")
3032
list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
3133
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
3234
list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")

‎llvm/tools/llvm-config/BuildVariables.inc.in

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
2828
#define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
2929
#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
30+
#define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@"

‎llvm/tools/llvm-config/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_
2525
set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
2626
set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
2727
set(LLVM_BUILD_SYSTEM cmake)
28+
set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
2829

2930
# Use the C++ link flags, since they should be a superset of C link flags.
3031
set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")

‎llvm/tools/llvm-config/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ else
3838
LLVM_SYSTEM_LIBS := $(LIBS)
3939
endif
4040

41+
ifneq ($(REQUIRES_RTTI), 1)
42+
LLVM_HAS_RTTI := NO
43+
else
44+
LLVM_HAS_RTTI := YES
45+
endif
46+
4147
# This is blank for now. We need to be careful about adding stuff here:
4248
# LDFLAGS tend not to be portable, and we don't currently require the
4349
# user to use libtool when linking against LLVM.
@@ -67,6 +73,8 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) Makefile $(ObjDir)/.dir
6773
>> temp.sed
6874
$(Verb) $(ECHO) 's/@LLVM_BUILD_SYSTEM@/autoconf/' \
6975
>> temp.sed
76+
$(Verb) $(ECHO) 's/@LLVM_HAS_RTTI@/$(LLVM_HAS_RTTI)/' \
77+
>> temp.sed
7078
$(Verb) $(SED) -f temp.sed < $< > $@
7179
$(Verb) $(RM) temp.sed
7280

‎llvm/tools/llvm-config/llvm-config.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Options:\n\
158158
--build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
159159
--assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
160160
--build-system Print the build system used to build LLVM (autoconf or cmake).\n\
161+
--has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\
161162
Typical components:\n\
162163
all All LLVM libraries (default).\n\
163164
engine Either a native JIT or a bitcode interpreter.\n";
@@ -326,6 +327,8 @@ int main(int argc, char **argv) {
326327
#endif
327328
} else if (Arg == "--build-system") {
328329
OS << LLVM_BUILD_SYSTEM << '\n';
330+
} else if (Arg == "--has-rtti") {
331+
OS << LLVM_HAS_RTTI << '\n';
329332
} else if (Arg == "--obj-root") {
330333
OS << ActivePrefix << '\n';
331334
} else if (Arg == "--src-root") {

0 commit comments

Comments
 (0)
Please sign in to comment.