150
|
1 cmake_minimum_required(VERSION 3.4.3)
|
|
2
|
|
3 if(POLICY CMP0075)
|
|
4 cmake_policy(SET CMP0075 NEW)
|
|
5 endif()
|
|
6
|
|
7 # If we are not building as a part of LLVM, build Clang as an
|
|
8 # standalone project, using LLVM as an external library:
|
|
9 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|
10 project(Clang)
|
|
11
|
|
12 # Rely on llvm-config.
|
|
13 set(CONFIG_OUTPUT)
|
|
14 if(LLVM_CONFIG)
|
|
15 set (LLVM_CONFIG_FOUND 1)
|
|
16 message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
|
17 message(DEPRECATION "Using llvm-config to detect the LLVM installation is \
|
|
18 deprecated. The installed cmake files should be used \
|
|
19 instead. CMake should be able to detect your LLVM install \
|
|
20 automatically, but you can also use LLVM_DIR to specify \
|
|
21 the path containing LLVMConfig.cmake.")
|
|
22 set(CONFIG_COMMAND ${LLVM_CONFIG}
|
|
23 "--assertion-mode"
|
|
24 "--bindir"
|
|
25 "--libdir"
|
|
26 "--includedir"
|
|
27 "--prefix"
|
|
28 "--src-root"
|
|
29 "--cmakedir")
|
|
30 execute_process(
|
|
31 COMMAND ${CONFIG_COMMAND}
|
|
32 RESULT_VARIABLE HAD_ERROR
|
|
33 OUTPUT_VARIABLE CONFIG_OUTPUT
|
|
34 )
|
|
35 if(NOT HAD_ERROR)
|
|
36 string(REGEX REPLACE
|
|
37 "[ \t]*[\r\n]+[ \t]*" ";"
|
|
38 CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
39 else()
|
|
40 string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
|
|
41 message(STATUS "${CONFIG_COMMAND_STR}")
|
|
42 message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
|
43 endif()
|
|
44
|
|
45 list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
|
|
46 list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
|
|
47 list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
|
|
48 list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
|
|
49 list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
|
|
50 list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
|
|
51 list(GET CONFIG_OUTPUT 6 LLVM_CONFIG_CMAKE_PATH)
|
|
52
|
|
53 # Normalize LLVM_CMAKE_PATH. --cmakedir might contain backslashes.
|
|
54 # CMake assumes slashes as PATH.
|
|
55 file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_PATH} LLVM_CMAKE_PATH)
|
|
56 endif()
|
|
57
|
|
58
|
|
59 if(NOT MSVC_IDE)
|
|
60 set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
|
|
61 CACHE BOOL "Enable assertions")
|
|
62 # Assertions should follow llvm-config's.
|
|
63 mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
|
|
64 endif()
|
|
65
|
|
66 find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")
|
|
67 list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
|
|
68
|
|
69 # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets
|
|
70 # LLVM_CONFIG.
|
|
71 if (NOT LLVM_CONFIG_FOUND)
|
|
72 # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
|
|
73 # path is removed.
|
|
74 set(TOOLS_BINARY_DIR ${LLVM_TOOLS_BINARY_DIR})
|
|
75 set(LIBRARY_DIR ${LLVM_LIBRARY_DIR})
|
|
76 set(INCLUDE_DIR ${LLVM_INCLUDE_DIR})
|
|
77 set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
|
|
78 # The LLVM_CMAKE_PATH variable is set when doing non-standalone builds and
|
|
79 # used in this project, so we need to make sure we set this value.
|
|
80 # FIXME: LLVM_CMAKE_DIR comes from LLVMConfig.cmake. We should rename
|
|
81 # LLVM_CMAKE_PATH to LLVM_CMAKE_DIR throughout the project.
|
|
82 set(LLVM_CMAKE_PATH ${LLVM_CMAKE_DIR})
|
|
83 endif()
|
|
84
|
|
85 set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
|
|
86 set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
|
|
87 set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
|
|
88 set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
|
|
89 set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
|
90
|
|
91 find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
|
92 NO_DEFAULT_PATH)
|
|
93
|
|
94 # They are used as destination of target generators.
|
|
95 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
|
|
96 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
|
97 if(WIN32 OR CYGWIN)
|
|
98 # DLL platform -- put DLLs into bin.
|
|
99 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
|
|
100 else()
|
|
101 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
|
|
102 endif()
|
|
103
|
|
104 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
|
|
105 option(LLVM_INSTALL_TOOLCHAIN_ONLY
|
|
106 "Only include toolchain files in the 'install' target." OFF)
|
|
107
|
|
108 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
|
|
109 "Set to ON to force using an old, unsupported host toolchain." OFF)
|
|
110 option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
|
|
111 option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
|
|
112
|
|
113 include(AddLLVM)
|
|
114 include(TableGen)
|
|
115 include(HandleLLVMOptions)
|
|
116 include(VersionFromVCS)
|
|
117 include(LLVMDistributionSupport)
|
|
118
|
|
119 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
120
|
|
121 if (NOT DEFINED LLVM_INCLUDE_TESTS)
|
|
122 set(LLVM_INCLUDE_TESTS ON)
|
|
123 endif()
|
|
124
|
|
125 include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
|
|
126 link_directories("${LLVM_LIBRARY_DIR}")
|
|
127
|
|
128 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
|
|
129 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
|
|
130 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
|
|
131
|
|
132 if(LLVM_INCLUDE_TESTS)
|
173
|
133 if(CMAKE_VERSION VERSION_LESS 3.12)
|
|
134 include(FindPythonInterp)
|
|
135 if(NOT PYTHONINTERP_FOUND)
|
|
136 message(FATAL_ERROR
|
|
137 "Unable to find Python interpreter, required for builds and testing.
|
|
138
|
|
139 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
|
|
140 endif()
|
|
141
|
|
142 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
|
|
143 message(FATAL_ERROR "Python 2.7 or newer is required")
|
|
144 endif()
|
150
|
145
|
173
|
146 add_executable(Python3::Interpreter IMPORTED)
|
|
147 set_target_properties(Python3::Interpreter PROPERTIES
|
|
148 IMPORTED_LOCATION ${PYTHON_EXECUTABLE})
|
|
149 set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
|
|
150 else()
|
|
151 find_package(Python3 COMPONENTS Interpreter)
|
|
152 if(NOT Python3_Interpreter_FOUND)
|
|
153 message(WARNING "Python3 not found, using python2 as a fallback")
|
|
154 find_package(Python2 COMPONENTS Interpreter REQUIRED)
|
|
155 if(Python2_VERSION VERSION_LESS 2.7)
|
|
156 message(SEND_ERROR "Python 2.7 or newer is required")
|
|
157 endif()
|
150
|
158
|
173
|
159 # Treat python2 as python3
|
|
160 add_executable(Python3::Interpreter IMPORTED)
|
|
161 set_target_properties(Python3::Interpreter PROPERTIES
|
|
162 IMPORTED_LOCATION ${Python2_EXECUTABLE})
|
|
163 set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
|
|
164 endif()
|
150
|
165 endif()
|
|
166
|
|
167 # Check prebuilt llvm/utils.
|
|
168 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
|
|
169 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
|
|
170 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
|
|
171 set(LLVM_UTILS_PROVIDED ON)
|
|
172 endif()
|
|
173
|
|
174 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
|
175 # Note: path not really used, except for checking if lit was found
|
|
176 set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
|
177 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
|
|
178 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
|
|
179 endif()
|
|
180 if(NOT LLVM_UTILS_PROVIDED)
|
|
181 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
|
|
182 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
|
|
183 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
|
|
184 set(LLVM_UTILS_PROVIDED ON)
|
|
185 set(CLANG_TEST_DEPS FileCheck count not)
|
|
186 endif()
|
|
187 set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
|
188 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
|
|
189 AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
|
190 AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
|
|
191 add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
|
192 endif()
|
|
193 else()
|
|
194 # Seek installed Lit.
|
|
195 find_program(LLVM_LIT
|
|
196 NAMES llvm-lit lit.py lit
|
|
197 PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
|
|
198 DOC "Path to lit.py")
|
|
199 endif()
|
|
200
|
|
201 if(LLVM_LIT)
|
|
202 # Define the default arguments to use with 'lit', and an option for the user
|
|
203 # to override.
|
|
204 set(LIT_ARGS_DEFAULT "-sv")
|
|
205 if (MSVC OR XCODE)
|
|
206 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
|
207 endif()
|
|
208 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
|
209
|
|
210 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
|
|
211 if( WIN32 AND NOT CYGWIN )
|
|
212 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
|
|
213 endif()
|
|
214 else()
|
|
215 set(LLVM_INCLUDE_TESTS OFF)
|
|
216 endif()
|
|
217 endif()
|
|
218
|
|
219 set( CLANG_BUILT_STANDALONE 1 )
|
|
220 set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
|
|
221 else()
|
|
222 set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
|
|
223 endif()
|
|
224
|
|
225 # Make sure that our source directory is on the current cmake module path so that
|
|
226 # we can include cmake files from this directory.
|
|
227 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
|
228
|
|
229 if(LLVM_ENABLE_LIBXML2)
|
|
230 # Don't look for libxml if we're using MSan, since uninstrumented third party
|
|
231 # code may call MSan interceptors like strlen, leading to false positives.
|
|
232 if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
|
|
233 set (LIBXML2_FOUND 0)
|
|
234 find_package(LibXml2 2.5.3 QUIET)
|
|
235 if (LIBXML2_FOUND)
|
|
236 set(CLANG_HAVE_LIBXML 1)
|
|
237 endif()
|
|
238 endif()
|
|
239 endif()
|
|
240
|
|
241 include(CheckIncludeFile)
|
|
242 check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
|
|
243
|
|
244 set(CLANG_RESOURCE_DIR "" CACHE STRING
|
|
245 "Relative directory from the Clang binary to its resource files.")
|
|
246
|
|
247 set(C_INCLUDE_DIRS "" CACHE STRING
|
|
248 "Colon separated list of directories clang will search for headers.")
|
|
249
|
|
250 set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
|
173
|
251 set(DEFAULT_SYSROOT "" CACHE STRING
|
150
|
252 "Default <path> to all compiler invocations for --sysroot=<path>." )
|
|
253
|
|
254 set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
|
|
255
|
|
256 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
|
|
257 "enable x86 relax relocations by default")
|
|
258
|
|
259 set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER FALSE CACHE BOOL
|
|
260 "Enable the experimental new pass manager by default.")
|
|
261
|
|
262 set(CLANG_SPAWN_CC1 OFF CACHE BOOL
|
|
263 "Whether clang should use a new process for the CC1 invocation")
|
|
264
|
|
265 # TODO: verify the values against LangStandards.def?
|
|
266 set(CLANG_DEFAULT_STD_C "" CACHE STRING
|
|
267 "Default standard to use for C/ObjC code (IDENT from LangStandards.def, empty for platform default)")
|
|
268 set(CLANG_DEFAULT_STD_CXX "" CACHE STRING
|
|
269 "Default standard to use for C++/ObjC++ code (IDENT from LangStandards.def, empty for platform default)")
|
|
270
|
|
271 set(CLANG_DEFAULT_LINKER "" CACHE STRING
|
|
272 "Default linker to use (linker name or absolute path, empty for platform default)")
|
|
273
|
|
274 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
|
|
275 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default")
|
|
276 if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR
|
|
277 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR
|
|
278 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++"))
|
|
279 message(WARNING "Resetting default C++ stdlib to use platform default")
|
|
280 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
|
|
281 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE)
|
|
282 endif()
|
|
283
|
|
284 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
|
|
285 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)")
|
|
286 if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
|
|
287 CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
|
|
288 CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
|
|
289 message(WARNING "Resetting default rtlib to use platform default")
|
|
290 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
|
|
291 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE)
|
|
292 endif()
|
|
293
|
|
294 set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING
|
|
295 "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)")
|
|
296 if (CLANG_DEFAULT_UNWINDLIB STREQUAL "")
|
|
297 if (CLANG_DEFAULT_RTLIB STREQUAL "libgcc")
|
|
298 set (CLANG_DEFAULT_UNWINDLIB "libgcc" CACHE STRING "" FORCE)
|
|
299 elseif (CLANG_DEFAULT_RTLIBS STREQUAL "libunwind")
|
|
300 set (CLANG_DEFAULT_UNWINDLIB "none" CACHE STRING "" FORCE)
|
|
301 endif()
|
|
302 endif()
|
|
303
|
|
304 if (NOT(CLANG_DEFAULT_UNWINDLIB STREQUAL "" OR
|
|
305 CLANG_DEFAULT_UNWINDLIB STREQUAL "none" OR
|
|
306 CLANG_DEFAULT_UNWINDLIB STREQUAL "libgcc" OR
|
|
307 CLANG_DEFAULT_UNWINDLIB STREQUAL "libunwind"))
|
|
308 message(WARNING "Resetting default unwindlib to use platform default")
|
|
309 set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING
|
|
310 "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty for none)" FORCE)
|
|
311 endif()
|
|
312
|
|
313 set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING
|
|
314 "Default objcopy executable to use.")
|
|
315
|
|
316 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
|
|
317 "Default OpenMP runtime used by -fopenmp.")
|
|
318
|
|
319 # OpenMP offloading requires at least sm_35 because we use shuffle instructions
|
|
320 # to generate efficient code for reductions and the atomicMax instruction on
|
|
321 # 64-bit integers in the implementation of conditional lastprivate.
|
|
322 set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_35" CACHE STRING
|
|
323 "Default architecture for OpenMP offloading to Nvidia GPUs.")
|
|
324 string(REGEX MATCH "^sm_([0-9]+)$" MATCHED_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}")
|
|
325 if (NOT DEFINED MATCHED_ARCH OR "${CMAKE_MATCH_1}" LESS 35)
|
|
326 message(WARNING "Resetting default architecture for OpenMP offloading to Nvidia GPUs to sm_35")
|
|
327 set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_35" CACHE STRING
|
|
328 "Default architecture for OpenMP offloading to Nvidia GPUs." FORCE)
|
|
329 endif()
|
|
330
|
173
|
331 set(CLANG_SYSTEMZ_DEFAULT_ARCH "z10" CACHE STRING "SystemZ Default Arch")
|
|
332
|
150
|
333 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
|
|
334 "Vendor-specific text for showing with version information.")
|
|
335
|
|
336 if( CLANG_VENDOR )
|
|
337 add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
|
|
338 endif()
|
|
339
|
|
340 set(CLANG_REPOSITORY_STRING "" CACHE STRING
|
|
341 "Vendor-specific text for showing the repository the source is taken from.")
|
|
342
|
|
343 if(CLANG_REPOSITORY_STRING)
|
|
344 add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}")
|
|
345 endif()
|
|
346
|
|
347 set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
|
|
348 "Vendor-specific uti.")
|
|
349
|
|
350 set(CLANG_PYTHON_BINDINGS_VERSIONS "" CACHE STRING
|
|
351 "Python versions to install libclang python bindings for")
|
|
352
|
|
353 set(CLANG_LINK_CLANG_DYLIB ${LLVM_LINK_LLVM_DYLIB} CACHE BOOL
|
|
354 "Link tools against libclang-cpp.so")
|
|
355
|
|
356 if (NOT LLVM_LINK_LLVM_DYLIB AND CLANG_LINK_CLANG_DYLIB)
|
|
357 message(FATAL_ERROR "Cannot set CLANG_LINK_CLANG_DYLIB=ON when "
|
|
358 "LLVM_LINK_LLVM_DYLIB=OFF")
|
|
359 endif()
|
|
360
|
|
361 # The libdir suffix must exactly match whatever LLVM's configuration used.
|
|
362 set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
|
|
363
|
|
364 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
365 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
366
|
|
367 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
|
|
368 message(FATAL_ERROR "In-source builds are not allowed. "
|
|
369 "Please create a directory and run cmake "
|
|
370 "from there, passing the path to this source directory as the last argument. "
|
|
371 "This process created the file `CMakeCache.txt' and the directory "
|
|
372 "`CMakeFiles'. Please delete them.")
|
|
373 endif()
|
|
374
|
|
375 # If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
|
|
376 if(NOT DEFINED CLANG_VERSION_MAJOR)
|
|
377 set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
|
|
378 endif()
|
|
379 if(NOT DEFINED CLANG_VERSION_MINOR)
|
|
380 set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
|
|
381 endif()
|
|
382 if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
|
|
383 set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
|
|
384 endif()
|
|
385 # Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
|
|
386 set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
|
|
387 message(STATUS "Clang version: ${CLANG_VERSION}")
|
|
388
|
|
389 # Configure the Version.inc file.
|
|
390 configure_file(
|
|
391 ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
|
|
392 ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
|
|
393
|
|
394 # Add appropriate flags for GCC
|
|
395 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
|
|
396 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
|
|
397 if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
398 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
|
|
399 endif ()
|
|
400
|
|
401 # Enable -pedantic for Clang even if it's not enabled for LLVM.
|
|
402 if (NOT LLVM_ENABLE_PEDANTIC)
|
|
403 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
|
|
404 endif ()
|
|
405
|
|
406 check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
|
|
407 if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
|
|
408 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
|
|
409 endif()
|
|
410 endif ()
|
|
411
|
|
412 # Determine HOST_LINK_VERSION on Darwin.
|
|
413 set(HOST_LINK_VERSION)
|
|
414 if (APPLE)
|
|
415 set(LD_V_OUTPUT)
|
|
416 execute_process(
|
|
417 COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
|
|
418 RESULT_VARIABLE HAD_ERROR
|
|
419 OUTPUT_VARIABLE LD_V_OUTPUT
|
|
420 )
|
|
421 if (NOT HAD_ERROR)
|
|
422 if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
|
|
423 string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
|
|
424 elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
|
|
425 string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
|
|
426 endif()
|
|
427 else()
|
|
428 message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
|
|
429 endif()
|
|
430 endif()
|
|
431
|
|
432 include(CMakeParseArguments)
|
|
433 include(AddClang)
|
|
434
|
|
435 set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
436
|
|
437 include_directories(BEFORE
|
|
438 ${CMAKE_CURRENT_BINARY_DIR}/include
|
|
439 ${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
440 )
|
|
441
|
|
442 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
443 install(DIRECTORY include/clang include/clang-c
|
|
444 DESTINATION include
|
|
445 COMPONENT clang-headers
|
|
446 FILES_MATCHING
|
|
447 PATTERN "*.def"
|
|
448 PATTERN "*.h"
|
|
449 PATTERN "config.h" EXCLUDE
|
|
450 PATTERN ".svn" EXCLUDE
|
|
451 )
|
|
452
|
|
453 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
|
|
454 DESTINATION include
|
|
455 COMPONENT clang-headers
|
|
456 FILES_MATCHING
|
|
457 PATTERN "CMakeFiles" EXCLUDE
|
|
458 PATTERN "*.inc"
|
|
459 PATTERN "*.h"
|
|
460 )
|
|
461
|
|
462 # Installing the headers needs to depend on generating any public
|
|
463 # tablegen'd headers.
|
|
464 add_custom_target(clang-headers DEPENDS clang-tablegen-targets)
|
|
465 set_target_properties(clang-headers PROPERTIES FOLDER "Misc")
|
|
466 if(NOT LLVM_ENABLE_IDE)
|
|
467 add_llvm_install_targets(install-clang-headers
|
|
468 DEPENDS clang-headers
|
|
469 COMPONENT clang-headers)
|
|
470 endif()
|
|
471
|
|
472 add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh)
|
|
473 install(PROGRAMS utils/bash-autocomplete.sh
|
|
474 DESTINATION share/clang
|
|
475 COMPONENT bash-autocomplete)
|
|
476 if(NOT LLVM_ENABLE_IDE)
|
|
477 add_llvm_install_targets(install-bash-autocomplete
|
|
478 DEPENDS bash-autocomplete
|
|
479 COMPONENT bash-autocomplete)
|
|
480 endif()
|
|
481 endif()
|
|
482
|
|
483 add_definitions( -D_GNU_SOURCE )
|
|
484
|
|
485 option(CLANG_BUILD_TOOLS
|
|
486 "Build the Clang tools. If OFF, just generate build targets." ON)
|
|
487
|
|
488 option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
|
|
489 option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
|
|
490
|
|
491 option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF)
|
|
492
|
|
493 if(NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
|
|
494 message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT or Z3")
|
|
495 endif()
|
|
496
|
|
497 if(CLANG_ENABLE_ARCMT)
|
|
498 set(CLANG_ENABLE_OBJC_REWRITER ON)
|
|
499 endif()
|
|
500
|
|
501 # Clang version information
|
|
502 set(CLANG_EXECUTABLE_VERSION
|
|
503 "${CLANG_VERSION_MAJOR}" CACHE STRING
|
|
504 "Major version number that will be appended to the clang executable name")
|
|
505 set(LIBCLANG_LIBRARY_VERSION
|
|
506 "${CLANG_VERSION_MAJOR}" CACHE STRING
|
|
507 "Major version number that will be appended to the libclang library")
|
|
508 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
|
|
509
|
|
510 option(CLANG_INCLUDE_TESTS
|
|
511 "Generate build targets for the Clang unit tests."
|
|
512 ${LLVM_INCLUDE_TESTS})
|
|
513
|
|
514 add_subdirectory(utils/TableGen)
|
|
515
|
|
516 add_subdirectory(include)
|
|
517
|
|
518 # All targets below may depend on all tablegen'd files.
|
|
519 get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
|
|
520 add_custom_target(clang-tablegen-targets DEPENDS ${CLANG_TABLEGEN_TARGETS})
|
|
521 set_target_properties(clang-tablegen-targets PROPERTIES FOLDER "Misc")
|
|
522 list(APPEND LLVM_COMMON_DEPENDS clang-tablegen-targets)
|
|
523
|
|
524 # Force target to be built as soon as possible. Clang modules builds depend
|
|
525 # header-wise on it as they ship all headers from the umbrella folders. Building
|
|
526 # an entire module might include header, which depends on intrinsics_gen.
|
|
527 if(LLVM_ENABLE_MODULES AND NOT CLANG_BUILT_STANDALONE)
|
|
528 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
|
|
529 endif()
|
|
530
|
|
531 add_subdirectory(lib)
|
|
532 add_subdirectory(tools)
|
|
533 add_subdirectory(runtime)
|
|
534
|
|
535 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
|
|
536 add_subdirectory(examples)
|
|
537
|
|
538 if(APPLE)
|
|
539 # this line is needed as a cleanup to ensure that any CMakeCaches with the old
|
|
540 # default value get updated to the new default.
|
|
541 if(CLANG_ORDER_FILE STREQUAL "")
|
|
542 unset(CLANG_ORDER_FILE CACHE)
|
|
543 unset(CLANG_ORDER_FILE)
|
|
544 endif()
|
|
545
|
|
546
|
|
547 set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
|
|
548 "Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).")
|
|
549
|
|
550 if(NOT EXISTS ${CLANG_ORDER_FILE})
|
|
551 string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
|
|
552 if(PATH_START EQUAL 0)
|
|
553 file(WRITE ${CLANG_ORDER_FILE} "\n")
|
|
554 else()
|
|
555 message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
|
|
556 endif()
|
|
557 endif()
|
|
558 endif()
|
|
559
|
|
560
|
|
561 if( CLANG_INCLUDE_TESTS )
|
|
562 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
|
|
563 add_subdirectory(unittests)
|
|
564 list(APPEND CLANG_TEST_DEPS ClangUnitTests)
|
|
565 list(APPEND CLANG_TEST_PARAMS
|
|
566 clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
|
|
567 )
|
|
568 endif()
|
|
569 add_subdirectory(test)
|
|
570 add_subdirectory(bindings/python/tests)
|
|
571
|
|
572 if(CLANG_BUILT_STANDALONE)
|
|
573 # Add a global check rule now that all subdirectories have been traversed
|
|
574 # and we know the total set of lit testsuites.
|
|
575 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
|
|
576 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
|
|
577 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
|
|
578 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
|
|
579 get_property(LLVM_ADDITIONAL_TEST_TARGETS
|
|
580 GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_TARGETS)
|
|
581 add_lit_target(check-all
|
|
582 "Running all regression tests"
|
|
583 ${LLVM_LIT_TESTSUITES}
|
|
584 PARAMS ${LLVM_LIT_PARAMS}
|
|
585 DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_TARGETS}
|
|
586 ARGS ${LLVM_LIT_EXTRA_ARGS}
|
|
587 )
|
|
588 endif()
|
|
589 add_subdirectory(utils/perf-training)
|
|
590 endif()
|
|
591
|
|
592 option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs."
|
|
593 ${LLVM_INCLUDE_DOCS})
|
|
594 if( CLANG_INCLUDE_DOCS )
|
|
595 add_subdirectory(docs)
|
|
596 endif()
|
|
597
|
|
598 # Custom target to install all clang libraries.
|
|
599 add_custom_target(clang-libraries)
|
|
600 set_target_properties(clang-libraries PROPERTIES FOLDER "Misc")
|
|
601
|
|
602 if(NOT LLVM_ENABLE_IDE)
|
|
603 add_llvm_install_targets(install-clang-libraries
|
|
604 DEPENDS clang-libraries
|
|
605 COMPONENT clang-libraries)
|
|
606 endif()
|
|
607
|
|
608 get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_LIBS)
|
|
609 if(CLANG_LIBS)
|
|
610 list(REMOVE_DUPLICATES CLANG_LIBS)
|
|
611 foreach(lib ${CLANG_LIBS})
|
|
612 add_dependencies(clang-libraries ${lib})
|
|
613 if(NOT LLVM_ENABLE_IDE)
|
|
614 add_dependencies(install-clang-libraries install-${lib})
|
173
|
615 add_dependencies(install-clang-libraries-stripped install-${lib}-stripped)
|
150
|
616 endif()
|
|
617 endforeach()
|
|
618 endif()
|
|
619
|
|
620 add_subdirectory(cmake/modules)
|
|
621
|
|
622 if(CLANG_STAGE)
|
|
623 message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
|
|
624 endif()
|
|
625
|
|
626 if (CLANG_ENABLE_BOOTSTRAP)
|
|
627 include(ExternalProject)
|
|
628
|
|
629 add_custom_target(clang-bootstrap-deps DEPENDS clang)
|
|
630
|
|
631 if(NOT CLANG_STAGE)
|
|
632 set(CLANG_STAGE stage1)
|
|
633 endif()
|
|
634
|
|
635 string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
|
|
636 if(MATCHED_STAGE)
|
|
637 if(NOT LLVM_BUILD_INSTRUMENTED)
|
|
638 math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1")
|
|
639 set(NEXT_CLANG_STAGE stage${STAGE_NUM})
|
|
640 else()
|
|
641 set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1})
|
|
642 endif()
|
|
643 else()
|
|
644 set(NEXT_CLANG_STAGE bootstrap)
|
|
645 endif()
|
|
646
|
|
647 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
|
|
648 set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented)
|
|
649 endif()
|
|
650 message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}")
|
|
651
|
|
652
|
|
653 set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/)
|
|
654 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/)
|
|
655
|
|
656 if(BOOTSTRAP_LLVM_ENABLE_LLD)
|
|
657 add_dependencies(clang-bootstrap-deps lld)
|
|
658 endif()
|
|
659
|
|
660 # If the next stage is LTO we need to depend on LTO and possibly lld or LLVMgold
|
|
661 if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO AND NOT LLVM_BUILD_INSTRUMENTED)
|
|
662 if(APPLE)
|
|
663 add_dependencies(clang-bootstrap-deps LTO)
|
|
664 # on Darwin we need to set DARWIN_LTO_LIBRARY so that -flto will work
|
|
665 # using the just-built compiler, and we need to override DYLD_LIBRARY_PATH
|
|
666 # so that the host object file tools will use the just-built libLTO.
|
|
667 # However if System Integrity Protection is enabled the DYLD variables
|
|
668 # will be scrubbed from the environment of any base system commands. This
|
|
669 # includes /bin/sh, which ninja uses when executing build commands. To
|
|
670 # work around the envar being filtered away we pass it in as a CMake
|
|
671 # variable, and have LLVM's CMake append the envar to the archiver calls.
|
|
672 set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib
|
|
673 -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR})
|
|
674 elseif(NOT WIN32)
|
|
675 add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
|
|
676 if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR)
|
|
677 add_dependencies(clang-bootstrap-deps LLVMgold)
|
|
678 endif()
|
|
679 set(${CLANG_STAGE}_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
|
|
680 set(${CLANG_STAGE}_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
|
|
681 endif()
|
|
682 endif()
|
|
683
|
|
684 if(CLANG_BOOTSTRAP_EXTRA_DEPS)
|
|
685 add_dependencies(clang-bootstrap-deps ${CLANG_BOOTSTRAP_EXTRA_DEPS})
|
|
686 endif()
|
|
687
|
|
688 add_custom_target(${NEXT_CLANG_STAGE}-clear
|
|
689 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
|
|
690 )
|
|
691 add_custom_command(
|
|
692 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
|
|
693 DEPENDS clang-bootstrap-deps
|
|
694 COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
|
|
695 COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR}
|
|
696 COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
|
|
697 COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR}
|
|
698 COMMENT "Clobberring ${NEXT_CLANG_STAGE} build and stamp directories"
|
|
699 )
|
|
700
|
|
701 if(CMAKE_VERBOSE_MAKEFILE)
|
|
702 set(verbose -DCMAKE_VERBOSE_MAKEFILE=On)
|
|
703 endif()
|
|
704
|
|
705 set(_BOOTSTRAP_DEFAULT_PASSTHROUGH
|
|
706 PACKAGE_VERSION
|
|
707 PACKAGE_VENDOR
|
|
708 LLVM_VERSION_MAJOR
|
|
709 LLVM_VERSION_MINOR
|
|
710 LLVM_VERSION_PATCH
|
|
711 CLANG_VERSION_MAJOR
|
|
712 CLANG_VERSION_MINOR
|
|
713 CLANG_VERSION_PATCHLEVEL
|
|
714 LLVM_VERSION_SUFFIX
|
|
715 LLVM_BINUTILS_INCDIR
|
|
716 CLANG_REPOSITORY_STRING
|
|
717 CMAKE_C_COMPILER_LAUNCHER
|
|
718 CMAKE_CXX_COMPILER_LAUNCHER
|
|
719 CMAKE_MAKE_PROGRAM
|
|
720 CMAKE_OSX_ARCHITECTURES
|
|
721 LLVM_ENABLE_PROJECTS
|
|
722 LLVM_ENABLE_RUNTIMES)
|
|
723
|
|
724 # We don't need to depend on compiler-rt/libcxx if we're building instrumented
|
|
725 # because the next stage will use the same compiler used to build this stage.
|
|
726 if(NOT LLVM_BUILD_INSTRUMENTED)
|
|
727 if(TARGET compiler-rt)
|
|
728 add_dependencies(clang-bootstrap-deps compiler-rt)
|
|
729 endif()
|
|
730 if(TARGET cxx-headers)
|
|
731 add_dependencies(clang-bootstrap-deps cxx-headers)
|
|
732 endif()
|
|
733 endif()
|
|
734
|
|
735 set(C_COMPILER "clang")
|
|
736 set(CXX_COMPILER "clang++")
|
|
737 if(WIN32)
|
|
738 set(C_COMPILER "clang-cl.exe")
|
|
739 set(CXX_COMPILER "clang-cl.exe")
|
|
740 endif()
|
|
741
|
|
742 set(COMPILER_OPTIONS
|
|
743 -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${CXX_COMPILER}
|
|
744 -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
|
|
745 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
|
|
746 -DCMAKE_ASM_COMPILER_ID=Clang)
|
|
747
|
|
748 if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
|
|
749 set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
|
|
750 set(${CLANG_STAGE}_TABLEGEN
|
|
751 -DLLVM_TABLEGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-tblgen
|
|
752 -DCLANG_TABLEGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-tblgen)
|
|
753 if(BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
754 if(BOOTSTRAP_LLVM_ENABLE_LLD)
|
|
755 set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld)
|
|
756 endif()
|
|
757 if(NOT BOOTSTRAP_LLVM_ENABLE_LTO)
|
|
758 add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
|
|
759 set(${CLANG_STAGE}_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
|
|
760 set(${CLANG_STAGE}_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
|
|
761 endif()
|
|
762 add_dependencies(clang-bootstrap-deps llvm-objcopy llvm-strip)
|
|
763 set(${CLANG_STAGE}_OBJCOPY -DCMAKE_OBJCOPY=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-objcopy)
|
|
764 set(${CLANG_STAGE}_STRIP -DCMAKE_STRIP=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-strip)
|
|
765 endif()
|
|
766 endif()
|
|
767
|
|
768 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
|
|
769 add_dependencies(clang-bootstrap-deps llvm-profdata)
|
|
770 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
|
|
771 endif()
|
|
772
|
|
773 if(LLVM_BUILD_INSTRUMENTED)
|
|
774 add_dependencies(clang-bootstrap-deps generate-profdata)
|
|
775 set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
|
|
776 # Use the current tools for LTO instead of the instrumented ones
|
|
777 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
|
|
778 CMAKE_CXX_COMPILER
|
|
779 CMAKE_C_COMPILER
|
|
780 CMAKE_ASM_COMPILER
|
|
781 CMAKE_AR
|
|
782 CMAKE_RANLIB
|
|
783 DARWIN_LTO_LIBRARY
|
|
784 DYLD_LIBRARY_PATH)
|
|
785
|
|
786 set(COMPILER_OPTIONS)
|
|
787 set(LTO_LIBRARY)
|
|
788 set(LTO_AR)
|
|
789 set(LTO_RANLIB)
|
|
790 endif()
|
|
791
|
|
792 # Find all variables that start with BOOTSTRAP_ and populate a variable with
|
|
793 # them.
|
|
794 get_cmake_property(variableNames VARIABLES)
|
|
795 foreach(variableName ${variableNames})
|
|
796 if(variableName MATCHES "^BOOTSTRAP_")
|
|
797 string(SUBSTRING ${variableName} 10 -1 varName)
|
|
798 string(REPLACE ";" "|" value "${${variableName}}")
|
|
799 list(APPEND PASSTHROUGH_VARIABLES
|
|
800 -D${varName}=${value})
|
|
801 endif()
|
|
802 if(${variableName} AND variableName MATCHES "LLVM_EXTERNAL_.*_SOURCE_DIR")
|
|
803 list(APPEND PASSTHROUGH_VARIABLES
|
|
804 -D${variableName}=${${variableName}})
|
|
805 endif()
|
|
806 endforeach()
|
|
807
|
|
808 # Populate the passthrough variables
|
|
809 foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH})
|
|
810 if(DEFINED ${variableName})
|
|
811 if("${${variableName}}" STREQUAL "")
|
|
812 set(value "")
|
|
813 else()
|
|
814 string(REPLACE ";" "|" value "${${variableName}}")
|
|
815 endif()
|
|
816 list(APPEND PASSTHROUGH_VARIABLES
|
|
817 -D${variableName}=${value})
|
|
818 endif()
|
|
819 endforeach()
|
|
820
|
|
821 ExternalProject_Add(${NEXT_CLANG_STAGE}
|
|
822 DEPENDS clang-bootstrap-deps
|
|
823 PREFIX ${NEXT_CLANG_STAGE}
|
|
824 SOURCE_DIR ${CMAKE_SOURCE_DIR}
|
|
825 STAMP_DIR ${STAMP_DIR}
|
|
826 BINARY_DIR ${BINARY_DIR}
|
|
827 EXCLUDE_FROM_ALL 1
|
|
828 CMAKE_ARGS
|
|
829 # We shouldn't need to set this here, but INSTALL_DIR doesn't
|
|
830 # seem to work, so instead I'm passing this through
|
|
831 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
|
832 ${PASSTHROUGH_VARIABLES}
|
|
833 ${CLANG_BOOTSTRAP_CMAKE_ARGS}
|
|
834 -DCLANG_STAGE=${NEXT_CLANG_STAGE}
|
|
835 ${COMPILER_OPTIONS}
|
|
836 ${${CLANG_STAGE}_CONFIG}
|
|
837 ${${CLANG_STAGE}_TABLEGEN}
|
|
838 ${LTO_LIBRARY} ${verbose} ${PGO_OPT}
|
|
839 ${${CLANG_STAGE}_LINKER}
|
|
840 ${${CLANG_STAGE}_AR}
|
|
841 ${${CLANG_STAGE}_RANLIB}
|
|
842 ${${CLANG_STAGE}_OBJCOPY}
|
|
843 ${${CLANG_STAGE}_STRIP}
|
|
844 INSTALL_COMMAND ""
|
|
845 STEP_TARGETS configure build
|
|
846 USES_TERMINAL_CONFIGURE 1
|
|
847 USES_TERMINAL_BUILD 1
|
|
848 USES_TERMINAL_INSTALL 1
|
|
849 LIST_SEPARATOR |
|
|
850 )
|
|
851
|
|
852 # exclude really-install from main target
|
|
853 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On)
|
|
854 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install
|
|
855 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
|
|
856 COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'"
|
|
857 DEPENDEES build
|
|
858 USES_TERMINAL 1
|
|
859 )
|
|
860 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install)
|
|
861 add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install)
|
|
862
|
|
863 if(NOT CLANG_BOOTSTRAP_TARGETS)
|
|
864 set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
|
|
865 endif()
|
|
866 foreach(target ${CLANG_BOOTSTRAP_TARGETS})
|
|
867 # exclude from main target
|
|
868 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
|
|
869
|
|
870 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
|
|
871 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
|
|
872 COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
|
|
873 DEPENDEES configure
|
|
874 USES_TERMINAL 1
|
|
875 )
|
|
876
|
|
877 if(target MATCHES "^stage[0-9]*")
|
|
878 add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target})
|
|
879 endif()
|
|
880
|
|
881 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target})
|
|
882 endforeach()
|
|
883 endif()
|
|
884
|
|
885 if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
|
|
886 add_subdirectory(utils/ClangVisualizers)
|
|
887 endif()
|
|
888 add_subdirectory(utils/hmaptool)
|
|
889
|
|
890 if(CLANG_BUILT_STANDALONE)
|
|
891 llvm_distribution_add_targets()
|
173
|
892 process_llvm_pass_plugins()
|
150
|
893 endif()
|
|
894
|
|
895 configure_file(
|
|
896 ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
|
|
897 ${CLANG_BINARY_DIR}/include/clang/Config/config.h)
|