Chris Bieneman | f8ebfc4 | 2016-05-31 20:21:38 +0000 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.4.3) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 2 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 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 ) |
| 6 | project(Clang) |
| 7 | |
| 8 | # Rely on llvm-config. |
| 9 | set(CONFIG_OUTPUT) |
| 10 | find_program(LLVM_CONFIG "llvm-config") |
| 11 | if(LLVM_CONFIG) |
| 12 | message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}") |
| 13 | set(CONFIG_COMMAND ${LLVM_CONFIG} |
| 14 | "--assertion-mode" |
| 15 | "--bindir" |
| 16 | "--libdir" |
| 17 | "--includedir" |
| 18 | "--prefix" |
Michal Gorny | 8c5c7ff | 2017-01-09 23:06:39 +0000 | [diff] [blame] | 19 | "--src-root" |
| 20 | "--cmakedir") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 21 | execute_process( |
| 22 | COMMAND ${CONFIG_COMMAND} |
| 23 | RESULT_VARIABLE HAD_ERROR |
| 24 | OUTPUT_VARIABLE CONFIG_OUTPUT |
| 25 | ) |
| 26 | if(NOT HAD_ERROR) |
| 27 | string(REGEX REPLACE |
| 28 | "[ \t]*[\r\n]+[ \t]*" ";" |
| 29 | CONFIG_OUTPUT ${CONFIG_OUTPUT}) |
| 30 | else() |
| 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}") |
| 34 | endif() |
| 35 | else() |
| 36 | message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}") |
| 37 | endif() |
| 38 | |
| 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) |
NAKAMURA Takumi | a1c0f60 | 2017-02-13 14:59:53 +0000 | [diff] [blame] | 45 | list(GET CONFIG_OUTPUT 6 LLVM_CONFIG_CMAKE_PATH) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 46 | |
| 47 | if(NOT MSVC_IDE) |
| 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) |
| 52 | endif() |
| 53 | |
| 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") |
| 59 | |
NAKAMURA Takumi | a1c0f60 | 2017-02-13 14:59:53 +0000 | [diff] [blame] | 60 | # Normalize LLVM_CMAKE_PATH. --cmakedir might contain backslashes. |
| 61 | # CMake assumes slashes as PATH. |
NAKAMURA Takumi | 3cc0d4e | 2017-02-19 03:17:31 +0000 | [diff] [blame] | 62 | file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_PATH} LLVM_CMAKE_PATH) |
NAKAMURA Takumi | a1c0f60 | 2017-02-13 14:59:53 +0000 | [diff] [blame] | 63 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 64 | find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} |
| 65 | NO_DEFAULT_PATH) |
| 66 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 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}) |
| 71 | else() |
| 72 | message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}") |
| 73 | endif() |
| 74 | |
| 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}) |
| 78 | if(WIN32 OR CYGWIN) |
| 79 | # DLL platform -- put DLLs into bin. |
| 80 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) |
| 81 | else() |
| 82 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| 83 | endif() |
| 84 | |
Eric Fiselier | c14f3fb | 2017-03-07 00:15:18 +0000 | [diff] [blame] | 85 | option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 86 | option(LLVM_INSTALL_TOOLCHAIN_ONLY |
| 87 | "Only include toolchain files in the 'install' target." OFF) |
| 88 | |
| 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) |
| 92 | |
| 93 | include(AddLLVM) |
| 94 | include(TableGen) |
| 95 | include(HandleLLVMOptions) |
| 96 | include(VersionFromVCS) |
| 97 | |
| 98 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 99 | |
| 100 | if (NOT DEFINED LLVM_INCLUDE_TESTS) |
| 101 | set(LLVM_INCLUDE_TESTS ON) |
| 102 | endif() |
| 103 | |
| 104 | include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") |
| 105 | link_directories("${LLVM_LIBRARY_DIR}") |
| 106 | |
| 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} ) |
| 110 | |
| 111 | if(LLVM_INCLUDE_TESTS) |
| 112 | set(Python_ADDITIONAL_VERSIONS 2.7) |
| 113 | include(FindPythonInterp) |
| 114 | if(NOT PYTHONINTERP_FOUND) |
| 115 | message(FATAL_ERROR |
| 116 | "Unable to find Python interpreter, required for builds and testing. |
| 117 | |
| 118 | Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") |
| 119 | endif() |
| 120 | |
| 121 | if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) |
| 122 | message(FATAL_ERROR "Python 2.7 or newer is required") |
| 123 | endif() |
| 124 | |
| 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) |
| 130 | endif() |
| 131 | |
| 132 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
Michal Gorny | da6d2b8 | 2016-10-18 17:07:30 +0000 | [diff] [blame] | 133 | # Note: path not really used, except for checking if lit was found |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 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) |
| 141 | endif() |
| 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) |
| 147 | endif() |
| 148 | else() |
| 149 | # Seek installed Lit. |
Michal Gorny | da6d2b8 | 2016-10-18 17:07:30 +0000 | [diff] [blame] | 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") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 154 | endif() |
| 155 | |
| 156 | if(LLVM_LIT) |
| 157 | # Define the default arguments to use with 'lit', and an option for the user |
| 158 | # to override. |
| 159 | set(LIT_ARGS_DEFAULT "-sv") |
| 160 | if (MSVC OR XCODE) |
| 161 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 162 | endif() |
| 163 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 164 | |
| 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") |
| 168 | endif() |
| 169 | else() |
| 170 | set(LLVM_INCLUDE_TESTS OFF) |
| 171 | endif() |
| 172 | endif() |
| 173 | |
| 174 | set( CLANG_BUILT_STANDALONE 1 ) |
| 175 | set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}") |
| 176 | else() |
| 177 | set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}") |
| 178 | endif() |
| 179 | |
Michael Gottesman | ca589cc | 2016-07-09 21:58:40 +0000 | [diff] [blame] | 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") |
| 183 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 184 | find_package(LibXml2 2.5.3 QUIET) |
| 185 | if (LIBXML2_FOUND) |
| 186 | set(CLANG_HAVE_LIBXML 1) |
| 187 | endif() |
| 188 | |
Dominic Chen | 08f943c | 2017-04-04 19:52:25 +0000 | [diff] [blame] | 189 | find_package(Z3 4.5) |
| 190 | |
Chris Bieneman | a6b39ab | 2016-08-23 20:07:07 +0000 | [diff] [blame] | 191 | include(CheckIncludeFile) |
| 192 | check_include_file(sys/resource.h CLANG_HAVE_RLIMITS) |
| 193 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 194 | set(CLANG_RESOURCE_DIR "" CACHE STRING |
| 195 | "Relative directory from the Clang binary to its resource files.") |
| 196 | |
| 197 | set(C_INCLUDE_DIRS "" CACHE STRING |
| 198 | "Colon separated list of directories clang will search for headers.") |
| 199 | |
| 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>." ) |
| 203 | |
Rafael Espindola | 5ed89d4 | 2016-06-03 17:26:16 +0000 | [diff] [blame] | 204 | set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld") |
| 205 | |
Rafael Espindola | 557679f | 2016-06-20 23:54:44 +0000 | [diff] [blame] | 206 | set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL |
| 207 | "enable x86 relax relocations by default") |
| 208 | |
Petr Hosek | fe2c2b0 | 2016-12-14 16:46:50 +0000 | [diff] [blame] | 209 | set(CLANG_DEFAULT_LINKER "" CACHE STRING |
| 210 | "Default linker to use (linker name or absolute path, empty for platform default)") |
| 211 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 212 | set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING |
Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 213 | "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 214 | if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR |
| 215 | CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR |
| 216 | CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++")) |
Jonas Hahnfeld | ebf8662 | 2016-07-25 08:04:26 +0000 | [diff] [blame] | 217 | message(WARNING "Resetting default C++ stdlib to use platform default") |
Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 218 | set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING |
| 219 | "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE) |
| 220 | endif() |
| 221 | |
| 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) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 230 | endif() |
| 231 | |
| 232 | set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING |
| 233 | "Default OpenMP runtime used by -fopenmp.") |
| 234 | |
| 235 | set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING |
| 236 | "Vendor-specific text for showing with version information.") |
| 237 | |
| 238 | if( CLANG_VENDOR ) |
| 239 | add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " ) |
| 240 | endif() |
| 241 | |
| 242 | set(CLANG_REPOSITORY_STRING "" CACHE STRING |
| 243 | "Vendor-specific text for showing the repository the source is taken from.") |
| 244 | |
| 245 | if(CLANG_REPOSITORY_STRING) |
| 246 | add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}") |
| 247 | endif() |
| 248 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 249 | set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING |
| 250 | "Vendor-specific uti.") |
| 251 | |
| 252 | # The libdir suffix must exactly match whatever LLVM's configuration used. |
| 253 | set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}") |
| 254 | |
| 255 | set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 256 | set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 257 | |
| 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.") |
| 264 | endif() |
| 265 | |
| 266 | if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) |
| 267 | file(GLOB_RECURSE |
| 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.") |
| 275 | endif() |
| 276 | endif() |
| 277 | |
Chris Bieneman | ebfc680 | 2016-09-20 19:09:21 +0000 | [diff] [blame] | 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}) |
| 281 | endif() |
| 282 | if(NOT DEFINED CLANG_VERSION_MINOR) |
| 283 | set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 284 | endif() |
| 285 | if(NOT DEFINED CLANG_VERSION_PATCHLEVEL) |
| 286 | set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) |
| 287 | endif() |
David L. Jones | 2f75452 | 2016-09-15 22:12:26 +0000 | [diff] [blame] | 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}") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 290 | message(STATUS "Clang version: ${CLANG_VERSION}") |
| 291 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 292 | # Configure the Version.inc file. |
| 293 | configure_file( |
| 294 | ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in |
| 295 | ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc) |
| 296 | |
| 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") |
| 302 | endif () |
| 303 | |
| 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") |
| 307 | endif () |
| 308 | |
| 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" ) |
| 312 | endif() |
| 313 | endif () |
| 314 | |
| 315 | # Determine HOST_LINK_VERSION on Darwin. |
| 316 | set(HOST_LINK_VERSION) |
| 317 | if (APPLE) |
| 318 | set(LD_V_OUTPUT) |
| 319 | execute_process( |
| 320 | COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1" |
| 321 | RESULT_VARIABLE HAD_ERROR |
| 322 | OUTPUT_VARIABLE LD_V_OUTPUT |
| 323 | ) |
| 324 | if (NOT HAD_ERROR) |
| 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}) |
| 329 | endif() |
| 330 | else() |
| 331 | message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") |
| 332 | endif() |
| 333 | endif() |
| 334 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 335 | include(CMakeParseArguments) |
Michael Gottesman | ca589cc | 2016-07-09 21:58:40 +0000 | [diff] [blame] | 336 | include(AddClang) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 337 | |
| 338 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 339 | |
| 340 | include_directories(BEFORE |
| 341 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 342 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 343 | ) |
| 344 | |
| 345 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 346 | install(DIRECTORY include/clang include/clang-c |
| 347 | DESTINATION include |
| 348 | FILES_MATCHING |
| 349 | PATTERN "*.def" |
| 350 | PATTERN "*.h" |
| 351 | PATTERN "config.h" EXCLUDE |
| 352 | PATTERN ".svn" EXCLUDE |
| 353 | ) |
| 354 | |
| 355 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang |
| 356 | DESTINATION include |
| 357 | FILES_MATCHING |
| 358 | PATTERN "CMakeFiles" EXCLUDE |
| 359 | PATTERN "*.inc" |
| 360 | PATTERN "*.h" |
| 361 | ) |
| 362 | endif() |
| 363 | |
| 364 | add_definitions( -D_GNU_SOURCE ) |
| 365 | |
Michael Gottesman | eb396a6 | 2016-07-10 01:44:00 +0000 | [diff] [blame] | 366 | option(CLANG_BUILD_TOOLS |
| 367 | "Build the Clang tools. If OFF, just generate build targets." ON) |
| 368 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 369 | option(CLANG_ENABLE_ARCMT "Build ARCMT." ON) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 370 | option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 371 | |
Dominic Chen | 08f943c | 2017-04-04 19:52:25 +0000 | [diff] [blame] | 372 | option(CLANG_ANALYZER_BUILD_Z3 |
| 373 | "Build the static analyzer with the Z3 constraint manager." OFF) |
| 374 | |
| 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") |
| 377 | endif() |
| 378 | |
| 379 | if(CLANG_ANALYZER_BUILD_Z3) |
| 380 | if(Z3_FOUND) |
| 381 | set(CLANG_ANALYZER_WITH_Z3 1) |
| 382 | else() |
| 383 | message(FATAL_ERROR "Cannot find Z3 header file or shared library") |
| 384 | endif() |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 385 | endif() |
| 386 | |
| 387 | if(CLANG_ENABLE_ARCMT) |
| 388 | add_definitions(-DCLANG_ENABLE_ARCMT) |
| 389 | add_definitions(-DCLANG_ENABLE_OBJC_REWRITER) |
| 390 | endif() |
| 391 | if(CLANG_ENABLE_STATIC_ANALYZER) |
| 392 | add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER) |
| 393 | endif() |
| 394 | |
| 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) |
| 403 | |
| 404 | option(CLANG_INCLUDE_TESTS |
| 405 | "Generate build targets for the Clang unit tests." |
| 406 | ${LLVM_INCLUDE_TESTS}) |
| 407 | |
| 408 | add_subdirectory(utils/TableGen) |
| 409 | |
| 410 | add_subdirectory(include) |
| 411 | |
| 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}) |
| 415 | |
| 416 | add_subdirectory(lib) |
| 417 | add_subdirectory(tools) |
| 418 | add_subdirectory(runtime) |
| 419 | |
| 420 | option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 421 | add_subdirectory(examples) |
| 422 | |
Alexander Shaposhnikov | fd7afa7 | 2016-12-31 05:25:52 +0000 | [diff] [blame] | 423 | if(APPLE) |
| 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) |
| 429 | endif() |
| 430 | |
| 431 | |
| 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).") |
| 434 | |
| 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") |
| 439 | else() |
| 440 | message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.") |
| 441 | endif() |
| 442 | endif() |
| 443 | endif() |
| 444 | |
| 445 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 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 |
| 452 | ) |
| 453 | endif() |
| 454 | add_subdirectory(test) |
| 455 | |
| 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} |
| 469 | ) |
| 470 | endif() |
| 471 | add_subdirectory(utils/perf-training) |
| 472 | endif() |
| 473 | |
| 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) |
| 478 | endif() |
| 479 | |
Michael Gottesman | fe9d2d8 | 2016-06-29 20:22:44 +0000 | [diff] [blame] | 480 | add_subdirectory(cmake/modules) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 481 | |
Chris Bieneman | c486541 | 2016-07-25 18:54:30 +0000 | [diff] [blame] | 482 | if(CLANG_STAGE) |
| 483 | message(STATUS "Setting current clang stage to: ${CLANG_STAGE}") |
| 484 | endif() |
| 485 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 486 | if (CLANG_ENABLE_BOOTSTRAP) |
| 487 | include(ExternalProject) |
| 488 | |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 489 | add_custom_target(clang-bootstrap-deps DEPENDS clang) |
| 490 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 491 | if(NOT CLANG_STAGE) |
| 492 | set(CLANG_STAGE stage1) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 493 | endif() |
| 494 | |
| 495 | string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}") |
| 496 | if(MATCHED_STAGE) |
| 497 | if(NOT LLVM_BUILD_INSTRUMENTED) |
| 498 | math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1") |
| 499 | set(NEXT_CLANG_STAGE stage${STAGE_NUM}) |
| 500 | else() |
| 501 | set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1}) |
| 502 | endif() |
| 503 | else() |
| 504 | set(NEXT_CLANG_STAGE bootstrap) |
| 505 | endif() |
| 506 | |
| 507 | if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED) |
| 508 | set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented) |
| 509 | endif() |
| 510 | message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}") |
| 511 | |
| 512 | |
| 513 | set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/) |
| 514 | set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/) |
| 515 | |
Petr Hosek | 0320314 | 2017-01-18 05:41:17 +0000 | [diff] [blame] | 516 | if(BOOTSTRAP_LLVM_ENABLE_LLD) |
| 517 | add_dependencies(clang-bootstrap-deps lld) |
| 518 | endif() |
| 519 | |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 520 | # If the next stage is LTO we need to depend on LTO and possibly lld or LLVMgold |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 521 | if(BOOTSTRAP_LLVM_ENABLE_LTO OR LLVM_ENABLE_LTO AND NOT LLVM_BUILD_INSTRUMENTED) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 522 | if(APPLE) |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 523 | add_dependencies(clang-bootstrap-deps LTO) |
Chris Bieneman | 3104605 | 2016-04-27 18:52:48 +0000 | [diff] [blame] | 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. |
Chris Bieneman | d052efc | 2016-07-25 23:48:14 +0000 | [diff] [blame] | 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}) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 534 | elseif(NOT WIN32) |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 535 | add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib) |
Petr Hosek | 0320314 | 2017-01-18 05:41:17 +0000 | [diff] [blame] | 536 | if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR) |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 537 | add_dependencies(clang-bootstrap-deps LLVMgold) |
| 538 | endif() |
Chris Bieneman | 3104605 | 2016-04-27 18:52:48 +0000 | [diff] [blame] | 539 | set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar) |
| 540 | set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 541 | endif() |
| 542 | endif() |
| 543 | |
| 544 | add_custom_target(${NEXT_CLANG_STAGE}-clear |
| 545 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared |
| 546 | ) |
| 547 | add_custom_command( |
| 548 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 549 | DEPENDS clang-bootstrap-deps |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 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" |
| 555 | ) |
| 556 | |
| 557 | if(CMAKE_VERBOSE_MAKEFILE) |
| 558 | set(verbose -DCMAKE_VERBOSE_MAKEFILE=On) |
| 559 | endif() |
| 560 | |
Chris Bieneman | c486541 | 2016-07-25 18:54:30 +0000 | [diff] [blame] | 561 | set(_BOOTSTRAP_DEFAULT_PASSTHROUGH |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 562 | PACKAGE_VERSION |
Chris Bieneman | b137053 | 2016-10-18 00:50:20 +0000 | [diff] [blame] | 563 | PACKAGE_VENDOR |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 564 | LLVM_VERSION_MAJOR |
| 565 | LLVM_VERSION_MINOR |
| 566 | LLVM_VERSION_PATCH |
Chris Bieneman | 2c4d54f | 2016-09-21 20:43:43 +0000 | [diff] [blame] | 567 | CLANG_VERSION_MAJOR |
| 568 | CLANG_VERSION_MINOR |
| 569 | CLANG_VERSION_PATCHLEVEL |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 570 | LLVM_VERSION_SUFFIX |
| 571 | LLVM_BINUTILS_INCDIR |
| 572 | CLANG_REPOSITORY_STRING |
Chris Bieneman | b137053 | 2016-10-18 00:50:20 +0000 | [diff] [blame] | 573 | CMAKE_MAKE_PROGRAM |
| 574 | CMAKE_OSX_ARCHITECTURES) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 575 | |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 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) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 580 | endif() |
| 581 | |
| 582 | set(COMPILER_OPTIONS |
| 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) |
| 586 | |
| 587 | if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED) |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 588 | add_dependencies(clang-bootstrap-deps llvm-profdata) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 589 | set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata) |
| 590 | endif() |
| 591 | |
| 592 | if(LLVM_BUILD_INSTRUMENTED) |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 593 | add_dependencies(clang-bootstrap-deps generate-profdata) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 594 | set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata) |
Chris Bieneman | a1aa406 | 2016-08-16 22:16:29 +0000 | [diff] [blame] | 595 | # Use the current tools for LTO instead of the instrumented ones |
| 596 | list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH |
| 597 | CMAKE_CXX_COMPILER |
| 598 | CMAKE_C_COMPILER |
| 599 | CMAKE_ASM_COMPILER |
| 600 | CMAKE_AR |
| 601 | CMAKE_RANLIB |
| 602 | DARWIN_LTO_LIBRARY |
| 603 | DYLD_LIBRARY_PATH) |
| 604 | |
| 605 | set(COMPILER_OPTIONS) |
| 606 | set(LTO_LIBRARY) |
Chris Bieneman | a1aa406 | 2016-08-16 22:16:29 +0000 | [diff] [blame] | 607 | set(LTO_AR) |
| 608 | set(LTO_RANLIB) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 609 | endif() |
| 610 | |
| 611 | # Find all variables that start with BOOTSTRAP_ and populate a variable with |
| 612 | # them. |
| 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}) |
| 620 | endif() |
| 621 | if(${variableName} AND variableName MATCHES "LLVM_EXTERNAL_.*_SOURCE_DIR") |
| 622 | list(APPEND PASSTHROUGH_VARIABLES |
| 623 | -D${variableName}=${${variableName}}) |
| 624 | endif() |
| 625 | endforeach() |
| 626 | |
| 627 | # Populate the passthrough variables |
Chris Bieneman | c486541 | 2016-07-25 18:54:30 +0000 | [diff] [blame] | 628 | foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH}) |
Chris Bieneman | 43a601d | 2016-09-21 23:24:15 +0000 | [diff] [blame] | 629 | if(DEFINED ${variableName}) |
Chris Bieneman | 725acc4 | 2016-09-22 00:18:12 +0000 | [diff] [blame] | 630 | if("${${variableName}}" STREQUAL "") |
| 631 | set(value "") |
| 632 | else() |
| 633 | string(REPLACE ";" "\;" value ${${variableName}}) |
| 634 | endif() |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 635 | list(APPEND PASSTHROUGH_VARIABLES |
| 636 | -D${variableName}=${value}) |
| 637 | endif() |
| 638 | endforeach() |
| 639 | |
| 640 | ExternalProject_Add(${NEXT_CLANG_STAGE} |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 641 | DEPENDS clang-bootstrap-deps |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 642 | PREFIX ${NEXT_CLANG_STAGE} |
| 643 | SOURCE_DIR ${CMAKE_SOURCE_DIR} |
| 644 | STAMP_DIR ${STAMP_DIR} |
| 645 | BINARY_DIR ${BINARY_DIR} |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 646 | EXCLUDE_FROM_ALL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 647 | CMAKE_ARGS |
| 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} |
| 654 | ${COMPILER_OPTIONS} |
| 655 | ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose} ${PGO_OPT} |
| 656 | INSTALL_COMMAND "" |
| 657 | STEP_TARGETS configure build |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 658 | USES_TERMINAL_CONFIGURE 1 |
| 659 | USES_TERMINAL_BUILD 1 |
| 660 | USES_TERMINAL_INSTALL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 661 | ) |
| 662 | |
| 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 |
Chris Bieneman | d052efc | 2016-07-25 23:48:14 +0000 | [diff] [blame] | 666 | COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 667 | COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'" |
| 668 | DEPENDEES build |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 669 | USES_TERMINAL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 670 | ) |
| 671 | ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install) |
| 672 | add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install) |
| 673 | |
| 674 | if(NOT CLANG_BOOTSTRAP_TARGETS) |
| 675 | set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all) |
| 676 | endif() |
| 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) |
| 680 | |
| 681 | ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target} |
Chris Bieneman | d052efc | 2016-07-25 23:48:14 +0000 | [diff] [blame] | 682 | COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target} |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 683 | COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'" |
| 684 | DEPENDEES configure |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 685 | USES_TERMINAL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 686 | ) |
| 687 | |
| 688 | if(target MATCHES "^stage[0-9]*") |
| 689 | add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target}) |
| 690 | endif() |
| 691 | |
| 692 | ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target}) |
| 693 | endforeach() |
| 694 | endif() |
| 695 | |
| 696 | if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION) |
| 697 | add_subdirectory(utils/ClangVisualizers) |
| 698 | endif() |
Dominic Chen | 08f943c | 2017-04-04 19:52:25 +0000 | [diff] [blame] | 699 | |
| 700 | configure_file( |
| 701 | ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake |
| 702 | ${CLANG_BINARY_DIR}/include/clang/Config/config.h) |