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)
|
|
14 if(NOT LLVM_DYLIB_EXPORT_ALL)
|
|
15 message(FATAL_ERROR "LLVM_DYLIB_EXPORT_ALL must be ON when LLVM_LINK_LLVM_DYLIB is ON")
|
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
|
|
36 if(NOT DEFINED LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
|
83
|
37 # To get the export list for a single llvm library:
|
|
38 # nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports
|
|
39
|
95
|
40 if (NOT LLVM_DYLIB_EXPORT_ALL)
|
|
41 if( WIN32 AND NOT CYGWIN )
|
|
42 message(FATAL_ERROR "Auto-generation not implemented for Win32 without GNU utils. Please specify LLVM_EXPORTED_SYMBOL_FILE.")
|
|
43 endif()
|
83
|
44
|
95
|
45 set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm.exports)
|
83
|
46
|
95
|
47 foreach (lib ${LIB_NAMES})
|
|
48 set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
49 set(LIB_NAME ${LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib})
|
|
50 set(LIB_PATH ${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
51 set(LIB_EXPORTS_PATH ${LIB_NAME}.exports)
|
|
52 list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH})
|
83
|
53
|
95
|
54
|
|
55 add_custom_command(OUTPUT ${LIB_EXPORTS_PATH}
|
|
56 COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_EXPORTS_PATH}
|
|
57 WORKING_DIRECTORY ${LIB_DIR}
|
|
58 DEPENDS ${lib}
|
|
59 COMMENT "Generating Export list for ${lib}..."
|
|
60 VERBATIM )
|
|
61 endforeach ()
|
|
62
|
|
63 add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
|
|
64 COMMAND cat ${LLVM_DYLIB_REQUIRED_EXPORTS} > ${LLVM_EXPORTED_SYMBOL_FILE}
|
83
|
65 WORKING_DIRECTORY ${LIB_DIR}
|
95
|
66 DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS}
|
|
67 COMMENT "Generating combined export list...")
|
|
68 add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
|
69 endif()
|
|
70 else()
|
|
71 set(LLVM_EXPORTED_SYMBOL_FILE ${LLVM_DYLIB_EXPORTED_SYMBOL_FILE})
|
|
72 add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
|
83
|
73 endif()
|
|
74
|
95
|
75 add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB ${SOURCES})
|
83
|
76
|
95
|
77 list(REMOVE_DUPLICATES LIB_NAMES)
|
83
|
78 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf"
|
|
79 # GNU ld doesn't resolve symbols in the version script.
|
|
80 set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
|
95
|
81 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
|
82 set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
|
83
|
83 endif()
|
|
84
|
95
|
85 target_link_libraries(LLVM PRIVATE ${LIB_NAMES})
|
83
|
86
|
95
|
87 if(TARGET libLLVMExports)
|
|
88 add_dependencies(LLVM libLLVMExports)
|
|
89 endif()
|
83
|
90
|
|
91 if (APPLE)
|
|
92 set_property(TARGET LLVM APPEND_STRING PROPERTY
|
|
93 LINK_FLAGS
|
|
94 " -compatibility_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
|
|
95 endif()
|
|
96
|