83
|
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 add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" )
|
|
6
|
|
7 set(SOURCES
|
|
8 libllvm.cpp
|
|
9 )
|
|
10
|
95
|
11 llvm_map_components_to_libnames(LIB_NAMES ${LLVM_DYLIB_COMPONENTS})
|
83
|
12
|
95
|
13 if(LLVM_LINK_LLVM_DYLIB)
|
100
|
14 if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
|
|
15 message(WARNING "Using LLVM_LINK_LLVM_DYLIB with LLVM_DYLIB_EXPORTED_SYMBOL_FILE may not work. Use at your own risk.")
|
83
|
16 endif()
|
|
17
|
95
|
18 # libLLVM.so should not have any dependencies on any other LLVM
|
|
19 # shared libraries. When using the "all" pseudo-component,
|
|
20 # LLVM_AVAILABLE_LIBS is added to the dependencies, which may
|
|
21 # contain shared libraries (e.g. libLTO).
|
|
22 #
|
|
23 # Also exclude libLLVMTableGen for the following reasons:
|
|
24 # - it is only used by internal *-tblgen utilities;
|
|
25 # - it pollutes the global options space.
|
|
26 foreach(lib ${LIB_NAMES})
|
|
27 get_target_property(t ${lib} TYPE)
|
|
28 if("${lib}" STREQUAL "LLVMTableGen")
|
|
29 elseif("x${t}" STREQUAL "xSTATIC_LIBRARY")
|
|
30 list(APPEND FILTERED_LIB_NAMES ${lib})
|
|
31 endif()
|
|
32 endforeach()
|
|
33 set(LIB_NAMES ${FILTERED_LIB_NAMES})
|
|
34 endif()
|
|
35
|
100
|
36 if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
|
95
|
37 set(LLVM_EXPORTED_SYMBOL_FILE ${LLVM_DYLIB_EXPORTED_SYMBOL_FILE})
|
|
38 add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
83
|
39 endif()
|
|
40
|
100
|
41 add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
|
83
|
42
|
95
|
43 list(REMOVE_DUPLICATES LIB_NAMES)
|
83
|
44 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf"
|
|
45 # GNU ld doesn't resolve symbols in the version script.
|
|
46 set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
|
95
|
47 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
|
48 set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
|
83
|
49 endif()
|
|
50
|
95
|
51 target_link_libraries(LLVM PRIVATE ${LIB_NAMES})
|
83
|
52
|
100
|
53 if (APPLE)
|
|
54 set_property(TARGET LLVM APPEND_STRING PROPERTY
|
|
55 LINK_FLAGS
|
|
56 " -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
|
|
57 endif()
|
|
58
|
95
|
59 if(TARGET libLLVMExports)
|
|
60 add_dependencies(LLVM libLLVMExports)
|
|
61 endif()
|
83
|
62
|
100
|
63 if(LLVM_BUILD_LLVM_C_DYLIB)
|
|
64 # To get the export list for a single llvm library:
|
|
65 # nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports
|
|
66
|
|
67 if(NOT APPLE)
|
|
68 message(FATAL_ERROR "Generating libLLVM-c is only supported on Darwin")
|
|
69 endif()
|
|
70
|
|
71 set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm-c.exports)
|
|
72
|
|
73 set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
74 set(LIB_NAME ${LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}LLVM)
|
|
75 set(LIB_PATH ${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
76 set(LIB_EXPORTS_PATH ${LIB_NAME}.exports)
|
|
77 list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH})
|
|
78
|
|
79 add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
|
|
80 COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LLVM_EXPORTED_SYMBOL_FILE}
|
|
81 WORKING_DIRECTORY ${LIB_DIR}
|
|
82 DEPENDS LLVM
|
|
83 COMMENT "Generating Export list for LLVM..."
|
|
84 VERBATIM )
|
|
85
|
|
86 add_custom_target(libLLVMCExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
|
87
|
|
88 add_llvm_library(LLVM-C SHARED ${SOURCES})
|
|
89
|
|
90 target_link_libraries(LLVM-C PUBLIC LLVM)
|
|
91 add_dependencies(LLVM-C libLLVMCExports)
|
|
92
|
|
93 set_property(TARGET LLVM-C APPEND_STRING PROPERTY
|
83
|
94 LINK_FLAGS
|
100
|
95 " -compatibility_version 1 -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH} -Wl,-reexport_library ${LIB_PATH}")
|
83
|
96 endif()
|
|
97
|