[CMake] Enhance llvm_update_compile_flags(name sources) to handle LLVM_REQUIRES_EH and LLVM_REQUIRES_RTTI.

LLVM_REQUIRES_EH implies LLVM_REQUIRES_RTTI. It is as same behavior as Makefile.rule's.
llvm/examples/ExceptionDemo is affected. (It was built with -fno-rtti.)

For MSVC, Remove flags like "/EHsc /GR" in HandleLLVMOptions, or CL.EXE complains with flags like "/GR /GR-".

llvm_update_compile_flags() updates source file property if the target contains *.c.
COMPILE_FLAGS in target properties affects both C++ and C!

LLVM_NO_RTTI is deprecated. It was introduced by me and was my mistake.

llvm-svn: 200301
This commit is contained in:
NAKAMURA Takumi 2014-01-28 09:44:06 +00:00
parent 73fb9bab5e
commit 806bce066e
2 changed files with 43 additions and 8 deletions

View File

@ -3,20 +3,45 @@ include(LLVMProcessSources)
include(LLVM-Config)
function(llvm_update_compile_flags name)
get_property(target_compile_flags TARGET ${name} PROPERTY COMPILE_FLAGS)
if(NOT "${LLVM_COMPILE_FLAGS}" STREQUAL "")
set(target_compile_flags "${target_compile_flags} ${LLVM_COMPILE_FLAGS}")
set(ALL_SOURCES ${ARGN})
if("${ALL_SOURCES}" MATCHES "\\.c(;|$)")
set(update_src_props ON)
endif()
if(LLVM_NO_RTTI)
if(LLVM_REQUIRES_EH)
set(LLVM_REQUIRES_RTTI ON)
else()
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
set(target_compile_flags "${target_compile_flags} -fno-exceptions")
elseif(MSVC)
list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
set(target_compile_flags "${target_compile_flags} /EHs-c-")
endif()
endif()
if(NOT LLVM_REQUIRES_RTTI)
list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
set(target_compile_flags "${target_compile_flags} -fno-rtti")
elseif (MSVC)
llvm_replace_compiler_option(target_compile_flags "/GR" "/GR-")
set(target_compile_flags "${target_compile_flags} /GR-")
endif ()
endif()
set_property(TARGET ${name} PROPERTY COMPILE_FLAGS "${target_compile_flags}")
if(update_src_props)
foreach(fn ${ALL_SOURCES})
get_filename_component(suf ${fn} EXT)
if("${suf}" STREQUAL ".cpp")
set_property(SOURCE ${fn} APPEND_STRING PROPERTY
COMPILE_FLAGS "${target_compile_flags}")
endif()
endforeach()
else()
# Update target props, since all sources are C++.
set_property(TARGET ${name} APPEND_STRING PROPERTY
COMPILE_FLAGS "${target_compile_flags}")
endif()
set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
endfunction()
@ -137,6 +162,7 @@ macro(add_llvm_library name)
add_library( ${name} ${ALL_FILES} )
set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
llvm_update_compile_flags(${name} ${ALL_FILES})
add_dead_strip( ${name} )
if( LLVM_COMMON_DEPENDS )
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
@ -196,6 +222,7 @@ ${name} ignored.")
add_library( ${name} ${libkind} ${ALL_FILES} )
set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
set_target_properties( ${name} PROPERTIES PREFIX "" )
llvm_update_compile_flags(${name} ${ALL_FILES})
add_dead_strip( ${name} )
if (LLVM_EXPORTED_SYMBOL_FILE)
@ -237,6 +264,7 @@ macro(add_llvm_executable name)
else()
add_executable(${name} ${ALL_FILES})
endif()
llvm_update_compile_flags(${name} ${ALL_FILES})
add_dead_strip( ${name} )
if (LLVM_EXPORTED_SYMBOL_FILE)
@ -374,7 +402,7 @@ function(add_unittest test_suite test_name)
set(LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
endif ()
set(LLVM_NO_RTTI ON)
set(LLVM_REQUIRES_RTTI OFF)
add_llvm_executable(${test_name} ${ARGN})
set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
@ -390,7 +418,6 @@ function(add_unittest test_suite test_name)
if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
endif ()
llvm_update_compile_flags(${test_name})
endfunction()
# This function provides an automatic way to 'configure'-like generate a file

View File

@ -359,3 +359,11 @@ if(NOT CYGWIN AND NOT WIN32)
append("-ffunction-sections -fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif()
endif()
if(MSVC)
# Remove flags here, for exceptions and RTTI.
# Each target property of source proerty should be responsible to control them.
# CL.EXE complains to override flags like "/GR /GR-".
string(REGEX REPLACE "(^| ) */EH[-cs]+ *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "(^| ) */GR-? *( |$)" "\\1 \\2" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()