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