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