CMake: Use -fno-rtti on most build configurations

This commit is contained in:
Sam Edwards 2019-09-19 04:44:46 -06:00
parent 9645aaee07
commit 8429f50d3a
3 changed files with 27 additions and 4 deletions

View File

@ -127,6 +127,9 @@ if(MSVC)
set(cxx_exceptions_on "/EHsc") set(cxx_exceptions_on "/EHsc")
set(cxx_exceptions_off "/D_HAS_EXCEPTIONS=0") set(cxx_exceptions_off "/D_HAS_EXCEPTIONS=0")
set(cxx_rtti_on "/GR")
set(cxx_rtti_off "/GR-")
else() else()
check_cxx_compiler_flag("-fno-exceptions" COMPILER_SUPPORTS_FEXCEPTIONS) check_cxx_compiler_flag("-fno-exceptions" COMPILER_SUPPORTS_FEXCEPTIONS)
if(COMPILER_SUPPORTS_FEXCEPTIONS) if(COMPILER_SUPPORTS_FEXCEPTIONS)
@ -139,6 +142,17 @@ else()
endif() 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() endif()
set(cxx_exceptions_property "$<BOOL:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>") set(cxx_exceptions_property "$<BOOL:$<TARGET_PROPERTY:CXX_EXCEPTIONS>>")
@ -146,6 +160,19 @@ add_compile_options(
"$<${cxx_exceptions_property}:${cxx_exceptions_on}>" "$<${cxx_exceptions_property}:${cxx_exceptions_on}>"
"$<$<NOT:${cxx_exceptions_property}>:${cxx_exceptions_off}>") "$<$<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) if(MSVC)
set(msvc_bigobj_property "$<BOOL:$<TARGET_PROPERTY:MSVC_BIGOBJ>>") set(msvc_bigobj_property "$<BOOL:$<TARGET_PROPERTY:MSVC_BIGOBJ>>")
add_compile_options("$<${msvc_bigobj_property}:/bigobj>") add_compile_options("$<${msvc_bigobj_property}:/bigobj>")

View File

@ -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(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(linux/input.h PHAVE_LINUX_INPUT_H)
check_include_file_cxx(stdint.h PHAVE_STDINT_H) check_include_file_cxx(stdint.h PHAVE_STDINT_H)
check_include_file_cxx(typeinfo HAVE_RTTI)
# Do we have Posix threads? # Do we have Posix threads?
#set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT}) #set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT})

View File

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