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 | |
| 5 | |
| 6 | # You can configure which libraries from LLVM you want to include in the shared |
| 7 | # library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited list of |
| 8 | # LLVM components. All compoenent names handled by llvm-config are valid. |
| 9 | |
| 10 | if(NOT DEFINED LLVM_DYLIB_COMPONENTS) |
| 11 | set(LLVM_LINK_COMPONENTS |
| 12 | ${LLVM_TARGETS_TO_BUILD} |
| 13 | Analysis |
| 14 | AsmPrinter |
| 15 | BitWriter |
| 16 | CodeGen |
| 17 | Core |
| 18 | ExecutionEngine |
| 19 | IPA |
| 20 | IPO |
| 21 | IRReader |
| 22 | InstCombine |
| 23 | Instrumentation |
| 24 | Interpreter |
| 25 | Linker |
| 26 | MC |
| 27 | MCJIT |
| 28 | ObjCARCOpts |
| 29 | Object |
| 30 | ScalarOpts |
| 31 | SelectionDAG |
| 32 | Support |
| 33 | Target |
| 34 | TransformUtils |
| 35 | Vectorize |
| 36 | native |
| 37 | ) |
| 38 | else() |
| 39 | set(LLVM_LINK_COMPONENTS ${LLVM_DYLIB_COMPONENTS}) |
| 40 | endif() |
| 41 | |
| 42 | add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" ) |
| 43 | |
| 44 | set(SOURCES |
| 45 | libllvm.cpp |
| 46 | ) |
| 47 | |
| 48 | if(NOT DEFINED LLVM_EXPORTED_SYMBOL_FILE) |
| 49 | |
| 50 | if( WIN32 AND NOT CYGWIN ) |
| 51 | message(FATAL_ERROR "Auto-generation not implemented for Win32 without GNU utils. Please specify LLVM_EXPORTED_SYMBOL_FILE.") |
| 52 | endif() |
| 53 | |
| 54 | # To get the export list for a single llvm library: |
| 55 | # nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports |
| 56 | |
| 57 | set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm.exports) |
| 58 | |
| 59 | llvm_map_components_to_libnames(LIB_NAMES ${LLVM_LINK_COMPONENTS}) |
| 60 | |
| 61 | foreach (lib ${LIB_NAMES}) |
| 62 | |
| 63 | set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib) |
| 64 | set(LIB_NAME ${LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}) |
| 65 | set(LIB_PATH ${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 66 | set(LIB_EXPORTS_PATH ${LIB_NAME}.exports) |
| 67 | |
| 68 | list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH}) |
| 69 | |
| 70 | add_custom_command(OUTPUT ${LIB_EXPORTS_PATH} |
| 71 | COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_EXPORTS_PATH} |
| 72 | WORKING_DIRECTORY ${LIB_DIR} |
| 73 | DEPENDS ${lib} |
| 74 | COMMENT "Generating Export list for ${lib}..." |
| 75 | VERBATIM ) |
| 76 | endforeach () |
| 77 | |
| 78 | add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE} |
| 79 | COMMAND cat ${LLVM_DYLIB_REQUIRED_EXPORTS} > ${LLVM_EXPORTED_SYMBOL_FILE} |
| 80 | WORKING_DIRECTORY ${LIB_DIR} |
| 81 | DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS} |
| 82 | COMMENT "Generating combined export list...") |
| 83 | |
| 84 | endif() |
| 85 | |
| 86 | add_llvm_library(LLVM SHARED ${SOURCES}) |
| 87 | |
| 88 | add_dependencies(LLVM ${LLVM_EXPORTED_SYMBOL_FILE}) |
| 89 | |
| 90 | if (APPLE) |
| 91 | set_property(TARGET LLVM APPEND_STRING PROPERTY |
| 92 | LINK_FLAGS |
| 93 | " -compatibility_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") |
| 94 | endif() |
| 95 | |