~pali/+junk/llvm-toolchain-3.7

« back to all changes in this revision

Viewing changes to tools/llvm-shlib/CMakeLists.txt

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2015-07-15 17:51:08 UTC
  • Revision ID: package-import@ubuntu.com-20150715175108-l8mynwovkx4zx697
Tags: upstream-3.7~+rc2
ImportĀ upstreamĀ versionĀ 3.7~+rc2

Show diffs side-by-side

added added

removed removed

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