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