1set( LLVM_LINK_COMPONENTS
2  ${LLVM_TARGETS_TO_BUILD}
3  Analysis
4  CodeGen
5  Core
6  IPO
7  AggressiveInstCombine
8  InstCombine
9  Instrumentation
10  MC
11  MCParser
12  ObjCARCOpts
13  Option
14  ScalarOpts
15  Support
16  TransformUtils
17  Vectorize
18  )
19
20option(CLANG_PLUGIN_SUPPORT "Build clang with plugin support" ON)
21
22# Support plugins.
23if(CLANG_PLUGIN_SUPPORT)
24  set(support_plugins SUPPORT_PLUGINS)
25endif()
26
27add_clang_tool(clang
28  driver.cpp
29  cc1_main.cpp
30  cc1as_main.cpp
31  cc1gen_reproducer_main.cpp
32
33  DEPENDS
34  intrinsics_gen
35  ${support_plugins}
36  )
37
38clang_target_link_libraries(clang
39  PRIVATE
40  clangBasic
41  clangCodeGen
42  clangDriver
43  clangFrontend
44  clangFrontendTool
45  clangSerialization
46  )
47
48if(WIN32 AND NOT CYGWIN)
49  # Prevent versioning if the buildhost is targeting for Win32.
50else()
51  set_target_properties(clang PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})
52endif()
53
54# Support plugins.
55if(CLANG_PLUGIN_SUPPORT)
56  export_executable_symbols_for_plugins(clang)
57endif()
58
59add_dependencies(clang clang-resource-headers)
60
61if(NOT CLANG_LINKS_TO_CREATE)
62  set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
63endif()
64
65foreach(link ${CLANG_LINKS_TO_CREATE})
66  add_clang_symlink(${link} clang)
67endforeach()
68
69# Configure plist creation for OS X.
70set (TOOL_INFO_PLIST "Info.plist" CACHE STRING "Plist name")
71if (APPLE)
72  if (CLANG_VENDOR)
73    set(TOOL_INFO_NAME "${CLANG_VENDOR} clang")
74  else()
75    set(TOOL_INFO_NAME "clang")
76  endif()
77
78  set(TOOL_INFO_UTI "${CLANG_VENDOR_UTI}")
79  set(TOOL_INFO_VERSION "${CLANG_VERSION}")
80  set(TOOL_INFO_BUILD_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
81
82  set(TOOL_INFO_PLIST_OUT "${CMAKE_CURRENT_BINARY_DIR}/${TOOL_INFO_PLIST}")
83  target_link_libraries(clang
84    PRIVATE
85    "-Wl,-sectcreate,__TEXT,__info_plist,${TOOL_INFO_PLIST_OUT}")
86  configure_file("${TOOL_INFO_PLIST}.in" "${TOOL_INFO_PLIST_OUT}" @ONLY)
87
88  set(TOOL_INFO_UTI)
89  set(TOOL_INFO_NAME)
90  set(TOOL_INFO_VERSION)
91  set(TOOL_INFO_BUILD_VERSION)
92endif()
93
94if(CLANG_ORDER_FILE AND
95    (LLVM_LINKER_IS_LD64 OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
96  include(CheckLinkerFlag)
97
98  if (LLVM_LINKER_IS_LD64)
99    set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
100  elseif (LLVM_LINKER_IS_GOLD)
101    set(LINKER_ORDER_FILE_OPTION "-Wl,--section-ordering-file,${CLANG_ORDER_FILE}")
102  elseif (LLVM_LINKER_IS_LLD)
103    set(LINKER_ORDER_FILE_OPTION "-Wl,--symbol-ordering-file,${CLANG_ORDER_FILE}")
104  endif()
105
106  # This is a test to ensure the actual order file works with the linker.
107  check_linker_flag(${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS)
108
109  # Passing an empty order file disables some linker layout optimizations.
110  # To work around this and enable workflows for re-linking when the order file
111  # changes we check during configuration if the file is empty, and make it a
112  # configuration dependency.
113  file(READ ${CLANG_ORDER_FILE} ORDER_FILE LIMIT 20)
114  if("${ORDER_FILE}" STREQUAL "\n")
115    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CLANG_ORDER_FILE})
116  elseif(LINKER_ORDER_FILE_WORKS)
117    target_link_libraries(clang PRIVATE ${LINKER_ORDER_FILE_OPTION})
118    set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
119  endif()
120endif()
121