diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-12-28 23:31:44 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-12-28 23:31:44 +0000 |
commit | b6fe25c47661a287224d09165b68ce76084294ca (patch) | |
tree | b8f9b8e17241ebe4ea979afeda7ce16dea31afc3 /cmake/modules/AddLLVM.cmake | |
parent | 621bd8d76a698899959190849a1b21d019f56e52 (diff) | |
download | llvm-b6fe25c47661a287224d09165b68ce76084294ca.tar.gz llvm-b6fe25c47661a287224d09165b68ce76084294ca.tar.bz2 llvm-b6fe25c47661a287224d09165b68ce76084294ca.tar.xz |
EXPORTED_SYMBOL_FILE support for cmake
The cmake build didn't support EXPORTED_SYMBOL_FILE. Instead, it had a
Windows-only implementation in tools/lto/CMakeLists.txt, a linux-only
implementation in tools/gold/CMakeLists.txt, and a darwin-only implementation
in tools/clang/tools/libclang/CMakeLists.txt.
This attempts to consolidate these one-offs into a single place. Clients can now
just set LLVM_EXPORTED_SYMBOL_FILE and things (hopefully) Just Work, like in
the make build.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198136 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/modules/AddLLVM.cmake')
-rw-r--r-- | cmake/modules/AddLLVM.cmake | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 2daa622ded..fdd79a0abb 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -2,6 +2,72 @@ include(LLVMParseArguments) include(LLVMProcessSources) include(LLVM-Config) +function(add_llvm_symbol_exports target_name export_file) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(native_export_file "symbol.exports") + add_custom_command(OUTPUT symbol.exports + COMMAND sed -e "s/^/_/" < ${export_file} > symbol.exports + DEPENDS ${export_file} + VERBATIM + COMMENT "Creating export file for ${target_name}") + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports") + elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) + # Gold and BFD ld require a version script rather than a plain list. + set(native_export_file "symbol.exports") + # FIXME: Don't write the "local:" line on OpenBSD. + add_custom_command(OUTPUT symbol.exports + COMMAND echo "{" > symbol.exports + COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> symbol.exports || : + COMMAND sed -e "s/$$/;/" -e "s/^/ /" < ${export_file} >> symbol.exports + COMMAND echo " local: *;" >> symbol.exports + COMMAND echo "};" >> symbol.exports + DEPENDS ${export_file} + VERBATIM + COMMENT "Creating export file for ${target_name}") + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports") + else() + set(native_export_file "symbol.def") + + set(CAT "type") + if(CYGWIN) + set(CAT "cat") + endif() + + add_custom_command(OUTPUT symbol.def + COMMAND cmake -E echo "EXPORTS" > symbol.def + COMMAND ${CAT} < ${export_file} >> symbol.def + DEPENDS ${export_file} + VERBATIM + COMMENT "Creating export file for ${target_name}") + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " ${CMAKE_CURRENT_BINARY_DIR}/symbol.def") + endif() + + add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) + + get_property(srcs TARGET ${target_name} PROPERTY SOURCES) + foreach(src ${srcs}) + get_filename_component(extension ${src} EXT) + if(extension STREQUAL ".cpp") + set(first_source_file ${src}) + break() + endif() + endforeach() + + # Force re-linking when the exports file changes. Actually, it + # forces recompilation of the source file. The LINK_DEPENDS target + # property only works for makefile-based generators. + set_property(SOURCE ${first_source_file} APPEND PROPERTY + OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}) + + set_property(DIRECTORY APPEND + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file}) + + add_dependencies(${target_name} ${target_name}_exports) +endfunction(add_llvm_symbol_exports) + macro(add_llvm_library name) llvm_process_sources( ALL_FILES ${ARGN} ) add_library( ${name} ${ALL_FILES} ) @@ -19,6 +85,10 @@ macro(add_llvm_library name) endif () endif() + if (LLVM_EXPORTED_SYMBOL_FILE) + add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) + endif() + # Ensure that the system libraries always comes last on the # list. Without this, linking the unit tests on MinGW fails. link_system_libs( ${name} ) @@ -57,6 +127,10 @@ ${name} ignored.") set(libkind SHARED) endif() + if (LLVM_EXPORTED_SYMBOL_FILE) + add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) + endif(LLVM_EXPORTED_SYMBOL_FILE) + add_library( ${name} ${libkind} ${ALL_FILES} ) set_target_properties( ${name} PROPERTIES PREFIX "" ) @@ -91,6 +165,11 @@ macro(add_llvm_executable name) else() add_executable(${name} ${ALL_FILES}) endif() + + if (LLVM_EXPORTED_SYMBOL_FILE) + add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) + endif(LLVM_EXPORTED_SYMBOL_FILE) + set(EXCLUDE_FROM_ALL OFF) llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) if( LLVM_COMMON_DEPENDS ) |