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. |
| 62 | get_filename_component(LLVM_CMAKE_PATH ${LLVM_CONFIG_CMAKE_PATH} ABSOLUTE) |
| 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 | |
| 85 | option(LLVM_INSTALL_TOOLCHAIN_ONLY |
| 86 | "Only include toolchain files in the 'install' target." OFF) |
| 87 | |
| 88 | option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN |
| 89 | "Set to ON to force using an old, unsupported host toolchain." OFF) |
| 90 | option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF) |
| 91 | |
| 92 | include(AddLLVM) |
| 93 | include(TableGen) |
| 94 | include(HandleLLVMOptions) |
| 95 | include(VersionFromVCS) |
| 96 | |
| 97 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 98 | |
| 99 | if (NOT DEFINED LLVM_INCLUDE_TESTS) |
| 100 | set(LLVM_INCLUDE_TESTS ON) |
| 101 | endif() |
| 102 | |
| 103 | include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") |
| 104 | link_directories("${LLVM_LIBRARY_DIR}") |
| 105 | |
| 106 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) |
| 107 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 108 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 109 | |
| 110 | if(LLVM_INCLUDE_TESTS) |
| 111 | set(Python_ADDITIONAL_VERSIONS 2.7) |
| 112 | include(FindPythonInterp) |
| 113 | if(NOT PYTHONINTERP_FOUND) |
| 114 | message(FATAL_ERROR |
| 115 | "Unable to find Python interpreter, required for builds and testing. |
| 116 | |
| 117 | Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") |
| 118 | endif() |
| 119 | |
| 120 | if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) |
| 121 | message(FATAL_ERROR "Python 2.7 or newer is required") |
| 122 | endif() |
| 123 | |
| 124 | # Check prebuilt llvm/utils. |
| 125 | if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX} |
| 126 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX} |
| 127 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX}) |
| 128 | set(LLVM_UTILS_PROVIDED ON) |
| 129 | endif() |
| 130 | |
| 131 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
Michal Gorny | da6d2b8 | 2016-10-18 17:07:30 +0000 | [diff] [blame] | 132 | # Note: path not really used, except for checking if lit was found |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 133 | set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 134 | if(NOT LLVM_UTILS_PROVIDED) |
| 135 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck) |
| 136 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count) |
| 137 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not) |
| 138 | set(LLVM_UTILS_PROVIDED ON) |
| 139 | set(CLANG_TEST_DEPS FileCheck count not) |
| 140 | endif() |
| 141 | set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest) |
| 142 | if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h |
| 143 | AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 144 | AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt) |
| 145 | add_subdirectory(${UNITTEST_DIR} utils/unittest) |
| 146 | endif() |
| 147 | else() |
| 148 | # Seek installed Lit. |
Michal Gorny | da6d2b8 | 2016-10-18 17:07:30 +0000 | [diff] [blame] | 149 | find_program(LLVM_LIT |
| 150 | NAMES llvm-lit lit.py lit |
| 151 | PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit" |
| 152 | DOC "Path to lit.py") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 153 | endif() |
| 154 | |
| 155 | if(LLVM_LIT) |
| 156 | # Define the default arguments to use with 'lit', and an option for the user |
| 157 | # to override. |
| 158 | set(LIT_ARGS_DEFAULT "-sv") |
| 159 | if (MSVC OR XCODE) |
| 160 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 161 | endif() |
| 162 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 163 | |
| 164 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 165 | if( WIN32 AND NOT CYGWIN ) |
| 166 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 167 | endif() |
| 168 | else() |
| 169 | set(LLVM_INCLUDE_TESTS OFF) |
| 170 | endif() |
| 171 | endif() |
| 172 | |
| 173 | set( CLANG_BUILT_STANDALONE 1 ) |
| 174 | set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}") |
| 175 | else() |
| 176 | set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}") |
| 177 | endif() |
| 178 | |
Michael Gottesman | ca589cc | 2016-07-09 21:58:40 +0000 | [diff] [blame] | 179 | # Make sure that our source directory is on the current cmake module path so that |
| 180 | # we can include cmake files from this directory. |
| 181 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") |
| 182 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 183 | find_package(LibXml2 2.5.3 QUIET) |
| 184 | if (LIBXML2_FOUND) |
| 185 | set(CLANG_HAVE_LIBXML 1) |
| 186 | endif() |
| 187 | |
Chris Bieneman | a6b39ab | 2016-08-23 20:07:07 +0000 | [diff] [blame] | 188 | include(CheckIncludeFile) |
| 189 | check_include_file(sys/resource.h CLANG_HAVE_RLIMITS) |
| 190 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 191 | set(CLANG_RESOURCE_DIR "" CACHE STRING |
| 192 | "Relative directory from the Clang binary to its resource files.") |
| 193 | |
| 194 | set(C_INCLUDE_DIRS "" CACHE STRING |
| 195 | "Colon separated list of directories clang will search for headers.") |
| 196 | |
| 197 | set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." ) |
| 198 | set(DEFAULT_SYSROOT "" CACHE PATH |
| 199 | "Default <path> to all compiler invocations for --sysroot=<path>." ) |
| 200 | |
Rafael Espindola | 5ed89d4 | 2016-06-03 17:26:16 +0000 | [diff] [blame] | 201 | set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld") |
| 202 | |
Rafael Espindola | 557679f | 2016-06-20 23:54:44 +0000 | [diff] [blame] | 203 | set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL |
| 204 | "enable x86 relax relocations by default") |
| 205 | |
Petr Hosek | fe2c2b0 | 2016-12-14 16:46:50 +0000 | [diff] [blame] | 206 | set(CLANG_DEFAULT_LINKER "" CACHE STRING |
| 207 | "Default linker to use (linker name or absolute path, empty for platform default)") |
| 208 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 209 | set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING |
Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 210 | "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 211 | if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR |
| 212 | CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR |
| 213 | CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++")) |
Jonas Hahnfeld | ebf8662 | 2016-07-25 08:04:26 +0000 | [diff] [blame] | 214 | message(WARNING "Resetting default C++ stdlib to use platform default") |
Jonas Hahnfeld | d196fa5 | 2016-07-27 08:15:54 +0000 | [diff] [blame] | 215 | set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING |
| 216 | "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default" FORCE) |
| 217 | endif() |
| 218 | |
| 219 | set(CLANG_DEFAULT_RTLIB "" CACHE STRING |
| 220 | "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)") |
| 221 | if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR |
| 222 | CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR |
| 223 | CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt")) |
| 224 | message(WARNING "Resetting default rtlib to use platform default") |
| 225 | set(CLANG_DEFAULT_RTLIB "" CACHE STRING |
| 226 | "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] | 227 | endif() |
| 228 | |
| 229 | set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING |
| 230 | "Default OpenMP runtime used by -fopenmp.") |
| 231 | |
| 232 | set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING |
| 233 | "Vendor-specific text for showing with version information.") |
| 234 | |
| 235 | if( CLANG_VENDOR ) |
| 236 | add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " ) |
| 237 | endif() |
| 238 | |
| 239 | set(CLANG_REPOSITORY_STRING "" CACHE STRING |
| 240 | "Vendor-specific text for showing the repository the source is taken from.") |
| 241 | |
| 242 | if(CLANG_REPOSITORY_STRING) |
| 243 | add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}") |
| 244 | endif() |
| 245 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 246 | set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING |
| 247 | "Vendor-specific uti.") |
| 248 | |
| 249 | # The libdir suffix must exactly match whatever LLVM's configuration used. |
| 250 | set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}") |
| 251 | |
| 252 | set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 253 | set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 254 | |
| 255 | if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) |
| 256 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 257 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 258 | "from there, passing the path to this source directory as the last argument. " |
| 259 | "This process created the file `CMakeCache.txt' and the directory " |
| 260 | "`CMakeFiles'. Please delete them.") |
| 261 | endif() |
| 262 | |
| 263 | if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) |
| 264 | file(GLOB_RECURSE |
| 265 | tablegenned_files_on_include_dir |
| 266 | "${CLANG_SOURCE_DIR}/include/clang/*.inc") |
| 267 | if( tablegenned_files_on_include_dir ) |
| 268 | message(FATAL_ERROR "Apparently there is a previous in-source build, " |
| 269 | "probably as the result of running `configure' and `make' on " |
| 270 | "${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n" |
| 271 | "${tablegenned_files_on_include_dir}\nPlease clean the source directory.") |
| 272 | endif() |
| 273 | endif() |
| 274 | |
Chris Bieneman | ebfc680 | 2016-09-20 19:09:21 +0000 | [diff] [blame] | 275 | # If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*. |
| 276 | if(NOT DEFINED CLANG_VERSION_MAJOR) |
| 277 | set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) |
| 278 | endif() |
| 279 | if(NOT DEFINED CLANG_VERSION_MINOR) |
| 280 | set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 281 | endif() |
| 282 | if(NOT DEFINED CLANG_VERSION_PATCHLEVEL) |
| 283 | set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) |
| 284 | endif() |
David L. Jones | 2f75452 | 2016-09-15 22:12:26 +0000 | [diff] [blame] | 285 | # Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX. |
| 286 | set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}") |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 287 | message(STATUS "Clang version: ${CLANG_VERSION}") |
| 288 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 289 | # Configure the Version.inc file. |
| 290 | configure_file( |
| 291 | ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in |
| 292 | ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc) |
| 293 | |
| 294 | # Add appropriate flags for GCC |
| 295 | if (LLVM_COMPILER_IS_GCC_COMPATIBLE) |
| 296 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual") |
| 297 | if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 298 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") |
| 299 | endif () |
| 300 | |
| 301 | # Enable -pedantic for Clang even if it's not enabled for LLVM. |
| 302 | if (NOT LLVM_ENABLE_PEDANTIC) |
| 303 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long") |
| 304 | endif () |
| 305 | |
| 306 | check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG) |
| 307 | if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG ) |
| 308 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" ) |
| 309 | endif() |
| 310 | endif () |
| 311 | |
| 312 | # Determine HOST_LINK_VERSION on Darwin. |
| 313 | set(HOST_LINK_VERSION) |
| 314 | if (APPLE) |
| 315 | set(LD_V_OUTPUT) |
| 316 | execute_process( |
| 317 | COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1" |
| 318 | RESULT_VARIABLE HAD_ERROR |
| 319 | OUTPUT_VARIABLE LD_V_OUTPUT |
| 320 | ) |
| 321 | if (NOT HAD_ERROR) |
| 322 | if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*") |
| 323 | string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) |
| 324 | elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*") |
| 325 | string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) |
| 326 | endif() |
| 327 | else() |
| 328 | message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") |
| 329 | endif() |
| 330 | endif() |
| 331 | |
| 332 | configure_file( |
| 333 | ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake |
| 334 | ${CLANG_BINARY_DIR}/include/clang/Config/config.h) |
| 335 | |
| 336 | include(CMakeParseArguments) |
Michael Gottesman | ca589cc | 2016-07-09 21:58:40 +0000 | [diff] [blame] | 337 | include(AddClang) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 338 | |
| 339 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 340 | |
| 341 | include_directories(BEFORE |
| 342 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 343 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 344 | ) |
| 345 | |
| 346 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 347 | install(DIRECTORY include/clang include/clang-c |
| 348 | DESTINATION include |
| 349 | FILES_MATCHING |
| 350 | PATTERN "*.def" |
| 351 | PATTERN "*.h" |
| 352 | PATTERN "config.h" EXCLUDE |
| 353 | PATTERN ".svn" EXCLUDE |
| 354 | ) |
| 355 | |
| 356 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang |
| 357 | DESTINATION include |
| 358 | FILES_MATCHING |
| 359 | PATTERN "CMakeFiles" EXCLUDE |
| 360 | PATTERN "*.inc" |
| 361 | PATTERN "*.h" |
| 362 | ) |
| 363 | endif() |
| 364 | |
| 365 | add_definitions( -D_GNU_SOURCE ) |
| 366 | |
Michael Gottesman | eb396a6 | 2016-07-10 01:44:00 +0000 | [diff] [blame] | 367 | option(CLANG_BUILD_TOOLS |
| 368 | "Build the Clang tools. If OFF, just generate build targets." ON) |
| 369 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 370 | option(CLANG_ENABLE_ARCMT "Build ARCMT." ON) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 371 | option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 372 | |
| 373 | if (NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT) |
| 374 | message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT") |
| 375 | endif() |
| 376 | |
| 377 | if(CLANG_ENABLE_ARCMT) |
| 378 | add_definitions(-DCLANG_ENABLE_ARCMT) |
| 379 | add_definitions(-DCLANG_ENABLE_OBJC_REWRITER) |
| 380 | endif() |
| 381 | if(CLANG_ENABLE_STATIC_ANALYZER) |
| 382 | add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER) |
| 383 | endif() |
| 384 | |
| 385 | # Clang version information |
| 386 | set(CLANG_EXECUTABLE_VERSION |
| 387 | "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING |
| 388 | "Version number that will be placed into the clang executable, in the form XX.YY") |
| 389 | set(LIBCLANG_LIBRARY_VERSION |
| 390 | "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING |
| 391 | "Version number that will be placed into the libclang library , in the form XX.YY") |
| 392 | mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION) |
| 393 | |
| 394 | option(CLANG_INCLUDE_TESTS |
| 395 | "Generate build targets for the Clang unit tests." |
| 396 | ${LLVM_INCLUDE_TESTS}) |
| 397 | |
| 398 | add_subdirectory(utils/TableGen) |
| 399 | |
| 400 | add_subdirectory(include) |
| 401 | |
| 402 | # All targets below may depend on all tablegen'd files. |
| 403 | get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS) |
| 404 | list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS}) |
| 405 | |
| 406 | add_subdirectory(lib) |
| 407 | add_subdirectory(tools) |
| 408 | add_subdirectory(runtime) |
| 409 | |
| 410 | option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 411 | add_subdirectory(examples) |
| 412 | |
Alexander Shaposhnikov | fd7afa7 | 2016-12-31 05:25:52 +0000 | [diff] [blame] | 413 | if(APPLE) |
| 414 | # this line is needed as a cleanup to ensure that any CMakeCaches with the old |
| 415 | # default value get updated to the new default. |
| 416 | if(CLANG_ORDER_FILE STREQUAL "") |
| 417 | unset(CLANG_ORDER_FILE CACHE) |
| 418 | unset(CLANG_ORDER_FILE) |
| 419 | endif() |
| 420 | |
| 421 | |
| 422 | set(CLANG_ORDER_FILE ${CMAKE_CURRENT_BINARY_DIR}/clang.order CACHE FILEPATH |
| 423 | "Order file to use when compiling clang in order to improve startup time (Darwin Only - requires ld64).") |
| 424 | |
| 425 | if(NOT EXISTS ${CLANG_ORDER_FILE}) |
| 426 | string(FIND "${CLANG_ORDER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}" PATH_START) |
| 427 | if(PATH_START EQUAL 0) |
| 428 | file(WRITE ${CLANG_ORDER_FILE} "\n") |
| 429 | else() |
| 430 | message(FATAL_ERROR "Specified order file '${CLANG_ORDER_FILE}' does not exist.") |
| 431 | endif() |
| 432 | endif() |
| 433 | endif() |
| 434 | |
| 435 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 436 | if( CLANG_INCLUDE_TESTS ) |
| 437 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) |
| 438 | add_subdirectory(unittests) |
| 439 | list(APPEND CLANG_TEST_DEPS ClangUnitTests) |
| 440 | list(APPEND CLANG_TEST_PARAMS |
| 441 | clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg |
| 442 | ) |
| 443 | endif() |
| 444 | add_subdirectory(test) |
| 445 | |
| 446 | if(CLANG_BUILT_STANDALONE) |
| 447 | # Add a global check rule now that all subdirectories have been traversed |
| 448 | # and we know the total set of lit testsuites. |
| 449 | get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES) |
| 450 | get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS) |
| 451 | get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS) |
| 452 | get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS) |
| 453 | add_lit_target(check-all |
| 454 | "Running all regression tests" |
| 455 | ${LLVM_LIT_TESTSUITES} |
| 456 | PARAMS ${LLVM_LIT_PARAMS} |
| 457 | DEPENDS ${LLVM_LIT_DEPENDS} |
| 458 | ARGS ${LLVM_LIT_EXTRA_ARGS} |
| 459 | ) |
| 460 | endif() |
| 461 | add_subdirectory(utils/perf-training) |
| 462 | endif() |
| 463 | |
| 464 | option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs." |
| 465 | ${LLVM_INCLUDE_DOCS}) |
| 466 | if( CLANG_INCLUDE_DOCS ) |
| 467 | add_subdirectory(docs) |
| 468 | endif() |
| 469 | |
Michael Gottesman | fe9d2d8 | 2016-06-29 20:22:44 +0000 | [diff] [blame] | 470 | add_subdirectory(cmake/modules) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 471 | |
Chris Bieneman | c486541 | 2016-07-25 18:54:30 +0000 | [diff] [blame] | 472 | if(CLANG_STAGE) |
| 473 | message(STATUS "Setting current clang stage to: ${CLANG_STAGE}") |
| 474 | endif() |
| 475 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 476 | if (CLANG_ENABLE_BOOTSTRAP) |
| 477 | include(ExternalProject) |
| 478 | |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 479 | add_custom_target(clang-bootstrap-deps DEPENDS clang) |
| 480 | |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 481 | if(NOT CLANG_STAGE) |
| 482 | set(CLANG_STAGE stage1) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 483 | endif() |
| 484 | |
| 485 | string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}") |
| 486 | if(MATCHED_STAGE) |
| 487 | if(NOT LLVM_BUILD_INSTRUMENTED) |
| 488 | math(EXPR STAGE_NUM "${CMAKE_MATCH_1} + 1") |
| 489 | set(NEXT_CLANG_STAGE stage${STAGE_NUM}) |
| 490 | else() |
| 491 | set(NEXT_CLANG_STAGE stage${CMAKE_MATCH_1}) |
| 492 | endif() |
| 493 | else() |
| 494 | set(NEXT_CLANG_STAGE bootstrap) |
| 495 | endif() |
| 496 | |
| 497 | if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED) |
| 498 | set(NEXT_CLANG_STAGE ${NEXT_CLANG_STAGE}-instrumented) |
| 499 | endif() |
| 500 | message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}") |
| 501 | |
| 502 | |
| 503 | set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/) |
| 504 | set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/) |
| 505 | |
Petr Hosek | 0320314 | 2017-01-18 05:41:17 +0000 | [diff] [blame] | 506 | if(BOOTSTRAP_LLVM_ENABLE_LLD) |
| 507 | add_dependencies(clang-bootstrap-deps lld) |
| 508 | endif() |
| 509 | |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 510 | # 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] | 511 | 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] | 512 | if(APPLE) |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 513 | add_dependencies(clang-bootstrap-deps LTO) |
Chris Bieneman | 3104605 | 2016-04-27 18:52:48 +0000 | [diff] [blame] | 514 | # on Darwin we need to set DARWIN_LTO_LIBRARY so that -flto will work |
| 515 | # using the just-built compiler, and we need to override DYLD_LIBRARY_PATH |
| 516 | # 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] | 517 | # However if System Integrity Protection is enabled the DYLD variables |
| 518 | # will be scrubbed from the environment of any base system commands. This |
| 519 | # includes /bin/sh, which ninja uses when executing build commands. To |
| 520 | # work around the envar being filtered away we pass it in as a CMake |
| 521 | # variable, and have LLVM's CMake append the envar to the archiver calls. |
| 522 | set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib |
| 523 | -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 524 | elseif(NOT WIN32) |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 525 | add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib) |
Petr Hosek | 0320314 | 2017-01-18 05:41:17 +0000 | [diff] [blame] | 526 | if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR) |
Petr Hosek | 8e07a88 | 2016-11-16 23:59:06 +0000 | [diff] [blame] | 527 | add_dependencies(clang-bootstrap-deps LLVMgold) |
| 528 | endif() |
Chris Bieneman | 3104605 | 2016-04-27 18:52:48 +0000 | [diff] [blame] | 529 | set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar) |
| 530 | set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 531 | endif() |
| 532 | endif() |
| 533 | |
| 534 | add_custom_target(${NEXT_CLANG_STAGE}-clear |
| 535 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared |
| 536 | ) |
| 537 | add_custom_command( |
| 538 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 539 | DEPENDS clang-bootstrap-deps |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 540 | COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR} |
| 541 | COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR} |
| 542 | COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR} |
| 543 | COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR} |
| 544 | COMMENT "Clobberring ${NEXT_CLANG_STAGE} build and stamp directories" |
| 545 | ) |
| 546 | |
| 547 | if(CMAKE_VERBOSE_MAKEFILE) |
| 548 | set(verbose -DCMAKE_VERBOSE_MAKEFILE=On) |
| 549 | endif() |
| 550 | |
Chris Bieneman | c486541 | 2016-07-25 18:54:30 +0000 | [diff] [blame] | 551 | set(_BOOTSTRAP_DEFAULT_PASSTHROUGH |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 552 | PACKAGE_VERSION |
Chris Bieneman | b137053 | 2016-10-18 00:50:20 +0000 | [diff] [blame] | 553 | PACKAGE_VENDOR |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 554 | LLVM_VERSION_MAJOR |
| 555 | LLVM_VERSION_MINOR |
| 556 | LLVM_VERSION_PATCH |
Chris Bieneman | 2c4d54f | 2016-09-21 20:43:43 +0000 | [diff] [blame] | 557 | CLANG_VERSION_MAJOR |
| 558 | CLANG_VERSION_MINOR |
| 559 | CLANG_VERSION_PATCHLEVEL |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 560 | LLVM_VERSION_SUFFIX |
| 561 | LLVM_BINUTILS_INCDIR |
| 562 | CLANG_REPOSITORY_STRING |
Chris Bieneman | b137053 | 2016-10-18 00:50:20 +0000 | [diff] [blame] | 563 | CMAKE_MAKE_PROGRAM |
| 564 | CMAKE_OSX_ARCHITECTURES) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 565 | |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 566 | # We don't need to depend on compiler-rt if we're building instrumented |
| 567 | # because the next stage will use the same compiler used to build this stage. |
| 568 | if(TARGET compiler-rt AND NOT LLVM_BUILD_INSTRUMENTED) |
| 569 | add_dependencies(clang-bootstrap-deps compiler-rt) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 570 | endif() |
| 571 | |
| 572 | set(COMPILER_OPTIONS |
| 573 | -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++ |
| 574 | -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang |
| 575 | -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) |
| 576 | |
| 577 | if(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED) |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 578 | add_dependencies(clang-bootstrap-deps llvm-profdata) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 579 | set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata) |
| 580 | endif() |
| 581 | |
| 582 | if(LLVM_BUILD_INSTRUMENTED) |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 583 | add_dependencies(clang-bootstrap-deps generate-profdata) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 584 | 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] | 585 | # Use the current tools for LTO instead of the instrumented ones |
| 586 | list(APPEND _BOOTSTRAP_DEFAULT_PASSTHROUGH |
| 587 | CMAKE_CXX_COMPILER |
| 588 | CMAKE_C_COMPILER |
| 589 | CMAKE_ASM_COMPILER |
| 590 | CMAKE_AR |
| 591 | CMAKE_RANLIB |
| 592 | DARWIN_LTO_LIBRARY |
| 593 | DYLD_LIBRARY_PATH) |
| 594 | |
| 595 | set(COMPILER_OPTIONS) |
| 596 | set(LTO_LIBRARY) |
Chris Bieneman | a1aa406 | 2016-08-16 22:16:29 +0000 | [diff] [blame] | 597 | set(LTO_AR) |
| 598 | set(LTO_RANLIB) |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 599 | endif() |
| 600 | |
| 601 | # Find all variables that start with BOOTSTRAP_ and populate a variable with |
| 602 | # them. |
| 603 | get_cmake_property(variableNames VARIABLES) |
| 604 | foreach(variableName ${variableNames}) |
| 605 | if(variableName MATCHES "^BOOTSTRAP_") |
| 606 | string(SUBSTRING ${variableName} 10 -1 varName) |
| 607 | string(REPLACE ";" "\;" value "${${variableName}}") |
| 608 | list(APPEND PASSTHROUGH_VARIABLES |
| 609 | -D${varName}=${value}) |
| 610 | endif() |
| 611 | if(${variableName} AND variableName MATCHES "LLVM_EXTERNAL_.*_SOURCE_DIR") |
| 612 | list(APPEND PASSTHROUGH_VARIABLES |
| 613 | -D${variableName}=${${variableName}}) |
| 614 | endif() |
| 615 | endforeach() |
| 616 | |
| 617 | # Populate the passthrough variables |
Chris Bieneman | c486541 | 2016-07-25 18:54:30 +0000 | [diff] [blame] | 618 | foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${_BOOTSTRAP_DEFAULT_PASSTHROUGH}) |
Chris Bieneman | 43a601d | 2016-09-21 23:24:15 +0000 | [diff] [blame] | 619 | if(DEFINED ${variableName}) |
Chris Bieneman | 725acc4 | 2016-09-22 00:18:12 +0000 | [diff] [blame] | 620 | if("${${variableName}}" STREQUAL "") |
| 621 | set(value "") |
| 622 | else() |
| 623 | string(REPLACE ";" "\;" value ${${variableName}}) |
| 624 | endif() |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 625 | list(APPEND PASSTHROUGH_VARIABLES |
| 626 | -D${variableName}=${value}) |
| 627 | endif() |
| 628 | endforeach() |
| 629 | |
| 630 | ExternalProject_Add(${NEXT_CLANG_STAGE} |
Chris Bieneman | 76a2e60 | 2016-10-19 21:18:48 +0000 | [diff] [blame] | 631 | DEPENDS clang-bootstrap-deps |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 632 | PREFIX ${NEXT_CLANG_STAGE} |
| 633 | SOURCE_DIR ${CMAKE_SOURCE_DIR} |
| 634 | STAMP_DIR ${STAMP_DIR} |
| 635 | BINARY_DIR ${BINARY_DIR} |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 636 | EXCLUDE_FROM_ALL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 637 | CMAKE_ARGS |
| 638 | # We shouldn't need to set this here, but INSTALL_DIR doesn't |
| 639 | # seem to work, so instead I'm passing this through |
| 640 | -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} |
| 641 | ${CLANG_BOOTSTRAP_CMAKE_ARGS} |
| 642 | ${PASSTHROUGH_VARIABLES} |
| 643 | -DCLANG_STAGE=${NEXT_CLANG_STAGE} |
| 644 | ${COMPILER_OPTIONS} |
| 645 | ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose} ${PGO_OPT} |
| 646 | INSTALL_COMMAND "" |
| 647 | STEP_TARGETS configure build |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 648 | USES_TERMINAL_CONFIGURE 1 |
| 649 | USES_TERMINAL_BUILD 1 |
| 650 | USES_TERMINAL_INSTALL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 651 | ) |
| 652 | |
| 653 | # exclude really-install from main target |
| 654 | set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On) |
| 655 | ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install |
Chris Bieneman | d052efc | 2016-07-25 23:48:14 +0000 | [diff] [blame] | 656 | COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 657 | COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'" |
| 658 | DEPENDEES build |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 659 | USES_TERMINAL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 660 | ) |
| 661 | ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install) |
| 662 | add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install) |
| 663 | |
| 664 | if(NOT CLANG_BOOTSTRAP_TARGETS) |
| 665 | set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all) |
| 666 | endif() |
| 667 | foreach(target ${CLANG_BOOTSTRAP_TARGETS}) |
| 668 | # exclude from main target |
| 669 | set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On) |
| 670 | |
| 671 | ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target} |
Chris Bieneman | d052efc | 2016-07-25 23:48:14 +0000 | [diff] [blame] | 672 | COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target} |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 673 | COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'" |
| 674 | DEPENDEES configure |
Chris Bieneman | f325b8c | 2016-06-09 22:38:42 +0000 | [diff] [blame] | 675 | USES_TERMINAL 1 |
Mike Spertus | e9f15b4 | 2016-03-28 18:24:22 +0000 | [diff] [blame] | 676 | ) |
| 677 | |
| 678 | if(target MATCHES "^stage[0-9]*") |
| 679 | add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target}) |
| 680 | endif() |
| 681 | |
| 682 | ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target}) |
| 683 | endforeach() |
| 684 | endif() |
| 685 | |
| 686 | if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION) |
| 687 | add_subdirectory(utils/ClangVisualizers) |
| 688 | endif() |