From 8429f50d3a34c7f5f035c2434825117274664f26 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Thu, 19 Sep 2019 04:44:46 -0600 Subject: [PATCH] CMake: Use -fno-rtti on most build configurations --- dtool/CompilerFlags.cmake | 27 +++++++++++++++++++++++++++ dtool/LocalSetup.cmake | 1 - dtool/dtool_config.h.in | 3 --- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dtool/CompilerFlags.cmake b/dtool/CompilerFlags.cmake index d48ffe3aa7..118e8f95d6 100644 --- a/dtool/CompilerFlags.cmake +++ b/dtool/CompilerFlags.cmake @@ -127,6 +127,9 @@ if(MSVC) set(cxx_exceptions_on "/EHsc") set(cxx_exceptions_off "/D_HAS_EXCEPTIONS=0") + set(cxx_rtti_on "/GR") + set(cxx_rtti_off "/GR-") + else() check_cxx_compiler_flag("-fno-exceptions" COMPILER_SUPPORTS_FEXCEPTIONS) if(COMPILER_SUPPORTS_FEXCEPTIONS) @@ -139,6 +142,17 @@ else() endif() + check_cxx_compiler_flag("-fno-rtti" COMPILER_SUPPORTS_FRTTI) + if(COMPILER_SUPPORTS_FRTTI) + set(cxx_rtti_on "-frtti") + set(cxx_rtti_off "-fno-rtti") + + else() + set(cxx_rtti_on) + set(cxx_rtti_off) + + endif() + endif() set(cxx_exceptions_property "$>") @@ -146,6 +160,19 @@ add_compile_options( "$<${cxx_exceptions_property}:${cxx_exceptions_on}>" "$<$:${cxx_exceptions_off}>") +set(cxx_rtti_property "$>") +if(NOT ANDROID) + # Normally, our Debug build defaults RTTI on. This is not the case on + # Android, where we don't use it even on Debug, to save space. + + set(cxx_rtti_property "$,${cxx_rtti_property}>") +endif() +add_compile_options( + "$<${cxx_rtti_property}:${cxx_rtti_on}>" + "$<$:${cxx_rtti_off}>") +set_property(DIRECTORY "${PROJECT_SOURCE_DIR}" APPEND PROPERTY + COMPILE_DEFINITIONS "$<${cxx_rtti_property}:HAVE_RTTI>") + if(MSVC) set(msvc_bigobj_property "$>") add_compile_options("$<${msvc_bigobj_property}:/bigobj>") diff --git a/dtool/LocalSetup.cmake b/dtool/LocalSetup.cmake index a181fb12e9..eed31b0e84 100644 --- a/dtool/LocalSetup.cmake +++ b/dtool/LocalSetup.cmake @@ -132,7 +132,6 @@ check_include_file_cxx(dirent.h PHAVE_DIRENT_H) check_include_file_cxx(ucontext.h PHAVE_UCONTEXT_H) #TODO doesn't work on OSX, use sys/ucontext.h check_include_file_cxx(linux/input.h PHAVE_LINUX_INPUT_H) check_include_file_cxx(stdint.h PHAVE_STDINT_H) -check_include_file_cxx(typeinfo HAVE_RTTI) # Do we have Posix threads? #set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT}) diff --git a/dtool/dtool_config.h.in b/dtool/dtool_config.h.in index edfa19e061..159488ab9d 100644 --- a/dtool/dtool_config.h.in +++ b/dtool/dtool_config.h.in @@ -227,9 +227,6 @@ /* Do we have ? */ #cmakedefine PHAVE_STDINT_H -/* Do we have RTTI (and )? */ -#cmakedefine HAVE_RTTI - /* Do we have Posix threads? */ #cmakedefine HAVE_POSIX_THREADS