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_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 find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
63 set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
64 if(EXISTS ${LLVMCONFIG_FILE})
65 list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
66 include(${LLVMCONFIG_FILE})
68 message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
71 # They are used as destination of target generators.
72 set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
73 set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
75 # DLL platform -- put DLLs into bin.
76 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
78 set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
81 option(LLVM_INSTALL_TOOLCHAIN_ONLY
82 "Only include toolchain files in the 'install' target." OFF)
84 option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
85 "Set to ON to force using an old, unsupported host toolchain." OFF)
86 option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
90 include(HandleLLVMOptions)
91 include(VersionFromVCS)
93 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
95 if (NOT DEFINED LLVM_INCLUDE_TESTS)
96 set(LLVM_INCLUDE_TESTS ON)
99 include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
100 link_directories("${LLVM_LIBRARY_DIR}")
102 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
103 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
104 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
106 if(LLVM_INCLUDE_TESTS)
107 set(Python_ADDITIONAL_VERSIONS 2.7)
108 include(FindPythonInterp)
109 if(NOT PYTHONINTERP_FOUND)
111 "Unable to find Python interpreter, required for builds and testing.
113 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
116 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
117 message(FATAL_ERROR "Python 2.7 or newer is required")
120 # Check prebuilt llvm/utils.
121 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
122 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
123 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
124 set(LLVM_UTILS_PROVIDED ON)
127 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
128 # Note: path not really used, except for checking if lit was found
129 set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
130 if(NOT LLVM_UTILS_PROVIDED)
131 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
132 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
133 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
134 set(LLVM_UTILS_PROVIDED ON)
135 set(CLANG_TEST_DEPS FileCheck count not)
137 set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
138 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
139 AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
140 AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
141 add_subdirectory(${UNITTEST_DIR} utils/unittest)
144 # Seek installed Lit.
145 find_program(LLVM_LIT
146 NAMES llvm-lit lit.py lit
147 PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
148 DOC "Path to lit.py")
152 # Define the default arguments to use with 'lit', and an option for the user
154 set(LIT_ARGS_DEFAULT "-sv")
156 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
158 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
160 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
161 if( WIN32 AND NOT CYGWIN )
162 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
165 set(LLVM_INCLUDE_TESTS OFF)
169 set( CLANG_BUILT_STANDALONE 1 )
170 set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
172 set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
175 # Make sure that our source directory is on the current cmake module path so that
176 # we can include cmake files from this directory.
177 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
179 find_package(LibXml2 2.5.3 QUIET)
181 set(CLANG_HAVE_LIBXML 1)
184 include(CheckIncludeFile)
185 check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
187 set(CLANG_RESOURCE_DIR "" CACHE STRING
188 "Relative directory from the Clang binary to its resource files.")
190 set(C_INCLUDE_DIRS "" CACHE STRING
191 "Colon separated list of directories clang will search for headers.")
193 set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
194 set(DEFAULT_SYSROOT "" CACHE PATH
195 "Default <path> to all compiler invocations for --sysroot=<path>." )
197 set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
199 set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
200 "enable x86 relax relocations by default")
202 set(CLANG_DEFAULT_LINKER "" CACHE STRING
203 "Default linker to use (linker name or absolute path, empty for platform default)")
205 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
206 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default")
207 if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR
208 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR
209 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++"))
210 message(WARNING "Resetting default C++ stdlib to use platform default")
211 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
212 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE)
215 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
216 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)")
217 if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
218 CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
219 CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
220 message(WARNING "Resetting default rtlib to use platform default")
221 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
222 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE)
225 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
226 "Default OpenMP runtime used by -fopenmp.")
228 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
229 "Vendor-specific text for showing with version information.")
232 add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
235 set(CLANG_REPOSITORY_STRING "" CACHE STRING
236 "Vendor-specific text for showing the repository the source is taken from.")
238 if(CLANG_REPOSITORY_STRING)
239 add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}")
242 set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
243 "Vendor-specific uti.")
245 # The libdir suffix must exactly match whatever LLVM's configuration used.
246 set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
248 set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
249 set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
251 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
252 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
253 "the makefiles distributed with LLVM. Please create a directory and run cmake "
254 "from there, passing the path to this source directory as the last argument. "
255 "This process created the file `CMakeCache.txt' and the directory "
256 "`CMakeFiles'. Please delete them.")
259 if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
261 tablegenned_files_on_include_dir
262 "${CLANG_SOURCE_DIR}/include/clang/*.inc")
263 if( tablegenned_files_on_include_dir )
264 message(FATAL_ERROR "Apparently there is a previous in-source build, "
265 "probably as the result of running `configure' and `make' on "
266 "${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
267 "${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
271 # If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
272 if(NOT DEFINED CLANG_VERSION_MAJOR)
273 set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
275 if(NOT DEFINED CLANG_VERSION_MINOR)
276 set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
278 if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
279 set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
281 # Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
282 set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
283 message(STATUS "Clang version: ${CLANG_VERSION}")
285 # Configure the Version.inc file.
287 ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
288 ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
290 # Add appropriate flags for GCC
291 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
292 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
293 if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
294 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
297 # Enable -pedantic for Clang even if it's not enabled for LLVM.
298 if (NOT LLVM_ENABLE_PEDANTIC)
299 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
302 check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
303 if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
304 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
308 # Determine HOST_LINK_VERSION on Darwin.
309 set(HOST_LINK_VERSION)
313 COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
314 RESULT_VARIABLE HAD_ERROR
315 OUTPUT_VARIABLE LD_V_OUTPUT
318 if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
319 string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
320 elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
321 string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
324 message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
329 ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
330 ${CLANG_BINARY_DIR}/include/clang/Config/config.h)
332 include(CMakeParseArguments)
335 set(CMAKE_INCLUDE_CURRENT_DIR ON)
337 include_directories(BEFORE
338 ${CMAKE_CURRENT_BINARY_DIR}/include
339 ${CMAKE_CURRENT_SOURCE_DIR}/include
342 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
343 install(DIRECTORY include/clang include/clang-c
348 PATTERN "config.h" EXCLUDE
349 PATTERN ".svn" EXCLUDE
352 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
355 PATTERN "CMakeFiles" EXCLUDE
361 add_definitions( -D_GNU_SOURCE )
363 option(CLANG_BUILD_TOOLS
364 "Build the Clang tools. If OFF, just generate build targets." ON)
366 option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
367 option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
369 if (NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
370 message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT")
373 if(CLANG_ENABLE_ARCMT)
374 add_definitions(-DCLANG_ENABLE_ARCMT)
375 add_definitions(-DCLANG_ENABLE_OBJC_REWRITER)
377 if(CLANG_ENABLE_STATIC_ANALYZER)
378 add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER)
381 # Clang version information
382 set(CLANG_EXECUTABLE_VERSION
383 "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
384 "Version number that will be placed into the clang executable, in the form XX.YY")
385 set(LIBCLANG_LIBRARY_VERSION
386 "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
387 "Version number that will be placed into the libclang library , in the form XX.YY")
388 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
390 option(CLANG_INCLUDE_TESTS
391 "Generate build targets for the Clang unit tests."
392 ${LLVM_INCLUDE_TESTS})
394 add_subdirectory(utils/TableGen)
396 add_subdirectory(include)
398 # All targets below may depend on all tablegen'd files.
399 get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
400 list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS})
402 add_subdirectory(lib)
403 add_subdirectory(tools)
404 add_subdirectory(runtime)
406 option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
407 add_subdirectory(examples)
410 # this line is needed as a cleanup to ensure that any CMakeCaches with the old
411 # default value get updated to the new default.
412 if(CLANG_ORDER_FILE STREQUAL "")
413 unset(CLANG_ORDER_FILE CACHE)
414 unset(CLANG_ORDER_FILE)
418 set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
419 "Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).")
421 if(NOT EXISTS ${CLANG_ORDER_FILE})
422 string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
423 if(PATH_START EQUAL 0)
424 file(WRITE ${CLANG_ORDER_FILE} "\n")
426 message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
432 if( CLANG_INCLUDE_TESTS )
433 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
434 add_subdirectory(unittests)
435 list(APPEND CLANG_TEST_DEPS ClangUnitTests)
436 list(APPEND CLANG_TEST_PARAMS
437 clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
440 add_subdirectory(test)
442 if(CLANG_BUILT_STANDALONE)
443 # Add a global check rule now that all subdirectories have been traversed
444 # and we know the total set of lit testsuites.
445 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
446 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
447 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
448 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
449 add_lit_target(check-all
450 "Running all regression tests"
451 ${LLVM_LIT_TESTSUITES}
452 PARAMS ${LLVM_LIT_PARAMS}
453 DEPENDS ${LLVM_LIT_DEPENDS}
454 ARGS ${LLVM_LIT_EXTRA_ARGS}
457 add_subdirectory(utils/perf-training)
460 option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs."
461 ${LLVM_INCLUDE_DOCS})
462 if( CLANG_INCLUDE_DOCS )
463 add_subdirectory(docs)
466 add_subdirectory(cmake/modules)
469 message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
472 if (CLANG_ENABLE_BOOTSTRAP)
473 include(ExternalProject)
475 add_custom_target(clang-bootstrap-deps DEPENDS clang)
478 set(CLANG_STAGE stage1)
481 string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
483 if(NOT LLVM_BUILD_INSTRUMENTED)
484 math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1")
485 set(NEXT_CLANG_STAGE stage${STAGE_NUM})
487 set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1})
490 set(NEXT_CLANG_STAGE bootstrap)
493 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
494 set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented)
496 message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}")
499 set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/)
500 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/)
502 if(BOOTSTRAP_LLVM_ENABLE_LLD)
503 add_dependencies(clang-bootstrap-deps lld)
506 # If the next stage is LTO we need to depend on LTO and possibly lld or LLVMgold
507 if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO AND NOT LLVM_BUILD_INSTRUMENTED)
509 add_dependencies(clang-bootstrap-deps LTO)
510 # on Darwin we need to set DARWIN_LTO_LIBRARY so that -flto will work
511 # using the just-built compiler, and we need to override DYLD_LIBRARY_PATH
512 # so that the host object file tools will use the just-built libLTO.
513 # However if System Integrity Protection is enabled the DYLD variables
514 # will be scrubbed from the environment of any base system commands. This
515 # includes /bin/sh, which ninja uses when executing build commands. To
516 # work around the envar being filtered away we pass it in as a CMake
517 # variable, and have LLVM's CMake append the envar to the archiver calls.
518 set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib
519 -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR})
521 add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
522 if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR)
523 add_dependencies(clang-bootstrap-deps LLVMgold)
525 set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
526 set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
530 add_custom_target(${NEXT_CLANG_STAGE}-clear
531 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
534 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
535 DEPENDS clang-bootstrap-deps
536 COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
537 COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR}
538 COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
539 COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR}
540 COMMENT "Clobberring ${NEXT_CLANG_STAGE} build and stamp directories"
543 if(CMAKE_VERBOSE_MAKEFILE)
544 set(verbose -DCMAKE_VERBOSE_MAKEFILE=On)
547 set(_BOOTSTRAP_DEFAULT_PASSTHROUGH
555 CLANG_VERSION_PATCHLEVEL
558 CLANG_REPOSITORY_STRING
560 CMAKE_OSX_ARCHITECTURES)
562 # We don't need to depend on compiler-rt if we're building instrumented
563 # because the next stage will use the same compiler used to build this stage.
564 if(TARGET compiler-rt AND NOT LLVM_BUILD_INSTRUMENTED)
565 add_dependencies(clang-bootstrap-deps compiler-rt)
569 -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
570 -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
571 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
573 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
574 add_dependencies(clang-bootstrap-deps llvm-profdata)
575 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
578 if(LLVM_BUILD_INSTRUMENTED)
579 add_dependencies(clang-bootstrap-deps generate-profdata)
580 set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
581 # Use the current tools for LTO instead of the instrumented ones
582 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
591 set(COMPILER_OPTIONS)
597 # Find all variables that start with BOOTSTRAP_ and populate a variable with
599 get_cmake_property(variableNames VARIABLES)
600 foreach(variableName ${variableNames})
601 if(variableName MATCHES "^BOOTSTRAP_")
602 string(SUBSTRING ${variableName} 10 -1 varName)
603 string(REPLACE ";" "\;" value "${${variableName}}")
604 list(APPEND PASSTHROUGH_VARIABLES
605 -D${varName}=${value})
607 if(${variableName} AND variableName MATCHES "LLVM_EXTERNAL_.*_SOURCE_DIR")
608 list(APPEND PASSTHROUGH_VARIABLES
609 -D${variableName}=${${variableName}})
613 # Populate the passthrough variables
614 foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH})
615 if(DEFINED ${variableName})
616 if("${${variableName}}" STREQUAL "")
619 string(REPLACE ";" "\;" value ${${variableName}})
621 list(APPEND PASSTHROUGH_VARIABLES
622 -D${variableName}=${value})
626 ExternalProject_Add(${NEXT_CLANG_STAGE}
627 DEPENDS clang-bootstrap-deps
628 PREFIX ${NEXT_CLANG_STAGE}
629 SOURCE_DIR ${CMAKE_SOURCE_DIR}
630 STAMP_DIR ${STAMP_DIR}
631 BINARY_DIR ${BINARY_DIR}
634 # We shouldn't need to set this here, but INSTALL_DIR doesn't
635 # seem to work, so instead I'm passing this through
636 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
637 ${CLANG_BOOTSTRAP_CMAKE_ARGS}
638 ${PASSTHROUGH_VARIABLES}
639 -DCLANG_STAGE=${NEXT_CLANG_STAGE}
641 ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose} ${PGO_OPT}
643 STEP_TARGETS configure build
644 USES_TERMINAL_CONFIGURE 1
645 USES_TERMINAL_BUILD 1
646 USES_TERMINAL_INSTALL 1
649 # exclude really-install from main target
650 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On)
651 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install
652 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
653 COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'"
657 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install)
658 add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install)
660 if(NOT CLANG_BOOTSTRAP_TARGETS)
661 set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
663 foreach(target ${CLANG_BOOTSTRAP_TARGETS})
664 # exclude from main target
665 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
667 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
668 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
669 COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
674 if(target MATCHES "^stage[0-9]*")
675 add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target})
678 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target})
682 if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
683 add_subdirectory(utils/ClangVisualizers)