Browse Source

CMake: Use -fno-rtti on most build configurations

Sam Edwards 6 years ago
parent
commit
8429f50d3a
3 changed files with 27 additions and 4 deletions
  1. 27 0
      dtool/CompilerFlags.cmake
  2. 0 1
      dtool/LocalSetup.cmake
  3. 0 3
      dtool/dtool_config.h.in

+ 27 - 0
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 "$<BOOL:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>")
@@ -146,6 +160,19 @@ add_compile_options(
   "$<${cxx_exceptions_property}:${cxx_exceptions_on}>"
   "$<$<NOT:${cxx_exceptions_property}>:${cxx_exceptions_off}>")
 
+set(cxx_rtti_property "$<BOOL:$<TARGET_PROPERTY:CXX_RTTI>>")
+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 "$<OR:$<CONFIG:Debug>,${cxx_rtti_property}>")
+endif()
+add_compile_options(
+  "$<${cxx_rtti_property}:${cxx_rtti_on}>"
+  "$<$<NOT:${cxx_rtti_property}>:${cxx_rtti_off}>")
+set_property(DIRECTORY "${PROJECT_SOURCE_DIR}" APPEND PROPERTY
+  COMPILE_DEFINITIONS "$<${cxx_rtti_property}:HAVE_RTTI>")
+
 if(MSVC)
   set(msvc_bigobj_property "$<BOOL:$<TARGET_PROPERTY:MSVC_BIGOBJ>>")
   add_compile_options("$<${msvc_bigobj_property}:/bigobj>")

+ 0 - 1
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})

+ 0 - 3
dtool/dtool_config.h.in

@@ -227,9 +227,6 @@
 /* Do we have <stdint.h>? */
 #cmakedefine PHAVE_STDINT_H
 
-/* Do we have RTTI (and <typeinfo>)? */
-#cmakedefine HAVE_RTTI
-
 /* Do we have Posix threads? */
 #cmakedefine HAVE_POSIX_THREADS