diff options
Diffstat (limited to 'cmake/modules')
-rw-r--r-- | cmake/modules/AddLLVM.cmake | 91 | ||||
-rw-r--r-- | cmake/modules/HandleLLVMOptions.cmake | 10 | ||||
-rw-r--r-- | cmake/modules/LLVMConfig.cmake.in | 2 | ||||
-rw-r--r-- | cmake/modules/Makefile | 7 |
4 files changed, 81 insertions, 29 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 50cee30..b3fccb0 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -158,33 +158,38 @@ if(NOT WIN32 AND NOT APPLE) endif() 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(LLVM_LINKER_IS_GOLD) - # With gold gc-sections is always safe. - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--gc-sections") - # Note that there is a bug with -Wl,--icf=safe so it is not safe - # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704. - endif() + # Don't use linker optimizations in debug builds since it slows down the + # linker in a context where the optimizations are not important. + if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - if(NOT LLVM_NO_DEAD_STRIP) - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # ld64's implementation of -dead_strip breaks tools that use plugins. + # 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,-dead_strip") - elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD) - # 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. + LINK_FLAGS " -Wl,-O3") + endif() + + if(LLVM_LINKER_IS_GOLD) + # With gold gc-sections is always safe. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--gc-sections") + # Note that there is a bug with -Wl,--icf=safe so it is not safe + # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704. + 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 AND NOT LLVM_LINKER_IS_GOLD) + # 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() endif() endfunction(add_link_opts) @@ -402,6 +407,11 @@ function(llvm_add_library name) endfunction() macro(add_llvm_library name) + cmake_parse_arguments(ARG + "SHARED" + "" + "" + ${ARGN}) if( BUILD_SHARED_LIBS ) llvm_add_library(${name} SHARED ${ARGN}) else() @@ -413,12 +423,20 @@ macro(add_llvm_library name) set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) else() if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO") + if(ARG_SHARED OR BUILD_SHARED_LIBS) + if(WIN32 OR CYGWIN) + set(install_type RUNTIME) + else() + set(install_type LIBRARY) + endif() + else() + set(install_type ARCHIVE) + endif() + install(TARGETS ${name} - EXPORT LLVMExports - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} - COMPONENT ${name}) + EXPORT LLVMExports + ${install_type} DESTINATION lib${LLVM_LIBDIR_SUFFIX} + COMPONENT ${name}) if (NOT CMAKE_CONFIGURATION_TYPES) add_custom_target(install-${name} @@ -547,6 +565,18 @@ endmacro(add_llvm_example name) macro(add_llvm_utility name) add_llvm_executable(${name} ${ARGN}) set_target_properties(${name} PROPERTIES FOLDER "Utils") + if( LLVM_INSTALL_UTILS ) + install (TARGETS ${name} + RUNTIME DESTINATION bin + COMPONENT ${name}) + if (NOT CMAKE_CONFIGURATION_TYPES) + add_custom_target(install-${name} + DEPENDS ${name} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=${name} + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + endif() + endif() endmacro(add_llvm_utility name) @@ -791,8 +821,13 @@ function(add_lit_testsuites project directory) if (NOT CMAKE_CONFIGURATION_TYPES) parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) file(GLOB_RECURSE litCfg ${directory}/lit*.cfg) + set(lit_suites) foreach(f ${litCfg}) get_filename_component(dir ${f} DIRECTORY) + set(lit_suites ${lit_suites} ${dir}) + endforeach() + list(REMOVE_DUPLICATES lit_suites) + foreach(dir ${lit_suites}) string(REPLACE ${directory} "" name_slash ${dir}) if (name_slash) string(REPLACE "/" "-" name_slash ${name_slash}) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 67f86a6..27147dc 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -315,6 +315,13 @@ if( MSVC ) # Enable warnings if (LLVM_ENABLE_WARNINGS) append("/W4" msvc_warning_flags) + # CMake appends /W3 by default, and having /W3 followed by /W4 will result in + # cl : Command line warning D9025 : overriding '/W3' with '/W4'. Since this is + # a command line warning and not a compiler warning, it cannot be suppressed except + # by fixing the command line. + string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + if (LLVM_ENABLE_PEDANTIC) # No MSVC equivalent available endif (LLVM_ENABLE_PEDANTIC) @@ -486,7 +493,8 @@ endif() # But MinSizeRel seems to add that automatically, so maybe disable these # flags instead if LLVM_NO_DEAD_STRIP is set. if(NOT CYGWIN AND NOT WIN32) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND + NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS) if (C_SUPPORTS_FNO_FUNCTION_SECTIONS) # Don't add -ffunction-section if it can be disabled with -fno-function-sections. diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in index 9a9cd85..5b7789d 100644 --- a/cmake/modules/LLVMConfig.cmake.in +++ b/cmake/modules/LLVMConfig.cmake.in @@ -21,6 +21,8 @@ set(LLVM_TARGETS_WITH_JIT @LLVM_TARGETS_WITH_JIT@) set(TARGET_TRIPLE "@TARGET_TRIPLE@") +set(LLVM_ABI_BREAKING_CHECKS @LLVM_ABI_BREAKING_CHECKS@) + set(LLVM_ENABLE_ASSERTIONS @LLVM_ENABLE_ASSERTIONS@) set(LLVM_ENABLE_EH @LLVM_ENABLE_EH@) diff --git a/cmake/modules/Makefile b/cmake/modules/Makefile index e38f5a6..97ee7d3 100644 --- a/cmake/modules/Makefile +++ b/cmake/modules/Makefile @@ -21,6 +21,12 @@ else LLVM_ENABLE_ASSERTIONS := 1 endif +ifeq ($(ENABLE_ABI_BREAKING_CHECKS),1) + LLVM_ABI_BREAKING_CHECKS := FORCE_ON +else + LLVM_ABI_BREAKING_CHECKS := FORCE_OFF +endif + ifeq ($(REQUIRES_EH),1) LLVM_ENABLE_EH := 1 else @@ -63,6 +69,7 @@ $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in Makefile $(LLVMBuildCMakeF -e 's/@LLVM_TARGETS_TO_BUILD@/'"$(TARGETS_TO_BUILD)"'/' \ -e 's/@LLVM_TARGETS_WITH_JIT@/'"$(TARGETS_WITH_JIT)"'/' \ -e 's/@TARGET_TRIPLE@/'"$(TARGET_TRIPLE)"'/' \ + -e 's/@LLVM_ABI_BREAKING_CHECKS@/'"$(LLVM_ABI_BREAKING_CHECKS)"'/' \ -e 's/@LLVM_ENABLE_ASSERTIONS@/'"$(LLVM_ENABLE_ASSERTIONS)"'/' \ -e 's/@LLVM_ENABLE_EH@/'"$(LLVM_ENABLE_EH)"'/' \ -e 's/@LLVM_ENABLE_RTTI@/'"$(LLVM_ENABLE_RTTI)"'/' \ |