X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=cmake%2Fmodules%2FAddLLVM.cmake;h=bc26f0671668b889f031cd5988a919d65da7a0d4;hb=5b9a46b789b6077dcb8f2e2c39c0765d28924bfc;hp=81efae62e79ec3569f096184996dde3daadd47c4;hpb=afa0ba139fe2703da3d0f9fb221cd5b48e5b1cf6;p=oota-llvm.git diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 81efae62e79..bc26f067166 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -8,8 +8,13 @@ function(llvm_update_compile_flags name) set(update_src_props ON) endif() - if(LLVM_REQUIRES_EH) - set(LLVM_REQUIRES_RTTI ON) + # LLVM_REQUIRES_EH is an internal flag that individual + # targets can use to force EH + if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH) + if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) + message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}") + set(LLVM_REQUIRES_RTTI ON) + endif() else() if(LLVM_COMPILER_IS_GCC_COMPATIBLE) list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions") @@ -19,7 +24,9 @@ function(llvm_update_compile_flags name) endif() endif() - if(NOT LLVM_REQUIRES_RTTI) + # LLVM_REQUIRES_RTTI is an internal flag that individual + # targets can use to force RTTI + if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0) if (LLVM_COMPILER_IS_GCC_COMPATIBLE) list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti") @@ -78,27 +85,29 @@ function(add_llvm_symbol_exports target_name export_file) else() set(native_export_file "${target_name}.def") - set(CAT "type") - if(CYGWIN) - set(CAT "cat") + set(CAT "cat") + set(export_file_nativeslashes ${export_file}) + if(WIN32 AND NOT CYGWIN) + set(CAT "type") + # Convert ${export_file} to native format (backslashes) for "type" + # Does not use file(TO_NATIVE_PATH) as it doesn't create a native + # path but a build-system specific format (see CMake bug + # http://public.kitware.com/Bug/print_bug_page.php?bug_id=5939 ) + string(REPLACE / \\ export_file_nativeslashes ${export_file}) endif() - # Using ${export_file} in add_custom_command directly confuses cmd.exe. - file(TO_NATIVE_PATH ${export_file} export_file_backslashes) - add_custom_command(OUTPUT ${native_export_file} COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > ${native_export_file} - COMMAND ${CAT} ${export_file_backslashes} >> ${native_export_file} + COMMAND ${CAT} ${export_file_nativeslashes} >> ${native_export_file} DEPENDS ${export_file} VERBATIM COMMENT "Creating export file for ${target_name}") - if(CYGWIN OR MINGW) - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") - else() - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " /DEF:${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") + set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") + if(MSVC) + set(export_file_linker_flag "/DEF:${export_file_linker_flag}") endif() + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " ${export_file_linker_flag}") endif() add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) @@ -133,18 +142,29 @@ function(add_llvm_symbol_exports target_name export_file) set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) endfunction(add_llvm_symbol_exports) -function(add_dead_strip target_name) +function(add_link_opts target_name) + # Pass -O3 to the linker. This enabled different optimizations on different + # linkers. + if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32)) + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-O3") + endif() + if(NOT LLVM_NO_DEAD_STRIP) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + # ld64's implementation of -dead_strip breaks tools that use plugins. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip") elseif(NOT WIN32) # Object files are compiled with -ffunction-data-sections. + # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks + # tools that use plugins. Always pass --gc-sections once we require + # a newer linker. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections") endif() endif() -endfunction(add_dead_strip) +endfunction(add_link_opts) # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, @@ -274,7 +294,7 @@ function(llvm_add_library name) endif() set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) llvm_update_compile_flags(${name}) - add_dead_strip( ${name} ) + add_link_opts( ${name} ) if(ARG_OUTPUT_NAME) set_target_properties(${name} PROPERTIES @@ -303,6 +323,12 @@ function(llvm_add_library name) endif() if(ARG_MODULE OR ARG_SHARED) + # Do not add -Dname_EXPORTS to the command-line when building files in this + # target. Doing so is actively harmful for the modules build because it + # creates extra module variants, and not useful because we don't use these + # macros. + set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) + if (LLVM_EXPORTED_SYMBOL_FILE) add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) endif() @@ -333,22 +359,8 @@ function(llvm_add_library name) ${lib_deps} ${llvm_libs} ) - elseif((CYGWIN OR WIN32) AND ARG_SHARED) - # Win32's import library may be unaware of its dependent libs. - target_link_libraries(${name} PRIVATE - ${ARG_LINK_LIBS} - ${lib_deps} - ${llvm_libs} - ) - elseif(ARG_SHARED AND BUILD_SHARED_LIBS) - # FIXME: It may be PRIVATE since SO knows its dependent libs. - target_link_libraries(${name} PUBLIC - ${ARG_LINK_LIBS} - ${lib_deps} - ${llvm_libs} - ) else() - # MODULE|SHARED + # We can use PRIVATE since SO knows its dependent libs. target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS} ${lib_deps} @@ -426,7 +438,13 @@ macro(add_llvm_executable name) add_executable(${name} ${ALL_FILES}) endif() llvm_update_compile_flags(${name}) - add_dead_strip( ${name} ) + add_link_opts( ${name} ) + + # Do not add -Dname_EXPORTS to the command-line when building files in this + # target. Doing so is actively harmful for the modules build because it + # creates extra module variants, and not useful because we don't use these + # macros. + set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) if (LLVM_EXPORTED_SYMBOL_FILE) add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) @@ -632,6 +650,10 @@ function(configure_lit_site_cfg input output) set(HOST_OS ${CMAKE_SYSTEM_NAME}) set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR}) + set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") + set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") + set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}") + configure_file(${input} ${output} @ONLY) endfunction() @@ -657,6 +679,7 @@ function(add_lit_target target comment) add_custom_target(${target} COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS} COMMENT "${comment}" + ${cmake_3_2_USES_TERMINAL} ) add_dependencies(${target} ${ARG_DEPENDS}) else()