Updating symbol wildcards one more time.
[oota-llvm.git] / tools / llvm-shlib / CMakeLists.txt
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_DYLIB_COMPONENTS
12     ${LLVM_TARGETS_TO_BUILD}
13     Analysis
14     BitReader
15     BitWriter
16     CodeGen
17     Core
18     ExecutionEngine
19     IPA
20     IPO
21     IRReader
22     InstCombine
23     Instrumentation
24     Interpreter
25     Linker
26     MCDisassembler
27     MCJIT
28     ObjCARCOpts
29     Object
30     ScalarOpts
31     Support
32     Target
33     TransformUtils
34     Vectorize
35     native
36     )
37 endif()
38
39 add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" )
40
41 set(SOURCES
42   libllvm.cpp
43   )
44
45 llvm_map_components_to_libnames(LIB_NAMES ${LLVM_DYLIB_COMPONENTS})
46
47 if(NOT DEFINED LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
48
49   if( WIN32 AND NOT CYGWIN )
50     message(FATAL_ERROR "Auto-generation not implemented for Win32 without GNU utils. Please specify LLVM_EXPORTED_SYMBOL_FILE.")
51   endif()
52
53   # To get the export list for a single llvm library:
54   # nm ${LIB_PATH} | awk "/T _LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_PATH}.exports
55
56   set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_BINARY_DIR}/libllvm.exports)
57
58   if (NOT LLVM_DYLIB_EXPORT_ALL)
59     foreach (lib ${LIB_NAMES})
60       set(LIB_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
61       set(LIB_NAME ${LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib})
62       set(LIB_PATH ${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
63       set(LIB_EXPORTS_PATH ${LIB_NAME}.exports)
64       list(APPEND LLVM_DYLIB_REQUIRED_EXPORTS ${LIB_EXPORTS_PATH})
65
66       
67       add_custom_command(OUTPUT ${LIB_EXPORTS_PATH}
68         COMMAND nm ${LIB_PATH} | awk "/T _LLVM/ || /T LLVM/ { print $3 }" | sort -u | sed -e "s/^_//g" > ${LIB_EXPORTS_PATH}
69         WORKING_DIRECTORY ${LIB_DIR}
70         DEPENDS ${lib}
71         COMMENT "Generating Export list for ${lib}..."
72         VERBATIM )
73     endforeach ()
74   endif()
75
76   if (LLVM_DYLIB_EXPORT_ALL)
77     add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
78       COMMAND echo \"LLVM*\" > ${LLVM_EXPORTED_SYMBOL_FILE} && echo \"_Z*llvm*\" >> ${LLVM_EXPORTED_SYMBOL_FILE}
79       WORKING_DIRECTORY ${LIB_DIR}
80       DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS}
81       COMMENT "Generating combined export list...")
82   else()
83     add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
84       COMMAND cat ${LLVM_DYLIB_REQUIRED_EXPORTS} > ${LLVM_EXPORTED_SYMBOL_FILE}
85       WORKING_DIRECTORY ${LIB_DIR}
86       DEPENDS ${LLVM_DYLIB_REQUIRED_EXPORTS}
87       COMMENT "Generating combined export list...")
88   endif()
89
90   add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
91 else()
92   set(LLVM_EXPORTED_SYMBOL_FILE ${LLVM_DYLIB_EXPORTED_SYMBOL_FILE})
93   add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
94 endif()
95
96 add_llvm_library(LLVM SHARED ${SOURCES})
97
98 list(REMOVE_DUPLICATES LIB_NAMES)
99 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf"
100   # GNU ld doesn't resolve symbols in the version script.
101   set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
102 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
103   set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
104 endif()
105
106 target_link_libraries(LLVM PRIVATE ${LIB_NAMES})
107
108 add_dependencies(LLVM libLLVMExports)
109
110 if (APPLE)
111   set_property(TARGET LLVM APPEND_STRING PROPERTY
112               LINK_FLAGS
113               " -compatibility_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} -current_version ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
114 endif()
115