1 cmake_minimum_required(VERSION 3.4.3)
3 # If we are not building as a part of LLVM, build Clang as an
4 # standalone project, using LLVM as an external library:
5 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
10 find_program(LLVM_CONFIG "llvm-config")
12 message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
13 set(CONFIG_COMMAND ${LLVM_CONFIG}
22 COMMAND ${CONFIG_COMMAND}
23 RESULT_VARIABLE HAD_ERROR
24 OUTPUT_VARIABLE CONFIG_OUTPUT
28 "[ \t]*[\r\n]+[ \t]*" ";"
29 CONFIG_OUTPUT ${CONFIG_OUTPUT})
31 string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
32 message(STATUS "${CONFIG_COMMAND_STR}")
33 message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
36 message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}")
39 list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
40 list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
41 list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
42 list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
43 list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
44 list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
45 list(GET CONFIG_OUTPUT 6 LLVM_CONFIG_CMAKE_PATH)
48 set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
49 CACHE BOOL "Enable assertions")
50 # Assertions should follow llvm-config's.
51 mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
54 set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
55 set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
56 set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
57 set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
58 set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
60 # Normalize LLVM_CMAKE_PATH. --cmakedir might contain backslashes.
61 # CMake assumes slashes as PATH.
62 file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_PATH} LLVM_CMAKE_PATH)
64 find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
67 set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
68 if(EXISTS ${LLVMCONFIG_FILE})
69 list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
70 include(${LLVMCONFIG_FILE})
72 message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
75 # They are used as destination of target generators.
76 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
77 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
79 # DLL platform -- put DLLs into bin.
80 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
82 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
85 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
86 option(LLVM_INSTALL_TOOLCHAIN_ONLY
87 "Only include toolchain files in the 'install' target." OFF)
89 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
90 "Set to ON to force using an old, unsupported host toolchain." OFF)
91 option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
95 include(HandleLLVMOptions)
96 include(VersionFromVCS)
98 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
100 if (NOT DEFINED LLVM_INCLUDE_TESTS)
101 set(LLVM_INCLUDE_TESTS ON)
104 include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
105 link_directories("${LLVM_LIBRARY_DIR}")
107 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
108 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
109 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
111 if(LLVM_INCLUDE_TESTS)
112 set(Python_ADDITIONAL_VERSIONS 2.7)
113 include(FindPythonInterp)
114 if(NOT PYTHONINTERP_FOUND)
116 "Unable to find Python interpreter, required for builds and testing.
118 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
121 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
122 message(FATAL_ERROR "Python 2.7 or newer is required")
125 # Check prebuilt llvm/utils.
126 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
127 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
128 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
129 set(LLVM_UTILS_PROVIDED ON)
132 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
133 # Note: path not really used, except for checking if lit was found
134 set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
135 if(NOT LLVM_UTILS_PROVIDED)
136 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
137 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
138 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
139 set(LLVM_UTILS_PROVIDED ON)
140 set(CLANG_TEST_DEPS FileCheck count not)
142 set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
143 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
144 AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
145 AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
146 add_subdirectory(${UNITTEST_DIR} utils/unittest)
149 # Seek installed Lit.
150 find_program(LLVM_LIT
151 NAMES llvm-lit lit.py lit
152 PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
153 DOC "Path to lit.py")
157 # Define the default arguments to use with 'lit', and an option for the user
159 set(LIT_ARGS_DEFAULT "-sv")
161 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
163 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
165 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
166 if( WIN32 AND NOT CYGWIN )
167 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
170 set(LLVM_INCLUDE_TESTS OFF)
174 set( CLANG_BUILT_STANDALONE 1 )
175 set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
177 set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
180 # Make sure that our source directory is on the current cmake module path so that
181 # we can include cmake files from this directory.
182 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
184 find_package(LibXml2 2.5.3 QUIET)
186 set(CLANG_HAVE_LIBXML 1)
191 include(CheckIncludeFile)
192 check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
194 set(CLANG_RESOURCE_DIR "" CACHE STRING
195 "Relative directory from the Clang binary to its resource files.")
197 set(C_INCLUDE_DIRS "" CACHE STRING
198 "Colon separated list of directories clang will search for headers.")
200 set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
201 set(DEFAULT_SYSROOT "" CACHE PATH
202 "Default <path> to all compiler invocations for --sysroot=<path>." )
204 set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
206 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
207 "enable x86 relax relocations by default")
209 set(CLANG_DEFAULT_LINKER "" CACHE STRING
210 "Default linker to use (linker name or absolute path, empty for platform default)")
212 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
213 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default")
214 if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR
215 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR
216 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++"))
217 message(WARNING "Resetting default C++ stdlib to use platform default")
218 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
219 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE)
222 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
223 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)")
224 if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
225 CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
226 CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
227 message(WARNING "Resetting default rtlib to use platform default")
228 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
229 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE)
232 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
233 "Default OpenMP runtime used by -fopenmp.")
235 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
236 "Vendor-specific text for showing with version information.")
239 add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
242 set(CLANG_REPOSITORY_STRING "" CACHE STRING
243 "Vendor-specific text for showing the repository the source is taken from.")
245 if(CLANG_REPOSITORY_STRING)
246 add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}")
249 set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
250 "Vendor-specific uti.")
252 # The libdir suffix must exactly match whatever LLVM's configuration used.
253 set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
255 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
256 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
258 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
259 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
260 "the makefiles distributed with LLVM. Please create a directory and run cmake "
261 "from there, passing the path to this source directory as the last argument. "
262 "This process created the file `CMakeCache.txt' and the directory "
263 "`CMakeFiles'. Please delete them.")
266 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
268 tablegenned_files_on_include_dir
269 "${CLANG_SOURCE_DIR}/include/clang/*.inc")
270 if( tablegenned_files_on_include_dir )
271 message(FATAL_ERROR "Apparently there is a previous in-source build, "
272 "probably as the result of running `configure' and `make' on "
273 "${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
274 "${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
278 # If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
279 if(NOT DEFINED CLANG_VERSION_MAJOR)
280 set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
282 if(NOT DEFINED CLANG_VERSION_MINOR)
283 set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
285 if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
286 set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
288 # Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
289 set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
290 message(STATUS "Clang version: ${CLANG_VERSION}")
292 # Configure the Version.inc file.
294 ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
295 ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
297 # Add appropriate flags for GCC
298 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
299 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
300 if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
301 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
304 # Enable -pedantic for Clang even if it's not enabled for LLVM.
305 if (NOT LLVM_ENABLE_PEDANTIC)
306 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
309 check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
310 if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
311 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
315 # Determine HOST_LINK_VERSION on Darwin.
316 set(HOST_LINK_VERSION)
320 COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
321 RESULT_VARIABLE HAD_ERROR
322 OUTPUT_VARIABLE LD_V_OUTPUT
325 if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
326 string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
327 elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
328 string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
331 message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
335 include(CMakeParseArguments)
338 set(CMAKE_INCLUDE_CURRENT_DIR ON)
340 include_directories(BEFORE
341 ${CMAKE_CURRENT_BINARY_DIR}/include
342 ${CMAKE_CURRENT_SOURCE_DIR}/include
345 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
346 install(DIRECTORY include/clang include/clang-c
351 PATTERN "config.h" EXCLUDE
352 PATTERN ".svn" EXCLUDE
355 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
358 PATTERN "CMakeFiles" EXCLUDE
364 add_definitions( -D_GNU_SOURCE )
366 option(CLANG_BUILD_TOOLS
367 "Build the Clang tools. If OFF, just generate build targets." ON)
369 option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
370 option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
372 option(CLANG_ANALYZER_BUILD_Z3
373 "Build the static analyzer with the Z3 constraint manager." OFF)
375 if(NOT CLANG_ENABLE_STATIC_ANALYZER AND (CLANG_ENABLE_ARCMT OR CLANG_ANALYZER_BUILD_Z3))
376 message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT or Z3")
379 if(CLANG_ANALYZER_BUILD_Z3)
381 set(CLANG_ANALYZER_WITH_Z3 1)
383 message(FATAL_ERROR "Cannot find Z3 header file or shared library")
387 if(CLANG_ENABLE_ARCMT)
388 add_definitions(-DCLANG_ENABLE_ARCMT)
389 add_definitions(-DCLANG_ENABLE_OBJC_REWRITER)
391 if(CLANG_ENABLE_STATIC_ANALYZER)
392 add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER)
395 # Clang version information
396 set(CLANG_EXECUTABLE_VERSION
397 "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
398 "Version number that will be placed into the clang executable, in the form XX.YY")
399 set(LIBCLANG_LIBRARY_VERSION
400 "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
401 "Version number that will be placed into the libclang library , in the form XX.YY")
402 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
404 option(CLANG_INCLUDE_TESTS
405 "Generate build targets for the Clang unit tests."
406 ${LLVM_INCLUDE_TESTS})
408 add_subdirectory(utils/TableGen)
410 add_subdirectory(include)
412 # All targets below may depend on all tablegen'd files.
413 get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
414 list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS})
416 add_subdirectory(lib)
417 add_subdirectory(tools)
418 add_subdirectory(runtime)
420 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
421 add_subdirectory(examples)
424 # this line is needed as a cleanup to ensure that any CMakeCaches with the old
425 # default value get updated to the new default.
426 if(CLANG_ORDER_FILE STREQUAL "")
427 unset(CLANG_ORDER_FILE CACHE)
428 unset(CLANG_ORDER_FILE)
432 set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
433 "Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).")
435 if(NOT EXISTS ${CLANG_ORDER_FILE})
436 string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
437 if(PATH_START EQUAL 0)
438 file(WRITE ${CLANG_ORDER_FILE} "\n")
440 message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
446 if( CLANG_INCLUDE_TESTS )
447 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
448 add_subdirectory(unittests)
449 list(APPEND CLANG_TEST_DEPS ClangUnitTests)
450 list(APPEND CLANG_TEST_PARAMS
451 clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
454 add_subdirectory(test)
456 if(CLANG_BUILT_STANDALONE)
457 # Add a global check rule now that all subdirectories have been traversed
458 # and we know the total set of lit testsuites.
459 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
460 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
461 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
462 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
463 add_lit_target(check-all
464 "Running all regression tests"
465 ${LLVM_LIT_TESTSUITES}
466 PARAMS ${LLVM_LIT_PARAMS}
467 DEPENDS ${LLVM_LIT_DEPENDS}
468 ARGS ${LLVM_LIT_EXTRA_ARGS}
471 add_subdirectory(utils/perf-training)
474 option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs."
475 ${LLVM_INCLUDE_DOCS})
476 if( CLANG_INCLUDE_DOCS )
477 add_subdirectory(docs)
480 add_subdirectory(cmake/modules)
483 message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
486 if (CLANG_ENABLE_BOOTSTRAP)
487 include(ExternalProject)
489 add_custom_target(clang-bootstrap-deps DEPENDS clang)
492 set(CLANG_STAGE stage1)
495 string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
497 if(NOT LLVM_BUILD_INSTRUMENTED)
498 math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1")
499 set(NEXT_CLANG_STAGE stage${STAGE_NUM})
501 set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1})
504 set(NEXT_CLANG_STAGE bootstrap)
507 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
508 set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented)
510 message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}")
513 set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/)
514 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/)
516 if(BOOTSTRAP_LLVM_ENABLE_LLD)
517 add_dependencies(clang-bootstrap-deps lld)
520 # If the next stage is LTO we need to depend on LTO and possibly lld or LLVMgold
521 if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO AND NOT LLVM_BUILD_INSTRUMENTED)
523 add_dependencies(clang-bootstrap-deps LTO)
524 # on Darwin we need to set DARWIN_LTO_LIBRARY so that -flto will work
525 # using the just-built compiler, and we need to override DYLD_LIBRARY_PATH
526 # so that the host object file tools will use the just-built libLTO.
527 # However if System Integrity Protection is enabled the DYLD variables
528 # will be scrubbed from the environment of any base system commands. This
529 # includes /bin/sh, which ninja uses when executing build commands. To
530 # work around the envar being filtered away we pass it in as a CMake
531 # variable, and have LLVM's CMake append the envar to the archiver calls.
532 set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib
533 -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR})
535 add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
536 if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR)
537 add_dependencies(clang-bootstrap-deps LLVMgold)
539 set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
540 set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
544 add_custom_target(${NEXT_CLANG_STAGE}-clear
545 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
548 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
549 DEPENDS clang-bootstrap-deps
550 COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
551 COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR}
552 COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
553 COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR}
554 COMMENT "Clobberring ${NEXT_CLANG_STAGE} build and stamp directories"
557 if(CMAKE_VERBOSE_MAKEFILE)
558 set(verbose -DCMAKE_VERBOSE_MAKEFILE=On)
561 set(_BOOTSTRAP_DEFAULT_PASSTHROUGH
569 CLANG_VERSION_PATCHLEVEL
572 CLANG_REPOSITORY_STRING
574 CMAKE_OSX_ARCHITECTURES)
576 # We don't need to depend on compiler-rt if we're building instrumented
577 # because the next stage will use the same compiler used to build this stage.
578 if(TARGET compiler-rt AND NOT LLVM_BUILD_INSTRUMENTED)
579 add_dependencies(clang-bootstrap-deps compiler-rt)
583 -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
584 -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
585 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
587 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
588 add_dependencies(clang-bootstrap-deps llvm-profdata)
589 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
592 if(LLVM_BUILD_INSTRUMENTED)
593 add_dependencies(clang-bootstrap-deps generate-profdata)
594 set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
595 # Use the current tools for LTO instead of the instrumented ones
596 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
605 set(COMPILER_OPTIONS)
611 # Find all variables that start with BOOTSTRAP_ and populate a variable with
613 get_cmake_property(variableNames VARIABLES)
614 foreach(variableName ${variableNames})
615 if(variableName MATCHES "^BOOTSTRAP_")
616 string(SUBSTRING ${variableName} 10 -1 varName)
617 string(REPLACE ";" "\;" value "${${variableName}}")
618 list(APPEND PASSTHROUGH_VARIABLES
619 -D${varName}=${value})
621 if(${variableName} AND variableName MATCHES "LLVM_EXTERNAL_.*_SOURCE_DIR")
622 list(APPEND PASSTHROUGH_VARIABLES
623 -D${variableName}=${${variableName}})
627 # Populate the passthrough variables
628 foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH})
629 if(DEFINED ${variableName})
630 if("${${variableName}}" STREQUAL "")
633 string(REPLACE ";" "\;" value ${${variableName}})
635 list(APPEND PASSTHROUGH_VARIABLES
636 -D${variableName}=${value})
640 ExternalProject_Add(${NEXT_CLANG_STAGE}
641 DEPENDS clang-bootstrap-deps
642 PREFIX ${NEXT_CLANG_STAGE}
643 SOURCE_DIR ${CMAKE_SOURCE_DIR}
644 STAMP_DIR ${STAMP_DIR}
645 BINARY_DIR ${BINARY_DIR}
648 # We shouldn't need to set this here, but INSTALL_DIR doesn't
649 # seem to work, so instead I'm passing this through
650 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
651 ${CLANG_BOOTSTRAP_CMAKE_ARGS}
652 ${PASSTHROUGH_VARIABLES}
653 -DCLANG_STAGE=${NEXT_CLANG_STAGE}
655 ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose} ${PGO_OPT}
657 STEP_TARGETS configure build
658 USES_TERMINAL_CONFIGURE 1
659 USES_TERMINAL_BUILD 1
660 USES_TERMINAL_INSTALL 1
663 # exclude really-install from main target
664 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On)
665 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install
666 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
667 COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'"
671 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install)
672 add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install)
674 if(NOT CLANG_BOOTSTRAP_TARGETS)
675 set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
677 foreach(target ${CLANG_BOOTSTRAP_TARGETS})
678 # exclude from main target
679 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
681 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
682 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
683 COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
688 if(target MATCHES "^stage[0-9]*")
689 add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target})
692 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target})
696 if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
697 add_subdirectory(utils/ClangVisualizers)
701 ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
702 ${CLANG_BINARY_DIR}/include/clang/Config/config.h)