summaryrefslogtreecommitdiff
path: root/cmake/modules/AddLLVM.cmake
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2014-01-28 09:44:06 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2014-01-28 09:44:06 +0000
commit3303370cd028ecb3c57820e2e994f3d3099c0607 (patch)
tree3b4b5ae443ee5efa80d443c971725dee5fc3ceae /cmake/modules/AddLLVM.cmake
parent16268c0de7542009429f619fb5143937450d9c51 (diff)
downloadllvm-3303370cd028ecb3c57820e2e994f3d3099c0607.tar.gz
llvm-3303370cd028ecb3c57820e2e994f3d3099c0607.tar.bz2
llvm-3303370cd028ecb3c57820e2e994f3d3099c0607.tar.xz
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200301 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/modules/AddLLVM.cmake')
-rw-r--r--cmake/modules/AddLLVM.cmake43
1 files changed, 35 insertions, 8 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index 5bc3c22cf8..6996c388b3 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -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