Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 1 | # This tool creates a shared library from the LLVM libraries. Generating this |
| 2 | # library is enabled by setting LLVM_BUILD_LLVM_DYLIB=yes on the CMake |
| 3 | # commandline. By default the shared library only exports the LLVM C API. |
| 4 | |
Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 5 | if(LLVM_LINK_LLVM_DYLIB) |
| 6 | if(DEFINED LLVM_DYLIB_COMPONENTS) |
| 7 | # To avoid inscrutable link errors, just disallow setting |
| 8 | # LLVM_DYLIB_COMPONENTS when we're intending to link tools |
| 9 | # and shared libraries with the dylib. |
| 10 | message(FATAL_ERROR "LLVM_DYLIB_COMPONENTS must not be set when LLVM_LINK_LLVM_DYLIB is ON") |
| 11 | endif() |
| 12 | if(NOT LLVM_DYLIB_EXPORT_ALL) |
| 13 | message(FATAL_ERROR "LLVM_DYLIB_EXPORT_ALL must be ON when LLVM_LINK_LLVM_DYLIB is ON") |
| 14 | endif() |
| 15 | set(LLVM_DYLIB_COMPONENTS all) |
| 16 | endif() |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 17 | |
Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 18 | # If LLVM_LINK_LLVM_DYLIB is not OFF, you can configure which libraries from |
| 19 | # LLVM you want to include in the shared library by setting |
| 20 | # LLVM_DYLIB_COMPONENTS to a semi-colon delimited list of LLVM components. |
| 21 | # All component names handled by llvm-config are valid. |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 22 | if(NOT DEFINED LLVM_DYLIB_COMPONENTS) |
NAKAMURA Takumi | c8abc4c | 2014-11-10 15:04:02 +0000 | [diff] [blame] | 23 | set(LLVM_DYLIB_COMPONENTS |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 24 | ${LLVM_TARGETS_TO_BUILD} |
| 25 | Analysis |
NAKAMURA Takumi | 4239789 | 2014-11-08 14:12:30 +0000 | [diff] [blame] | 26 | BitReader |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 27 | BitWriter |
| 28 | CodeGen |
| 29 | Core |
Keno Fischer | 7ddd501 | 2015-07-13 19:41:51 +0000 | [diff] [blame] | 30 | DebugInfoDWARF |
| 31 | DebugInfoPDB |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 32 | ExecutionEngine |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 33 | IPO |
| 34 | IRReader |
| 35 | InstCombine |
| 36 | Instrumentation |
| 37 | Interpreter |
| 38 | Linker |
NAKAMURA Takumi | 4239789 | 2014-11-08 14:12:30 +0000 | [diff] [blame] | 39 | MCDisassembler |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 40 | MCJIT |
| 41 | ObjCARCOpts |
| 42 | Object |
| 43 | ScalarOpts |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 44 | Support |
| 45 | Target |
| 46 | TransformUtils |
| 47 | Vectorize |
| 48 | native |
| 49 | ) |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 50 | endif() |
| 51 | |
| 52 | add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" ) |
| 53 | |
| 54 | set(SOURCES |
| 55 | libllvm.cpp |
| 56 | ) |
| 57 | |
Chris Bieneman | 168ddf4 | 2015-04-13 21:29:46 +0000 | [diff] [blame] | 58 | llvm_map_components_to_libnames(LIB_NAMES ${LLVM_DYLIB_COMPONENTS}) |
| 59 | |
Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 60 | if(LLVM_LINK_LLVM_DYLIB) |
| 61 | # libLLVM.so should not have any dependencies on any other LLVM |
| 62 | # shared libraries. When using the "all" pseudo-component, |
| 63 | # LLVM_AVAILABLE_LIBS is added to the dependencies, which may |
| 64 | # contain shared libraries (e.g. libLTO). |
| 65 | # |
| 66 | # Also exclude libLLVMTableGen for the following reasons: |
| 67 | # - it is only used by internal *-tblgen utilities; |
| 68 | # - it pollutes the global options space. |
| 69 | foreach(lib ${LIB_NAMES}) |
| 70 | get_target_property(t ${lib} TYPE) |
| 71 | if("${lib}" STREQUAL "LLVMTableGen") |
| 72 | elseif("x${t}" STREQUAL "xSTATIC_LIBRARY") |
| 73 | list(APPEND FILTERED_LIB_NAMES ${lib}) |
| 74 | endif() |
| 75 | endforeach() |
| 76 | set(LIB_NAMES ${FILTERED_LIB_NAMES}) |
| 77 | endif() |
| 78 | |
Chris Bieneman | 168ddf4 | 2015-04-13 21:29:46 +0000 | [diff] [blame] | 79 | if(NOT DEFINED LLVM_DYLIB_EXPORTED_SYMBOL_FILE) |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 80 | |
| 81 | if( WIN32 AND NOT CYGWIN ) |
| 82 | message(FATAL_ERROR "Auto-generation not implemented for Win32 without GNU utils. Please specify LLVM_EXPORTED_SYMBOL_FILE.") |
| 83 | endif() |
| 84 | |
| 85 | # To get the export list for a single llvm library: |
| 86 | # nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports |
| 87 | |
| 88 | set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm.exports) |
| 89 | |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 90 | if (NOT LLVM_DYLIB_EXPORT_ALL) |
| 91 | foreach (lib ${LIB_NAMES}) |
| 92 | set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
| 93 | set(LIB_NAME ${LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}) |
| 94 | set(LIB_PATH ${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 95 | set(LIB_EXPORTS_PATH ${LIB_NAME}.exports) |
| 96 | list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH}) |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 97 | |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 98 | |
Chris Bieneman | 168ddf4 | 2015-04-13 21:29:46 +0000 | [diff] [blame] | 99 | add_custom_command(OUTPUT ${LIB_EXPORTS_PATH} |
| 100 | COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_EXPORTS_PATH} |
| 101 | WORKING_DIRECTORY ${LIB_DIR} |
| 102 | DEPENDS ${lib} |
| 103 | COMMENT "Generating Export list for ${lib}..." |
| 104 | VERBATIM ) |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 105 | endforeach () |
| 106 | endif() |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 107 | |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 108 | if (LLVM_DYLIB_EXPORT_ALL) |
| 109 | add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE} |
Chris Bieneman | c82d0ca | 2015-04-16 21:58:22 +0000 | [diff] [blame] | 110 | COMMAND echo \"LLVM*\" > ${LLVM_EXPORTED_SYMBOL_FILE} && echo \"_Z*llvm*\" >> ${LLVM_EXPORTED_SYMBOL_FILE} |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 111 | WORKING_DIRECTORY ${LIB_DIR} |
| 112 | DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS} |
| 113 | COMMENT "Generating combined export list...") |
| 114 | else() |
| 115 | add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE} |
| 116 | COMMAND cat ${LLVM_DYLIB_REQUIRED_EXPORTS} > ${LLVM_EXPORTED_SYMBOL_FILE} |
| 117 | WORKING_DIRECTORY ${LIB_DIR} |
| 118 | DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS} |
| 119 | COMMENT "Generating combined export list...") |
| 120 | endif() |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 121 | |
Chris Bieneman | 11fd9d6 | 2015-02-18 18:52:11 +0000 | [diff] [blame] | 122 | add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE}) |
Chris Bieneman | 168ddf4 | 2015-04-13 21:29:46 +0000 | [diff] [blame] | 123 | else() |
| 124 | set(LLVM_EXPORTED_SYMBOL_FILE ${LLVM_DYLIB_EXPORTED_SYMBOL_FILE}) |
| 125 | add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE}) |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 126 | endif() |
| 127 | |
Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 128 | add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB ${SOURCES}) |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 129 | |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 130 | list(REMOVE_DUPLICATES LIB_NAMES) |
NAKAMURA Takumi | c8abc4c | 2014-11-10 15:04:02 +0000 | [diff] [blame] | 131 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf" |
| 132 | # GNU ld doesn't resolve symbols in the version script. |
NAKAMURA Takumi | c8abc4c | 2014-11-10 15:04:02 +0000 | [diff] [blame] | 133 | set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive) |
Chris Bieneman | 3ee8196 | 2015-04-16 16:56:22 +0000 | [diff] [blame] | 134 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 135 | set(LIB_NAMES -Wl,-all_load ${LIB_NAMES}) |
NAKAMURA Takumi | c8abc4c | 2014-11-10 15:04:02 +0000 | [diff] [blame] | 136 | endif() |
| 137 | |
Chris Bieneman | 6a1b54a | 2015-03-23 20:03:57 +0000 | [diff] [blame] | 138 | target_link_libraries(LLVM PRIVATE ${LIB_NAMES}) |
NAKAMURA Takumi | c8abc4c | 2014-11-10 15:04:02 +0000 | [diff] [blame] | 139 | |
Chris Bieneman | 11fd9d6 | 2015-02-18 18:52:11 +0000 | [diff] [blame] | 140 | add_dependencies(LLVM libLLVMExports) |
Chris Bieneman | adffd01 | 2014-10-23 17:22:14 +0000 | [diff] [blame] | 141 | |
| 142 | if (APPLE) |
| 143 | set_property(TARGET LLVM APPEND_STRING PROPERTY |
| 144 | LINK_FLAGS |
| 145 | " -compatibility_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") |
| 146 | endif() |
| 147 | |