summaryrefslogtreecommitdiffstats
path: root/llvm/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/cmake')
-rw-r--r--llvm/cmake/modules/AddLLVM.cmake77
-rw-r--r--llvm/cmake/modules/HandleLLVMOptions.cmake22
-rw-r--r--llvm/cmake/modules/LLVMConfig.cmake.in1
3 files changed, 87 insertions, 13 deletions
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 06d26673e96..cc7445fb2cf 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -328,11 +328,13 @@ endfunction(set_windows_version_resource_properties)
# May specify header files for IDE generators.
# SONAME
# Should set SONAME link flags and create symlinks
+# PLUGIN_TOOL
+# The tool (i.e. cmake target) that this plugin will link against
# )
function(llvm_add_library name)
cmake_parse_arguments(ARG
"MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME"
- "OUTPUT_NAME"
+ "OUTPUT_NAME;PLUGIN_TOOL"
"ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
${ARGN})
list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
@@ -350,11 +352,15 @@ function(llvm_add_library name)
if(ARG_SHARED OR ARG_STATIC)
message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
endif()
- if(NOT LLVM_ENABLE_PLUGINS)
+ # Plugins that link against a tool are allowed even when plugins in general are not
+ if(NOT LLVM_ENABLE_PLUGINS AND NOT (ARG_PLUGIN_TOOL AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS))
message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
return()
endif()
else()
+ if(ARG_PLUGIN_TOOL)
+ message(WARNING "PLUGIN_TOOL without MODULE doesn't make sense.")
+ endif()
if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
set(ARG_SHARED TRUE)
endif()
@@ -468,7 +474,10 @@ function(llvm_add_library name)
endif()
endif()
- if (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS)
+ if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN))
+ # On DLL platforms symbols are imported from the tool by linking against it.
+ set(llvm_libs ${ARG_PLUGIN_TOOL})
+ elseif (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS)
if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
else()
@@ -673,7 +682,67 @@ macro(add_llvm_executable name)
endmacro(add_llvm_executable name)
function(export_executable_symbols target)
- if (NOT MSVC) # MSVC's linker doesn't support exporting all symbols.
+ if (LLVM_EXPORTED_SYMBOL_FILE)
+ # The symbol file should contain the symbols we want the executable to
+ # export
+ set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
+ elseif (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
+ # Extract the symbols to export from the static libraries that the
+ # executable links against.
+ set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
+ set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${target}.symbols)
+ # We need to consider not just the direct link dependencies, but also the
+ # transitive link dependencies. Do this by starting with the set of direct
+ # dependencies, then the dependencies of those dependencies, and so on.
+ get_target_property(new_libs ${target} LINK_LIBRARIES)
+ set(link_libs ${new_libs})
+ while(NOT "${new_libs}" STREQUAL "")
+ foreach(lib ${new_libs})
+ get_target_property(lib_type ${lib} TYPE)
+ if("${lib_type}" STREQUAL "STATIC_LIBRARY")
+ list(APPEND static_libs ${lib})
+ else()
+ list(APPEND other_libs ${lib})
+ endif()
+ get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
+ foreach(transitive_lib ${transitive_libs})
+ list(FIND link_libs ${transitive_lib} idx)
+ if(TARGET ${transitive_lib} AND idx EQUAL -1)
+ list(APPEND newer_libs ${transitive_lib})
+ list(APPEND link_libs ${transitive_lib})
+ endif()
+ endforeach(transitive_lib)
+ endforeach(lib)
+ set(new_libs ${newer_libs})
+ set(newer_libs "")
+ endwhile()
+ if (MSVC)
+ set(mangling microsoft)
+ else()
+ set(mangling itanium)
+ endif()
+ add_custom_command(OUTPUT ${exported_symbol_file}
+ COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file}
+ WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
+ DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py ${static_libs}
+ VERBATIM
+ COMMENT "Generating export list for ${target}")
+ add_llvm_symbol_exports( ${target} ${exported_symbol_file} )
+ # If something links against this executable then we want a
+ # transitive link against only the libraries whose symbols
+ # we aren't exporting.
+ set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${other_libs}")
+ # The default import library suffix that cmake uses for cygwin/mingw is
+ # ".dll.a", but for clang.exe that causes a collision with libclang.dll,
+ # where the import libraries of both get named libclang.dll.a. Use a suffix
+ # of ".exe.a" to avoid this.
+ if(CYGWIN OR MINGW)
+ set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".exe.a")
+ endif()
+ elseif(NOT (WIN32 OR CYGWIN))
+ # On Windows auto-exporting everything doesn't work because of the limit on
+ # the size of the exported symbol table, but on other platforms we can do
+ # it without any trouble.
set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
if (APPLE)
set_property(TARGET ${target} APPEND_STRING PROPERTY
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index ed2a6e9bb76..5422c658277 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -594,15 +594,6 @@ if(NOT CYGWIN AND NOT WIN32)
endif()
endif()
-if(CYGWIN OR MINGW)
- # Prune --out-implib from executables. It doesn't make sense even
- # with --export-all-symbols.
- string(REGEX REPLACE "-Wl,--out-implib,[^ ]+ " " "
- CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
- string(REGEX REPLACE "-Wl,--out-implib,[^ ]+ " " "
- CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
-endif()
-
if(MSVC)
# Remove flags here, for exceptions and RTTI.
# Each target property or source property should be responsible to control
@@ -640,6 +631,19 @@ elseif(LLVM_ENABLE_LTO)
CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()
+# This option makes utils/extract_symbols.py be used to determine the list of
+# symbols to export from LLVM tools. This is necessary when using MSVC if you
+# want to allow plugins, though note that the plugin has to explicitly link
+# against (exactly one) tool so we can't unilaterally turn on
+# LLVM_ENABLE_PLUGINS when it's enabled.
+option(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS "Export symbols from LLVM tools so that plugins can import them" OFF)
+if(BUILD_SHARED_LIBS AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
+ message(FATAL_ERROR "BUILD_SHARED_LIBS not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS")
+endif()
+if(LLVM_LINK_LLVM_DYLIB AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
+ message(FATAL_ERROR "LLVM_LINK_LLVM_DYLIB not compatible with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS")
+endif()
+
# Plugin support
# FIXME: Make this configurable.
if(WIN32 OR CYGWIN)
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in
index 5fec5110e2f..2034e5e5bf0 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -40,6 +40,7 @@ set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)
set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
set(LLVM_ENABLE_PLUGINS @LLVM_ENABLE_PLUGINS@)
+set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS @LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@)
set(LLVM_PLUGIN_EXT @LLVM_PLUGIN_EXT@)
set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
OpenPOWER on IntegriCloud