blob: 3a5f9349678638e6a33a8f868671952bd5a1c3e9 [file] [log] [blame]
Chris Bienemanf8ebfc42016-05-31 20:21:381cmake_minimum_required(VERSION 3.4.3)
Mike Spertuse9f15b42016-03-28 18:24:222
Shoaib Meenaibb997f02018-11-08 00:29:333if(POLICY CMP0075)
4 cmake_policy(SET CMP0075 NEW)
5endif()
6
Mike Spertuse9f15b42016-03-28 18:24:227# If we are not building as a part of LLVM, build Clang as an
8# standalone project, using LLVM as an external library:
9if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
10 project(Clang)
11
12 # Rely on llvm-config.
13 set(CONFIG_OUTPUT)
Mike Spertuse9f15b42016-03-28 18:24:2214 if(LLVM_CONFIG)
Tom Stellarde4faa5c2018-11-13 03:42:4615 set (LLVM_CONFIG_FOUND 1)
Mike Spertuse9f15b42016-03-28 18:24:2216 message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
Tom Stellarde4faa5c2018-11-13 03:42:4617 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.")
Mike Spertuse9f15b42016-03-28 18:24:2222 set(CONFIG_COMMAND ${LLVM_CONFIG}
23 "--assertion-mode"
24 "--bindir"
25 "--libdir"
26 "--includedir"
27 "--prefix"
Michal Gorny8c5c7ff2017-01-09 23:06:3928 "--src-root"
29 "--cmakedir")
Mike Spertuse9f15b42016-03-28 18:24:2230 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()
Tom Stellarde4faa5c2018-11-13 03:42:4644
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)
Mike Spertuse9f15b42016-03-28 18:24:2256 endif()
57
Mike Spertuse9f15b42016-03-28 18:24:2258
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
Tom Stellarde4faa5c2018-11-13 03:42:4666 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})
Tom Stellardb8a9fcc2019-02-20 01:11:0578 # 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})
Tom Stellarde4faa5c2018-11-13 03:42:4683 endif()
84
Mike Spertuse9f15b42016-03-28 18:24:2285 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
Mike Spertuse9f15b42016-03-28 18:24:2294 # 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
Eric Fiselierc14f3fb2017-03-07 00:15:18104 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
Mike Spertuse9f15b42016-03-28 18:24:22105 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)
David Callahan63c77fd2018-11-29 14:57:14111 option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)
Mike Spertuse9f15b42016-03-28 18:24:22112
113 include(AddLLVM)
114 include(TableGen)
115 include(HandleLLVMOptions)
116 include(VersionFromVCS)
117
118 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
119
120 if (NOT DEFINED LLVM_INCLUDE_TESTS)
121 set(LLVM_INCLUDE_TESTS ON)
122 endif()
123
124 include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
125 link_directories("${LLVM_LIBRARY_DIR}")
126
127 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
128 set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
129 set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
130
131 if(LLVM_INCLUDE_TESTS)
132 set(Python_ADDITIONAL_VERSIONS 2.7)
133 include(FindPythonInterp)
134 if(NOT PYTHONINTERP_FOUND)
135 message(FATAL_ERROR
136"Unable to find Python interpreter, required for builds and testing.
137
138Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
139 endif()
140
141 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
142 message(FATAL_ERROR "Python 2.7 or newer is required")
143 endif()
144
145 # Check prebuilt llvm/utils.
146 if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
147 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
148 AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
149 set(LLVM_UTILS_PROVIDED ON)
150 endif()
151
152 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
Michal Gornyda6d2b82016-10-18 17:07:30153 # Note: path not really used, except for checking if lit was found
Mike Spertuse9f15b42016-03-28 18:24:22154 set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
Michal Gornyba996ab2017-11-17 22:21:23155 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
156 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
157 endif()
Mike Spertuse9f15b42016-03-28 18:24:22158 if(NOT LLVM_UTILS_PROVIDED)
159 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
160 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
161 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
162 set(LLVM_UTILS_PROVIDED ON)
163 set(CLANG_TEST_DEPS FileCheck count not)
164 endif()
165 set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
166 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
167 AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
168 AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
169 add_subdirectory(${UNITTEST_DIR} utils/unittest)
170 endif()
171 else()
172 # Seek installed Lit.
Michal Gornyda6d2b82016-10-18 17:07:30173 find_program(LLVM_LIT
174 NAMES llvm-lit lit.py lit
175 PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
176 DOC "Path to lit.py")
Mike Spertuse9f15b42016-03-28 18:24:22177 endif()
178
179 if(LLVM_LIT)
180 # Define the default arguments to use with 'lit', and an option for the user
181 # to override.
182 set(LIT_ARGS_DEFAULT "-sv")
183 if (MSVC OR XCODE)
184 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
185 endif()
186 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
187
188 # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
189 if( WIN32 AND NOT CYGWIN )
190 set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
191 endif()
192 else()
193 set(LLVM_INCLUDE_TESTS OFF)
194 endif()
195 endif()
196
197 set( CLANG_BUILT_STANDALONE 1 )
198 set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
199else()
200 set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
201endif()
202
Michael Gottesmanca589cc2016-07-09 21:58:40203# Make sure that our source directory is on the current cmake module path so that
204# we can include cmake files from this directory.
205list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
206
David Callahan63c77fd2018-11-29 14:57:14207if(LLVM_ENABLE_LIBXML2)
208 # Don't look for libxml if we're using MSan, since uninstrumented third party
209 # code may call MSan interceptors like strlen, leading to false positives.
210 if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
211 set (LIBXML2_FOUND 0)
212 find_package(LibXml2 2.5.3 QUIET)
213 if (LIBXML2_FOUND)
214 set(CLANG_HAVE_LIBXML 1)
215 endif()
Vitaly Buka3d8e5092017-09-02 03:53:42216 endif()
Mike Spertuse9f15b42016-03-28 18:24:22217endif()
218
Chris Bienemana6b39ab2016-08-23 20:07:07219include(CheckIncludeFile)
220check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
221
Mike Spertuse9f15b42016-03-28 18:24:22222set(CLANG_RESOURCE_DIR "" CACHE STRING
223 "Relative directory from the Clang binary to its resource files.")
224
225set(C_INCLUDE_DIRS "" CACHE STRING
226 "Colon separated list of directories clang will search for headers.")
227
228set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
229set(DEFAULT_SYSROOT "" CACHE PATH
230 "Default <path> to all compiler invocations for --sysroot=<path>." )
231
Rafael Espindola5ed89d42016-06-03 17:26:16232set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
233
Rafael Espindola557679f2016-06-20 23:54:44234set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL
235 "enable x86 relax relocations by default")
236
Petr Hosekc3aa97a2018-04-06 00:53:00237set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER FALSE CACHE BOOL
238 "Enable the experimental new pass manager by default.")
239
Michal Gorny4289f4c2018-03-06 21:26:28240# TODO: verify the values against LangStandards.def?
241set(CLANG_DEFAULT_STD_C "" CACHE STRING
242 "Default standard to use for C/ObjC code (IDENT from LangStandards.def, empty for platform default)")
243set(CLANG_DEFAULT_STD_CXX "" CACHE STRING
244 "Default standard to use for C++/ObjC++ code (IDENT from LangStandards.def, empty for platform default)")
245
Petr Hosekfe2c2b02016-12-14 16:46:50246set(CLANG_DEFAULT_LINKER "" CACHE STRING
247 "Default linker to use (linker name or absolute path, empty for platform default)")
248
Mike Spertuse9f15b42016-03-28 18:24:22249set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
Jonas Hahnfeldd196fa52016-07-27 08:15:54250 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default")
Mike Spertuse9f15b42016-03-28 18:24:22251if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR
252 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR
253 CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++"))
Jonas Hahnfeldebf86622016-07-25 08:04:26254 message(WARNING "Resetting default C++ stdlib to use platform default")
Jonas Hahnfeldd196fa52016-07-27 08:15:54255 set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
256 "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE)
257endif()
258
259set(CLANG_DEFAULT_RTLIB "" CACHE STRING
260 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)")
261if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
262 CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
263 CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
264 message(WARNING "Resetting default rtlib to use platform default")
265 set(CLANG_DEFAULT_RTLIB "" CACHE STRING
266 "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE)
Mike Spertuse9f15b42016-03-28 18:24:22267endif()
268
Sterling Augustine62716062019-03-19 20:01:59269set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING
270 "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)")
271if (CLANG_DEFAULT_UNWINDLIB STREQUAL "")
272 if (CLANG_DEFAULT_RTLIB STREQUAL "libgcc")
273 set (CLANG_DEFAULT_UNWINDLIB "libgcc" CACHE STRING "" FORCE)
274 elseif (CLANG_DEFAULT_RTLIBS STREQUAL "libunwind")
275 set (CLANG_DEFAULT_UNWINDLIB "none" CACHE STRING "" FORCE)
276 endif()
277endif()
278
Evandro Menezes7e8476d2019-03-25 16:38:48279if (NOT(CLANG_DEFAULT_UNWINDLIB STREQUAL "" OR
280 CLANG_DEFAULT_UNWINDLIB STREQUAL "none" OR
Sterling Augustine62716062019-03-19 20:01:59281 CLANG_DEFAULT_UNWINDLIB STREQUAL "libgcc" OR
282 CLANG_DEFAULT_UNWINDLIB STREQUAL "libunwind"))
283 message(WARNING "Resetting default unwindlib to use platform default")
284 set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING
285 "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty for none)" FORCE)
286endif()
287
Jake Ehrlichc451cf22017-11-11 01:15:41288set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING
289 "Default objcopy executable to use.")
290
Mike Spertuse9f15b42016-03-28 18:24:22291set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
292 "Default OpenMP runtime used by -fopenmp.")
293
George Rokos145c5472017-12-07 20:27:31294# OpenMP offloading requires at least sm_35 because we use shuffle instructions
295# to generate efficient code for reductions and the atomicMax instruction on
296# 64-bit integers in the implementation of conditional lastprivate.
297set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_35" CACHE STRING
Jonas Hahnfeld30b44182017-10-17 13:37:36298 "Default architecture for OpenMP offloading to Nvidia GPUs.")
299string(REGEX MATCH "^sm_([0-9]+)$" MATCHED_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}")
George Rokos145c5472017-12-07 20:27:31300if (NOT DEFINED MATCHED_ARCH OR "${CMAKE_MATCH_1}" LESS 35)
301 message(WARNING "Resetting default architecture for OpenMP offloading to Nvidia GPUs to sm_35")
302 set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_35" CACHE STRING
Jonas Hahnfeld30b44182017-10-17 13:37:36303 "Default architecture for OpenMP offloading to Nvidia GPUs." FORCE)
304endif()
305
Mike Spertuse9f15b42016-03-28 18:24:22306set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
307 "Vendor-specific text for showing with version information.")
308
309if( CLANG_VENDOR )
310 add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
311endif()
312
313set(CLANG_REPOSITORY_STRING "" CACHE STRING
314 "Vendor-specific text for showing the repository the source is taken from.")
315
316if(CLANG_REPOSITORY_STRING)
317 add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}")
318endif()
319
Mike Spertuse9f15b42016-03-28 18:24:22320set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
321 "Vendor-specific uti.")
322
Saleem Abdulrasoolf02e4f92018-08-20 22:50:18323set(CLANG_PYTHON_BINDINGS_VERSIONS "" CACHE STRING
324 "Python versions to install libclang python bindings for")
325
Mike Spertuse9f15b42016-03-28 18:24:22326# The libdir suffix must exactly match whatever LLVM's configuration used.
327set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
328
329set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
330set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
331
332if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
Stephen Kellya21cc1f2018-08-30 23:41:03333 message(FATAL_ERROR "In-source builds are not allowed. "
334"Please create a directory and run cmake "
Mike Spertuse9f15b42016-03-28 18:24:22335"from there, passing the path to this source directory as the last argument. "
336"This process created the file `CMakeCache.txt' and the directory "
337"`CMakeFiles'. Please delete them.")
338endif()
339
Chris Bienemanebfc6802016-09-20 19:09:21340# If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
341if(NOT DEFINED CLANG_VERSION_MAJOR)
342 set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
343endif()
344if(NOT DEFINED CLANG_VERSION_MINOR)
345 set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
346endif()
347if(NOT DEFINED CLANG_VERSION_PATCHLEVEL)
348 set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
349endif()
David L. Jones2f754522016-09-15 22:12:26350# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
351set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
Mike Spertuse9f15b42016-03-28 18:24:22352message(STATUS "Clang version: ${CLANG_VERSION}")
353
Mike Spertuse9f15b42016-03-28 18:24:22354# Configure the Version.inc file.
355configure_file(
356 ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
357 ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
358
359# Add appropriate flags for GCC
360if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
361 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
362 if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
363 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
364 endif ()
365
366 # Enable -pedantic for Clang even if it's not enabled for LLVM.
367 if (NOT LLVM_ENABLE_PEDANTIC)
368 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
369 endif ()
370
371 check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
372 if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
373 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
374 endif()
375endif ()
376
377# Determine HOST_LINK_VERSION on Darwin.
378set(HOST_LINK_VERSION)
379if (APPLE)
380 set(LD_V_OUTPUT)
381 execute_process(
382 COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
383 RESULT_VARIABLE HAD_ERROR
384 OUTPUT_VARIABLE LD_V_OUTPUT
385 )
386 if (NOT HAD_ERROR)
387 if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
388 string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
389 elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
390 string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
391 endif()
392 else()
393 message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
394 endif()
395endif()
396
Mike Spertuse9f15b42016-03-28 18:24:22397include(CMakeParseArguments)
Michael Gottesmanca589cc2016-07-09 21:58:40398include(AddClang)
Mike Spertuse9f15b42016-03-28 18:24:22399
400set(CMAKE_INCLUDE_CURRENT_DIR ON)
401
402include_directories(BEFORE
403 ${CMAKE_CURRENT_BINARY_DIR}/include
404 ${CMAKE_CURRENT_SOURCE_DIR}/include
405 )
406
407if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
408 install(DIRECTORY include/clang include/clang-c
409 DESTINATION include
Shoaib Meenai20e7c0c2019-03-11 18:53:57410 COMPONENT clang-headers
Mike Spertuse9f15b42016-03-28 18:24:22411 FILES_MATCHING
412 PATTERN "*.def"
413 PATTERN "*.h"
414 PATTERN "config.h" EXCLUDE
415 PATTERN ".svn" EXCLUDE
416 )
417
418 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
419 DESTINATION include
Shoaib Meenai20e7c0c2019-03-11 18:53:57420 COMPONENT clang-headers
Mike Spertuse9f15b42016-03-28 18:24:22421 FILES_MATCHING
422 PATTERN "CMakeFiles" EXCLUDE
423 PATTERN "*.inc"
424 PATTERN "*.h"
425 )
Yuka Takahashic8068db2017-05-23 18:39:08426
Shoaib Meenai20e7c0c2019-03-11 18:53:57427 # Installing the headers needs to depend on generating any public
428 # tablegen'd headers.
429 add_custom_target(clang-headers DEPENDS clang-tablegen-targets)
430 set_target_properties(clang-headers PROPERTIES FOLDER "Misc")
431 if(NOT LLVM_ENABLE_IDE)
432 add_llvm_install_targets(install-clang-headers
433 DEPENDS clang-headers
434 COMPONENT clang-headers)
435 endif()
436
Yuka Takahashic8068db2017-05-23 18:39:08437 install(PROGRAMS utils/bash-autocomplete.sh
438 DESTINATION share/clang
439 )
Mike Spertuse9f15b42016-03-28 18:24:22440endif()
441
442add_definitions( -D_GNU_SOURCE )
443
Michael Gottesmaneb396a62016-07-10 01:44:00444option(CLANG_BUILD_TOOLS
445 "Build the Clang tools. If OFF, just generate build targets." ON)
446
Mike Spertuse9f15b42016-03-28 18:24:22447option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
Mike Spertuse9f15b42016-03-28 18:24:22448option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
Mike Spertuse9f15b42016-03-28 18:24:22449
Matt Morehousef051f5d2017-08-08 20:15:04450option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF)
451
Mikhail R. Gadelhadb695c82019-03-25 17:47:45452if(NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
Dominic Chen08f943c2017-04-04 19:52:25453 message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT or Z3")
454endif()
455
Mike Spertuse9f15b42016-03-28 18:24:22456if(CLANG_ENABLE_ARCMT)
NAKAMURA Takumi7f633df2017-07-18 08:55:03457 set(CLANG_ENABLE_OBJC_REWRITER ON)
Mike Spertuse9f15b42016-03-28 18:24:22458endif()
459
460# Clang version information
461set(CLANG_EXECUTABLE_VERSION
Sylvestre Ledrua8b717f2018-03-29 10:05:46462 "${CLANG_VERSION_MAJOR}" CACHE STRING
463 "Major version number that will be appended to the clang executable name")
Mike Spertuse9f15b42016-03-28 18:24:22464set(LIBCLANG_LIBRARY_VERSION
Sylvestre Ledrua8b717f2018-03-29 10:05:46465 "${CLANG_VERSION_MAJOR}" CACHE STRING
466 "Major version number that will be appended to the libclang library")
Mike Spertuse9f15b42016-03-28 18:24:22467mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
468
469option(CLANG_INCLUDE_TESTS
470 "Generate build targets for the Clang unit tests."
471 ${LLVM_INCLUDE_TESTS})
472
473add_subdirectory(utils/TableGen)
474
475add_subdirectory(include)
476
477# All targets below may depend on all tablegen'd files.
478get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
Chris Bieneman6b5851b2017-07-28 15:33:47479add_custom_target(clang-tablegen-targets DEPENDS ${CLANG_TABLEGEN_TARGETS})
Aaron Ballman3f8bad82017-11-04 20:06:49480set_target_properties(clang-tablegen-targets PROPERTIES FOLDER "Misc")
Chris Bieneman6b5851b2017-07-28 15:33:47481list(APPEND LLVM_COMMON_DEPENDS clang-tablegen-targets)
Mike Spertuse9f15b42016-03-28 18:24:22482
NAKAMURA Takumi7ae667d2017-07-23 05:09:44483# Force target to be built as soon as possible. Clang modules builds depend
484# header-wise on it as they ship all headers from the umbrella folders. Building
485# an entire module might include header, which depends on intrinsics_gen.
486if(LLVM_ENABLE_MODULES AND NOT CLANG_BUILT_STANDALONE)
487 list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen)
488endif()
489
Mike Spertuse9f15b42016-03-28 18:24:22490add_subdirectory(lib)
491add_subdirectory(tools)
492add_subdirectory(runtime)
493
494option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
Mike Spertuse9f15b42016-03-28 18:24:22495add_subdirectory(examples)
496
Alexander Shaposhnikovfd7afa72016-12-31 05:25:52497if(APPLE)
498 # this line is needed as a cleanup to ensure that any CMakeCaches with the old
499 # default value get updated to the new default.
500 if(CLANG_ORDER_FILE STREQUAL "")
501 unset(CLANG_ORDER_FILE CACHE)
502 unset(CLANG_ORDER_FILE)
503 endif()
504
505
506 set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH
507 "Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).")
508
509 if(NOT EXISTS ${CLANG_ORDER_FILE})
510 string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START)
511 if(PATH_START EQUAL 0)
512 file(WRITE ${CLANG_ORDER_FILE} "\n")
513 else()
514 message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.")
515 endif()
516 endif()
517endif()
518
519
Mike Spertuse9f15b42016-03-28 18:24:22520if( CLANG_INCLUDE_TESTS )
521 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
522 add_subdirectory(unittests)
523 list(APPEND CLANG_TEST_DEPS ClangUnitTests)
524 list(APPEND CLANG_TEST_PARAMS
525 clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
526 )
527 endif()
528 add_subdirectory(test)
Michal Gorny61adf8a2018-10-11 16:32:54529 add_subdirectory(bindings/python/tests)
Mike Spertuse9f15b42016-03-28 18:24:22530
531 if(CLANG_BUILT_STANDALONE)
532 # Add a global check rule now that all subdirectories have been traversed
533 # and we know the total set of lit testsuites.
534 get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
535 get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
536 get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
537 get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
Michal Gorny61adf8a2018-10-11 16:32:54538 get_property(LLVM_ADDITIONAL_TEST_TARGETS
539 GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_TARGETS)
Mike Spertuse9f15b42016-03-28 18:24:22540 add_lit_target(check-all
541 "Running all regression tests"
542 ${LLVM_LIT_TESTSUITES}
543 PARAMS ${LLVM_LIT_PARAMS}
Michal Gorny61adf8a2018-10-11 16:32:54544 DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_TARGETS}
Mike Spertuse9f15b42016-03-28 18:24:22545 ARGS ${LLVM_LIT_EXTRA_ARGS}
546 )
547 endif()
548 add_subdirectory(utils/perf-training)
549endif()
550
551option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs."
552 ${LLVM_INCLUDE_DOCS})
553if( CLANG_INCLUDE_DOCS )
554 add_subdirectory(docs)
555endif()
556
Shoaib Meenaid7058642019-02-15 15:59:04557# Custom target to install all clang libraries.
558add_custom_target(clang-libraries)
559set_target_properties(clang-libraries PROPERTIES FOLDER "Misc")
560
Shoaib Meenaidefb5a32019-02-20 23:08:43561if(NOT LLVM_ENABLE_IDE)
Shoaib Meenaid7058642019-02-15 15:59:04562 add_llvm_install_targets(install-clang-libraries
563 DEPENDS clang-libraries
564 COMPONENT clang-libraries)
565endif()
566
567get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_LIBS)
568if(CLANG_LIBS)
569 list(REMOVE_DUPLICATES CLANG_LIBS)
570 foreach(lib ${CLANG_LIBS})
571 add_dependencies(clang-libraries ${lib})
Shoaib Meenaidefb5a32019-02-20 23:08:43572 if(NOT LLVM_ENABLE_IDE)
Shoaib Meenaid7058642019-02-15 15:59:04573 add_dependencies(install-clang-libraries install-${lib})
574 endif()
575 endforeach()
576endif()
577
Michael Gottesmanfe9d2d82016-06-29 20:22:44578add_subdirectory(cmake/modules)
Mike Spertuse9f15b42016-03-28 18:24:22579
Chris Bienemanc4865412016-07-25 18:54:30580if(CLANG_STAGE)
581 message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
582endif()
583
Mike Spertuse9f15b42016-03-28 18:24:22584if (CLANG_ENABLE_BOOTSTRAP)
585 include(ExternalProject)
586
Chris Bieneman76a2e602016-10-19 21:18:48587 add_custom_target(clang-bootstrap-deps DEPENDS clang)
588
Mike Spertuse9f15b42016-03-28 18:24:22589 if(NOT CLANG_STAGE)
590 set(CLANG_STAGE stage1)
Mike Spertuse9f15b42016-03-28 18:24:22591 endif()
592
593 string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
594 if(MATCHED_STAGE)
595 if(NOT LLVM_BUILD_INSTRUMENTED)
596 math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1")
597 set(NEXT_CLANG_STAGE stage${STAGE_NUM})
598 else()
599 set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1})
600 endif()
601 else()
602 set(NEXT_CLANG_STAGE bootstrap)
603 endif()
604
605 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
606 set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented)
607 endif()
608 message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}")
Jake Ehrlichc451cf22017-11-11 01:15:41609
610
Mike Spertuse9f15b42016-03-28 18:24:22611 set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/)
612 set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/)
613
Petr Hosek03203142017-01-18 05:41:17614 if(BOOTSTRAP_LLVM_ENABLE_LLD)
615 add_dependencies(clang-bootstrap-deps lld)
616 endif()
617
Petr Hosek8e07a882016-11-16 23:59:06618 # If the next stage is LTO we need to depend on LTO and possibly lld or LLVMgold
Chris Bieneman76a2e602016-10-19 21:18:48619 if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO AND NOT LLVM_BUILD_INSTRUMENTED)
Mike Spertuse9f15b42016-03-28 18:24:22620 if(APPLE)
Petr Hosek8e07a882016-11-16 23:59:06621 add_dependencies(clang-bootstrap-deps LTO)
Chris Bieneman31046052016-04-27 18:52:48622 # on Darwin we need to set DARWIN_LTO_LIBRARY so that -flto will work
623 # using the just-built compiler, and we need to override DYLD_LIBRARY_PATH
624 # so that the host object file tools will use the just-built libLTO.
Chris Bienemand052efc2016-07-25 23:48:14625 # However if System Integrity Protection is enabled the DYLD variables
626 # will be scrubbed from the environment of any base system commands. This
627 # includes /bin/sh, which ninja uses when executing build commands. To
628 # work around the envar being filtered away we pass it in as a CMake
629 # variable, and have LLVM's CMake append the envar to the archiver calls.
630 set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib
631 -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR})
Mike Spertuse9f15b42016-03-28 18:24:22632 elseif(NOT WIN32)
Petr Hosek8e07a882016-11-16 23:59:06633 add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
Petr Hosek03203142017-01-18 05:41:17634 if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR)
Petr Hosek8e07a882016-11-16 23:59:06635 add_dependencies(clang-bootstrap-deps LLVMgold)
636 endif()
Petr Hosekf8e27b32018-11-16 04:46:48637 set(${CLANG_STAGE}_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
638 set(${CLANG_STAGE}_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
Mike Spertuse9f15b42016-03-28 18:24:22639 endif()
640 endif()
641
Petr Hosek534a1042018-06-11 20:59:31642 if(CLANG_BOOTSTRAP_EXTRA_DEPS)
643 add_dependencies(clang-bootstrap-deps ${CLANG_BOOTSTRAP_EXTRA_DEPS})
644 endif()
645
Mike Spertuse9f15b42016-03-28 18:24:22646 add_custom_target(${NEXT_CLANG_STAGE}-clear
647 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
648 )
649 add_custom_command(
650 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
Chris Bieneman76a2e602016-10-19 21:18:48651 DEPENDS clang-bootstrap-deps
Mike Spertuse9f15b42016-03-28 18:24:22652 COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
653 COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR}
654 COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
655 COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR}
656 COMMENT "Clobberring ${NEXT_CLANG_STAGE} build and stamp directories"
657 )
658
659 if(CMAKE_VERBOSE_MAKEFILE)
660 set(verbose -DCMAKE_VERBOSE_MAKEFILE=On)
661 endif()
662
Chris Bienemanc4865412016-07-25 18:54:30663 set(_BOOTSTRAP_DEFAULT_PASSTHROUGH
Mike Spertuse9f15b42016-03-28 18:24:22664 PACKAGE_VERSION
Chris Bienemanb13705312016-10-18 00:50:20665 PACKAGE_VENDOR
Mike Spertuse9f15b42016-03-28 18:24:22666 LLVM_VERSION_MAJOR
667 LLVM_VERSION_MINOR
668 LLVM_VERSION_PATCH
Chris Bieneman2c4d54f2016-09-21 20:43:43669 CLANG_VERSION_MAJOR
670 CLANG_VERSION_MINOR
671 CLANG_VERSION_PATCHLEVEL
Mike Spertuse9f15b42016-03-28 18:24:22672 LLVM_VERSION_SUFFIX
673 LLVM_BINUTILS_INCDIR
674 CLANG_REPOSITORY_STRING
JF Bastien2e754722019-03-06 20:36:00675 CMAKE_C_COMPILER_LAUNCHER
676 CMAKE_CXX_COMPILER_LAUNCHER
Chris Bienemanb13705312016-10-18 00:50:20677 CMAKE_MAKE_PROGRAM
Petr Hosekd32e51e2017-11-29 00:34:46678 CMAKE_OSX_ARCHITECTURES
679 LLVM_ENABLE_PROJECTS
680 LLVM_ENABLE_RUNTIMES)
Mike Spertuse9f15b42016-03-28 18:24:22681
Ahmed Bougacha8b597882018-06-28 18:35:25682 # We don't need to depend on compiler-rt/libcxx if we're building instrumented
Chris Bieneman76a2e602016-10-19 21:18:48683 # because the next stage will use the same compiler used to build this stage.
Ahmed Bougacha8b597882018-06-28 18:35:25684 if(NOT LLVM_BUILD_INSTRUMENTED)
685 if(TARGET compiler-rt)
686 add_dependencies(clang-bootstrap-deps compiler-rt)
687 endif()
688 if(TARGET cxx-headers)
689 add_dependencies(clang-bootstrap-deps cxx-headers)
690 endif()
Mike Spertuse9f15b42016-03-28 18:24:22691 endif()
692
NAKAMURA Takumi25f1a6e2017-05-11 13:19:24693 set(C_COMPILER "clang")
694 set(CXX_COMPILER "clang++")
695 if(WIN32)
696 set(C_COMPILER "clang-cl.exe")
697 set(CXX_COMPILER "clang-cl.exe")
698 endif()
699
Mike Spertuse9f15b42016-03-28 18:24:22700 set(COMPILER_OPTIONS
NAKAMURA Takumi25f1a6e2017-05-11 13:19:24701 -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${CXX_COMPILER}
702 -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
Don Hinton976f0512018-01-19 18:31:12703 -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER}
704 -DCMAKE_ASM_COMPILER_ID=Clang)
Mike Spertuse9f15b42016-03-28 18:24:22705
Petr Hosekf8e27b32018-11-16 04:46:48706 if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
707 set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config)
708 set(${CLANG_STAGE}_TABLEGEN
709 -DLLVM_TABLEGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-tblgen
710 -DCLANG_TABLEGEN=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-tblgen)
711 if(BOOTSTRAP_CMAKE_SYSTEM_NAME STREQUAL "Linux")
712 if(BOOTSTRAP_LLVM_ENABLE_LLD)
713 set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld)
714 endif()
715 if(NOT BOOTSTRAP_LLVM_ENABLE_LTO)
716 add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
717 set(${CLANG_STAGE}_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
718 set(${CLANG_STAGE}_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
719 endif()
720 add_dependencies(clang-bootstrap-deps llvm-objcopy llvm-strip)
721 set(${CLANG_STAGE}_OBJCOPY -DCMAKE_OBJCOPY=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-objcopy)
722 set(${CLANG_STAGE}_STRIP -DCMAKE_STRIP=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-strip)
723 endif()
724 endif()
725
Mike Spertuse9f15b42016-03-28 18:24:22726 if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED)
Chris Bieneman76a2e602016-10-19 21:18:48727 add_dependencies(clang-bootstrap-deps llvm-profdata)
Mike Spertuse9f15b42016-03-28 18:24:22728 set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
729 endif()
730
731 if(LLVM_BUILD_INSTRUMENTED)
Chris Bieneman76a2e602016-10-19 21:18:48732 add_dependencies(clang-bootstrap-deps generate-profdata)
Mike Spertuse9f15b42016-03-28 18:24:22733 set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
Chris Bienemana1aa4062016-08-16 22:16:29734 # Use the current tools for LTO instead of the instrumented ones
735 list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH
736 CMAKE_CXX_COMPILER
737 CMAKE_C_COMPILER
738 CMAKE_ASM_COMPILER
739 CMAKE_AR
740 CMAKE_RANLIB
741 DARWIN_LTO_LIBRARY
742 DYLD_LIBRARY_PATH)
743
744 set(COMPILER_OPTIONS)
745 set(LTO_LIBRARY)
Chris Bienemana1aa4062016-08-16 22:16:29746 set(LTO_AR)
747 set(LTO_RANLIB)
Mike Spertuse9f15b42016-03-28 18:24:22748 endif()
749
750 # Find all variables that start with BOOTSTRAP_ and populate a variable with
751 # them.
752 get_cmake_property(variableNames VARIABLES)
753 foreach(variableName ${variableNames})
754 if(variableName MATCHES "^BOOTSTRAP_")
755 string(SUBSTRING ${variableName} 10 -1 varName)
Petr Hosek5a34c342017-12-05 00:15:20756 string(REPLACE ";" "|" value "${${variableName}}")
Mike Spertuse9f15b42016-03-28 18:24:22757 list(APPEND PASSTHROUGH_VARIABLES
758 -D${varName}=${value})
759 endif()
760 if(${variableName} AND variableName MATCHES "LLVM_EXTERNAL_.*_SOURCE_DIR")
761 list(APPEND PASSTHROUGH_VARIABLES
762 -D${variableName}=${${variableName}})
763 endif()
764 endforeach()
765
766 # Populate the passthrough variables
Chris Bienemanc4865412016-07-25 18:54:30767 foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH})
Chris Bieneman43a601d2016-09-21 23:24:15768 if(DEFINED ${variableName})
Chris Bieneman725acc42016-09-22 00:18:12769 if("${${variableName}}" STREQUAL "")
770 set(value "")
771 else()
Petr Hosek5a34c342017-12-05 00:15:20772 string(REPLACE ";" "|" value "${${variableName}}")
Chris Bieneman725acc42016-09-22 00:18:12773 endif()
Mike Spertuse9f15b42016-03-28 18:24:22774 list(APPEND PASSTHROUGH_VARIABLES
775 -D${variableName}=${value})
776 endif()
777 endforeach()
778
779 ExternalProject_Add(${NEXT_CLANG_STAGE}
Chris Bieneman76a2e602016-10-19 21:18:48780 DEPENDS clang-bootstrap-deps
Mike Spertuse9f15b42016-03-28 18:24:22781 PREFIX ${NEXT_CLANG_STAGE}
782 SOURCE_DIR ${CMAKE_SOURCE_DIR}
783 STAMP_DIR ${STAMP_DIR}
784 BINARY_DIR ${BINARY_DIR}
Chris Bienemanf325b8c2016-06-09 22:38:42785 EXCLUDE_FROM_ALL 1
Mike Spertuse9f15b42016-03-28 18:24:22786 CMAKE_ARGS
787 # We shouldn't need to set this here, but INSTALL_DIR doesn't
788 # seem to work, so instead I'm passing this through
789 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
790 ${CLANG_BOOTSTRAP_CMAKE_ARGS}
791 ${PASSTHROUGH_VARIABLES}
792 -DCLANG_STAGE=${NEXT_CLANG_STAGE}
793 ${COMPILER_OPTIONS}
Petr Hosekf8e27b32018-11-16 04:46:48794 ${${CLANG_STAGE}_CONFIG}
795 ${${CLANG_STAGE}_TABLEGEN}
796 ${LTO_LIBRARY} ${verbose} ${PGO_OPT}
797 ${${CLANG_STAGE}_LINKER}
798 ${${CLANG_STAGE}_AR}
799 ${${CLANG_STAGE}_RANLIB}
800 ${${CLANG_STAGE}_OBJCOPY}
801 ${${CLANG_STAGE}_STRIP}
Mike Spertuse9f15b42016-03-28 18:24:22802 INSTALL_COMMAND ""
803 STEP_TARGETS configure build
Chris Bienemanf325b8c2016-06-09 22:38:42804 USES_TERMINAL_CONFIGURE 1
805 USES_TERMINAL_BUILD 1
806 USES_TERMINAL_INSTALL 1
Petr Hosek5a34c342017-12-05 00:15:20807 LIST_SEPARATOR |
Mike Spertuse9f15b42016-03-28 18:24:22808 )
809
810 # exclude really-install from main target
811 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On)
812 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install
Chris Bienemand052efc2016-07-25 23:48:14813 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
Mike Spertuse9f15b42016-03-28 18:24:22814 COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'"
815 DEPENDEES build
Chris Bienemanf325b8c2016-06-09 22:38:42816 USES_TERMINAL 1
Mike Spertuse9f15b42016-03-28 18:24:22817 )
818 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install)
819 add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install)
820
821 if(NOT CLANG_BOOTSTRAP_TARGETS)
822 set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
823 endif()
824 foreach(target ${CLANG_BOOTSTRAP_TARGETS})
825 # exclude from main target
826 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
827
828 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
Chris Bienemand052efc2016-07-25 23:48:14829 COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
Mike Spertuse9f15b42016-03-28 18:24:22830 COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
831 DEPENDEES configure
Chris Bienemanf325b8c2016-06-09 22:38:42832 USES_TERMINAL 1
Mike Spertuse9f15b42016-03-28 18:24:22833 )
834
835 if(target MATCHES "^stage[0-9]*")
836 add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target})
837 endif()
838
839 ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target})
840 endforeach()
841endif()
842
843if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
844 add_subdirectory(utils/ClangVisualizers)
845endif()
Bruno Cardoso Lopesdc3f88a2018-06-21 21:45:24846add_subdirectory(utils/hmaptool)
Dominic Chen08f943c2017-04-04 19:52:25847
848configure_file(
849 ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
850 ${CLANG_BINARY_DIR}/include/clang/Config/config.h)