Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / tools / driver / CMakeLists.txt
blob2182486f93a555386b955d99f0158020d0e256ae
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   TargetParser
17   TransformUtils
18   Vectorize
19   )
21 # Support plugins.
22 if(CLANG_PLUGIN_SUPPORT)
23   set(support_plugins SUPPORT_PLUGINS)
24 endif()
26 add_clang_tool(clang
27   driver.cpp
28   cc1_main.cpp
29   cc1as_main.cpp
30   cc1gen_reproducer_main.cpp
32   DEPENDS
33   intrinsics_gen
34   ${support_plugins}
35   GENERATE_DRIVER
36   )
38 clang_target_link_libraries(clang
39   PRIVATE
40   clangBasic
41   clangCodeGen
42   clangDriver
43   clangFrontend
44   clangFrontendTool
45   clangSerialization
46   )
48 if(WIN32 AND NOT CYGWIN)
49   # Prevent versioning if the buildhost is targeting for Win32.
50 else()
51   set_target_properties(clang PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})
52 endif()
54 # Support plugins.
55 if(CLANG_PLUGIN_SUPPORT)
56   export_executable_symbols_for_plugins(clang)
57 endif()
59 add_dependencies(clang clang-resource-headers)
61 if(NOT CLANG_LINKS_TO_CREATE)
62   set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
63 endif()
65 if (CLANG_ENABLE_HLSL)
66   set(HLSL_LINK clang-dxc)
67 endif()
69 foreach(link ${CLANG_LINKS_TO_CREATE} ${HLSL_LINK})
70   add_clang_symlink(${link} clang)
71 endforeach()
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()
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}")
86   set(TOOL_INFO_PLIST_OUT "${CMAKE_CURRENT_BINARY_DIR}/${TOOL_INFO_PLIST}")
88   if(LLVM_TOOL_LLVM_DRIVER_BUILD AND clang IN_LIST LLVM_DRIVER_TOOLS)
89     set(TARGET_NAME llvm-driver)
90   else()
91     set(TARGET_NAME clang)
92   endif()
94   target_link_libraries(${TARGET_NAME}
95     PRIVATE
96     "-Wl,-sectcreate,__TEXT,__info_plist,\"${TOOL_INFO_PLIST_OUT}\"")
97   configure_file("${TOOL_INFO_PLIST}.in" "${TOOL_INFO_PLIST_OUT}" @ONLY)
99   set(TOOL_INFO_UTI)
100   set(TOOL_INFO_NAME)
101   set(TOOL_INFO_VERSION)
102   set(TOOL_INFO_BUILD_VERSION)
103 endif()
105 if(CLANG_ORDER_FILE AND
106     (LLVM_LINKER_IS_LD64 OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
107   include(LLVMCheckLinkerFlag)
109   if (LLVM_LINKER_IS_LD64 OR (LLVM_LINKER_IS_LLD AND APPLE))
110     set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
111   elseif (LLVM_LINKER_IS_GOLD)
112     set(LINKER_ORDER_FILE_OPTION "-Wl,--section-ordering-file,${CLANG_ORDER_FILE}")
113   elseif (LLVM_LINKER_IS_LLD)
114     set(LINKER_ORDER_FILE_OPTION "-Wl,--symbol-ordering-file,${CLANG_ORDER_FILE}")
115   endif()
117   # This is a test to ensure the actual order file works with the linker.
118   llvm_check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS)
120   # Passing an empty order file disables some linker layout optimizations.
121   # To work around this and enable workflows for re-linking when the order file
122   # changes we check during configuration if the file is empty, and make it a
123   # configuration dependency.
124   file(READ ${CLANG_ORDER_FILE} ORDER_FILE LIMIT 20)
125   if("${ORDER_FILE}" STREQUAL "\n")
126     set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CLANG_ORDER_FILE})
127   elseif(LINKER_ORDER_FILE_WORKS)
128     target_link_libraries(clang PRIVATE ${LINKER_ORDER_FILE_OPTION})
129     set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE})
130   endif()
131 endif()