Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 1 | # See docs/CMake.html for instructions about how to build LLVM with CMake. |
| 2 | |
Chris Bieneman | b471191 | 2016-05-31 20:21:32 +0000 | [diff] [blame] | 3 | cmake_minimum_required(VERSION 3.4.3) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 4 | |
| 5 | if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 6 | message(STATUS "No build type selected, default to Debug") |
| 7 | set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)") |
| 8 | endif() |
| 9 | |
| 10 | if(POLICY CMP0022) |
| 11 | cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required |
| 12 | endif() |
| 13 | |
| 14 | if (POLICY CMP0051) |
| 15 | # CMake 3.1 and higher include generator expressions of the form |
| 16 | # $<TARGETLIB:obj> in the SOURCES property. These need to be |
| 17 | # stripped everywhere that access the SOURCES property, so we just |
| 18 | # defer to the OLD behavior of not including generator expressions |
| 19 | # in the output for now. |
| 20 | cmake_policy(SET CMP0051 OLD) |
| 21 | endif() |
| 22 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 23 | if(NOT DEFINED LLVM_VERSION_MAJOR) |
Hans Wennborg | c714d7c | 2016-07-18 17:51:04 +0000 | [diff] [blame] | 24 | set(LLVM_VERSION_MAJOR 4) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 25 | endif() |
| 26 | if(NOT DEFINED LLVM_VERSION_MINOR) |
Hans Wennborg | c714d7c | 2016-07-18 17:51:04 +0000 | [diff] [blame] | 27 | set(LLVM_VERSION_MINOR 0) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 28 | endif() |
| 29 | if(NOT DEFINED LLVM_VERSION_PATCH) |
| 30 | set(LLVM_VERSION_PATCH 0) |
| 31 | endif() |
| 32 | if(NOT DEFINED LLVM_VERSION_SUFFIX) |
| 33 | set(LLVM_VERSION_SUFFIX svn) |
| 34 | endif() |
| 35 | |
| 36 | if (POLICY CMP0048) |
| 37 | cmake_policy(SET CMP0048 NEW) |
| 38 | set(cmake_3_0_PROJ_VERSION |
| 39 | VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}) |
| 40 | set(cmake_3_0_LANGUAGES LANGUAGES) |
| 41 | endif() |
| 42 | |
| 43 | if (NOT PACKAGE_VERSION) |
| 44 | set(PACKAGE_VERSION |
| 45 | "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}") |
| 46 | endif() |
| 47 | |
| 48 | project(LLVM |
| 49 | ${cmake_3_0_PROJ_VERSION} |
| 50 | ${cmake_3_0_LANGUAGES} |
| 51 | C CXX ASM) |
| 52 | |
Chris Bieneman | 6108658 | 2016-04-28 20:14:19 +0000 | [diff] [blame] | 53 | if(APPLE) |
| 54 | if(NOT CMAKE_LIBTOOL) |
| 55 | find_program(CMAKE_LIBTOOL NAMES libtool) |
| 56 | endif() |
| 57 | if(CMAKE_LIBTOOL) |
| 58 | set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable") |
| 59 | message(STATUS "Found libtool - ${CMAKE_LIBTOOL}") |
| 60 | get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) |
| 61 | foreach(lang ${languages}) |
| 62 | set(CMAKE_${lang}_CREATE_STATIC_LIBRARY |
| 63 | "${CMAKE_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ") |
| 64 | endforeach() |
| 65 | endif() |
| 66 | endif() |
| 67 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 68 | # The following only works with the Ninja generator in CMake >= 3.0. |
| 69 | set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING |
| 70 | "Define the maximum number of concurrent compilation jobs.") |
| 71 | if(LLVM_PARALLEL_COMPILE_JOBS) |
Chris Bieneman | 35c7f96 | 2016-06-08 22:38:30 +0000 | [diff] [blame] | 72 | if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja") |
| 73 | message(WARNING "Job pooling is only available with Ninja generators.") |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 74 | else() |
| 75 | set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS}) |
| 76 | set(CMAKE_JOB_POOL_COMPILE compile_job_pool) |
| 77 | endif() |
| 78 | endif() |
| 79 | |
Quentin Colombet | c8df88c | 2016-07-21 17:26:45 +0000 | [diff] [blame] | 80 | option(LLVM_BUILD_GLOBAL_ISEL "Experimental: Build GlobalISel" OFF) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 81 | if(LLVM_BUILD_GLOBAL_ISEL) |
| 82 | add_definitions(-DLLVM_BUILD_GLOBAL_ISEL) |
| 83 | endif() |
| 84 | |
| 85 | set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING |
| 86 | "Define the maximum number of concurrent link jobs.") |
| 87 | if(LLVM_PARALLEL_LINK_JOBS) |
Chris Bieneman | 35c7f96 | 2016-06-08 22:38:30 +0000 | [diff] [blame] | 88 | if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja") |
| 89 | message(WARNING "Job pooling is only available with Ninja generators.") |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 90 | else() |
| 91 | set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS}) |
| 92 | set(CMAKE_JOB_POOL_LINK link_job_pool) |
| 93 | endif() |
| 94 | endif() |
| 95 | |
| 96 | # Add path for custom modules |
| 97 | set(CMAKE_MODULE_PATH |
| 98 | ${CMAKE_MODULE_PATH} |
| 99 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 100 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" |
| 101 | ) |
| 102 | |
| 103 | # Generate a CompilationDatabase (compile_commands.json file) for our build, |
| 104 | # for use by clang_complete, YouCompleteMe, etc. |
| 105 | set(CMAKE_EXPORT_COMPILE_COMMANDS 1) |
| 106 | |
| 107 | option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF) |
| 108 | |
| 109 | option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF) |
| 110 | |
| 111 | option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON) |
| 112 | if ( LLVM_USE_FOLDERS ) |
| 113 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 114 | endif() |
| 115 | |
| 116 | include(VersionFromVCS) |
| 117 | |
| 118 | option(LLVM_APPEND_VC_REV |
| 119 | "Append the version control system revision id to LLVM version" OFF) |
| 120 | |
| 121 | if( LLVM_APPEND_VC_REV ) |
| 122 | add_version_info_from_vcs(PACKAGE_VERSION) |
| 123 | endif() |
| 124 | |
| 125 | set(PACKAGE_NAME LLVM) |
| 126 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| 127 | set(PACKAGE_BUGREPORT "http://llvm.org/bugs/") |
| 128 | |
| 129 | set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING |
| 130 | "Default URL where bug reports are to be submitted.") |
| 131 | |
| 132 | # Configure CPack. |
| 133 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM") |
| 134 | set(CPACK_PACKAGE_VENDOR "LLVM") |
| 135 | set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) |
| 136 | set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 137 | set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH}) |
| 138 | set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) |
| 139 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT") |
| 140 | set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32") |
| 141 | if(WIN32 AND NOT UNIX) |
| 142 | set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM") |
| 143 | set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp") |
| 144 | set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico") |
| 145 | set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico") |
| 146 | set(CPACK_NSIS_MODIFY_PATH "ON") |
| 147 | set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON") |
| 148 | set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS |
| 149 | "ExecWait '$INSTDIR/tools/msbuild/install.bat'") |
| 150 | set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS |
| 151 | "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'") |
| 152 | if( CMAKE_CL_64 ) |
| 153 | set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") |
| 154 | endif() |
| 155 | endif() |
| 156 | include(CPack) |
| 157 | |
| 158 | # Sanity check our source directory to make sure that we are not trying to |
| 159 | # generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make |
| 160 | # sure that we don't have any stray generated files lying around in the tree |
| 161 | # (which would end up getting picked up by header search, instead of the correct |
| 162 | # versions). |
| 163 | if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) |
| 164 | message(FATAL_ERROR "In-source builds are not allowed. |
| 165 | CMake would overwrite the makefiles distributed with LLVM. |
| 166 | Please create a directory and run cmake from there, passing the path |
| 167 | to this source directory as the last argument. |
| 168 | This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. |
| 169 | Please delete them.") |
| 170 | endif() |
| 171 | if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) |
| 172 | file(GLOB_RECURSE |
| 173 | tablegenned_files_on_include_dir |
| 174 | "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen") |
| 175 | file(GLOB_RECURSE |
| 176 | tablegenned_files_on_lib_dir |
| 177 | "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc") |
| 178 | if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir) |
| 179 | message(FATAL_ERROR "Apparently there is a previous in-source build, |
| 180 | probably as the result of running `configure' and `make' on |
| 181 | ${CMAKE_CURRENT_SOURCE_DIR}. |
| 182 | This may cause problems. The suspicious files are: |
| 183 | ${tablegenned_files_on_lib_dir} |
| 184 | ${tablegenned_files_on_include_dir} |
| 185 | Please clean the source directory.") |
| 186 | endif() |
| 187 | endif() |
| 188 | |
| 189 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 190 | |
| 191 | if (CMAKE_BUILD_TYPE AND |
| 192 | NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$") |
| 193 | message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") |
| 194 | endif() |
| 195 | |
| 196 | set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) |
| 197 | |
Chris Bieneman | 2724f14 | 2016-06-08 21:19:26 +0000 | [diff] [blame] | 198 | set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") |
| 199 | mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) |
| 200 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 201 | # They are used as destination of target generators. |
| 202 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) |
| 203 | set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
| 204 | if(WIN32 OR CYGWIN) |
| 205 | # DLL platform -- put DLLs into bin. |
| 206 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) |
| 207 | else() |
| 208 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| 209 | endif() |
| 210 | |
| 211 | # Each of them corresponds to llvm-config's. |
| 212 | set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir |
| 213 | set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir |
| 214 | set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root |
| 215 | set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir |
| 216 | set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix |
| 217 | |
| 218 | set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples) |
| 219 | set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) |
| 220 | |
| 221 | set(LLVM_ALL_TARGETS |
| 222 | AArch64 |
| 223 | AMDGPU |
| 224 | ARM |
| 225 | BPF |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 226 | Hexagon |
| 227 | Mips |
| 228 | MSP430 |
| 229 | NVPTX |
| 230 | PowerPC |
| 231 | Sparc |
| 232 | SystemZ |
| 233 | X86 |
| 234 | XCore |
| 235 | ) |
| 236 | |
| 237 | # List of targets with JIT support: |
| 238 | set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ) |
| 239 | |
| 240 | set(LLVM_TARGETS_TO_BUILD "all" |
| 241 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
| 242 | |
| 243 | set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD "" |
| 244 | CACHE STRING "Semicolon-separated list of experimental targets to build.") |
| 245 | |
| 246 | option(BUILD_SHARED_LIBS |
| 247 | "Build all libraries as shared libraries instead of static" OFF) |
| 248 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 249 | option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON) |
| 250 | if(LLVM_ENABLE_BACKTRACES) |
| 251 | set(ENABLE_BACKTRACES 1) |
| 252 | endif() |
| 253 | |
| 254 | option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON) |
| 255 | if(LLVM_ENABLE_CRASH_OVERRIDES) |
| 256 | set(ENABLE_CRASH_OVERRIDES 1) |
| 257 | endif() |
| 258 | |
| 259 | option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF) |
| 260 | set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so") |
| 261 | set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h") |
| 262 | |
| 263 | set(LLVM_TARGET_ARCH "host" |
| 264 | CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.") |
| 265 | |
| 266 | option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON) |
| 267 | |
| 268 | option(LLVM_ENABLE_THREADS "Use threads if available." ON) |
| 269 | |
| 270 | option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON) |
| 271 | |
| 272 | if( LLVM_TARGETS_TO_BUILD STREQUAL "all" ) |
| 273 | set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} ) |
| 274 | endif() |
| 275 | |
| 276 | set(LLVM_TARGETS_TO_BUILD |
| 277 | ${LLVM_TARGETS_TO_BUILD} |
| 278 | ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}) |
| 279 | list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) |
| 280 | |
| 281 | include(AddLLVMDefinitions) |
| 282 | |
| 283 | option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON) |
| 284 | option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) |
| 285 | option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF) |
Adrian Prantl | 48e7cbd | 2016-06-30 01:46:49 +0000 | [diff] [blame] | 286 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
Adrian Prantl | 9f4ef63 | 2016-06-30 17:15:44 +0000 | [diff] [blame] | 287 | option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON) |
Adrian Prantl | 48e7cbd | 2016-06-30 01:46:49 +0000 | [diff] [blame] | 288 | option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." OFF) |
| 289 | else() |
Adrian Prantl | 9f4ef63 | 2016-06-30 17:15:44 +0000 | [diff] [blame] | 290 | option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF) |
Adrian Prantl | 48e7cbd | 2016-06-30 01:46:49 +0000 | [diff] [blame] | 291 | option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON) |
| 292 | endif() |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 293 | option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF) |
| 294 | option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF) |
| 295 | option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF) |
| 296 | option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 297 | option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 298 | |
| 299 | if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) |
| 300 | option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF) |
| 301 | else() |
| 302 | option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON) |
| 303 | endif() |
| 304 | |
Filipe Cabecinhas | 0da9937 | 2016-04-29 15:22:48 +0000 | [diff] [blame] | 305 | option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF) |
| 306 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 307 | set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING |
| 308 | "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.") |
| 309 | |
| 310 | option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN |
| 311 | "Set to ON to force using an old, unsupported host toolchain." OFF) |
| 312 | |
| 313 | option(LLVM_USE_INTEL_JITEVENTS |
| 314 | "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code" |
| 315 | OFF) |
| 316 | |
| 317 | if( LLVM_USE_INTEL_JITEVENTS ) |
| 318 | # Verify we are on a supported platform |
| 319 | if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 320 | message(FATAL_ERROR |
| 321 | "Intel JIT API support is available on Linux and Windows only.") |
| 322 | endif() |
| 323 | endif( LLVM_USE_INTEL_JITEVENTS ) |
| 324 | |
| 325 | option(LLVM_USE_OPROFILE |
| 326 | "Use opagent JIT interface to inform OProfile about JIT code" OFF) |
| 327 | |
| 328 | option(LLVM_EXTERNALIZE_DEBUGINFO |
| 329 | "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF) |
| 330 | |
| 331 | # If enabled, verify we are on a platform that supports oprofile. |
| 332 | if( LLVM_USE_OPROFILE ) |
| 333 | if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 334 | message(FATAL_ERROR "OProfile support is available on Linux only.") |
| 335 | endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 336 | endif( LLVM_USE_OPROFILE ) |
| 337 | |
| 338 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 339 | "Define the sanitizer used to build binaries and tests.") |
| 340 | |
| 341 | option(LLVM_USE_SPLIT_DWARF |
| 342 | "Use -gsplit-dwarf when compiling llvm." OFF) |
| 343 | |
Tobias Grosser | 3b32616 | 2016-05-04 20:04:40 +0000 | [diff] [blame] | 344 | option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON) |
| 345 | option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON) |
| 346 | |
| 347 | if (EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt) |
| 348 | set(POLLY_IN_TREE TRUE) |
| 349 | else() |
| 350 | set(POLLY_IN_TREE FALSE) |
| 351 | endif() |
| 352 | |
| 353 | if (LLVM_POLLY_BUILD AND POLLY_IN_TREE) |
| 354 | set(WITH_POLLY ON) |
| 355 | else() |
| 356 | set(WITH_POLLY OFF) |
| 357 | endif() |
| 358 | |
| 359 | if (LLVM_POLLY_LINK_INTO_TOOLS AND WITH_POLLY) |
| 360 | set(LINK_POLLY_INTO_TOOLS ON) |
| 361 | else() |
| 362 | set(LINK_POLLY_INTO_TOOLS OFF) |
| 363 | endif() |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 364 | |
| 365 | # Define an option controlling whether we should build for 32-bit on 64-bit |
| 366 | # platforms, where supported. |
| 367 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 368 | # TODO: support other platforms and toolchains. |
| 369 | option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) |
| 370 | endif() |
| 371 | |
| 372 | # Define the default arguments to use with 'lit', and an option for the user to |
| 373 | # override. |
| 374 | set(LIT_ARGS_DEFAULT "-sv") |
| 375 | if (MSVC_IDE OR XCODE) |
| 376 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 377 | endif() |
| 378 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 379 | |
| 380 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 381 | if( WIN32 AND NOT CYGWIN ) |
| 382 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 383 | endif() |
| 384 | |
| 385 | # Define options to control the inclusion and default build behavior for |
| 386 | # components which may not strictly be necessary (tools, examples, and tests). |
| 387 | # |
| 388 | # This is primarily to support building smaller or faster project files. |
| 389 | option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON) |
| 390 | option(LLVM_BUILD_TOOLS |
| 391 | "Build the LLVM tools. If OFF, just generate build targets." ON) |
| 392 | |
| 393 | option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON) |
Michael Gottesman | be5b787 | 2016-07-10 02:43:47 +0000 | [diff] [blame] | 394 | option(LLVM_BUILD_UTILS |
| 395 | "Build LLVM utility binaries. If OFF, just generate build targets." ON) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 396 | |
| 397 | option(LLVM_BUILD_RUNTIME |
| 398 | "Build the LLVM runtime libraries." ON) |
| 399 | option(LLVM_BUILD_EXAMPLES |
| 400 | "Build the LLVM example programs. If OFF, just generate build targets." OFF) |
| 401 | option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON) |
| 402 | |
| 403 | option(LLVM_BUILD_TESTS |
| 404 | "Build LLVM unit tests. If OFF, just generate build targets." OFF) |
| 405 | option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON) |
| 406 | option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON) |
| 407 | |
| 408 | option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF) |
| 409 | option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON) |
| 410 | option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF) |
| 411 | option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) |
| 412 | |
| 413 | option (LLVM_BUILD_EXTERNAL_COMPILER_RT |
| 414 | "Build compiler-rt as an external project." OFF) |
| 415 | |
| 416 | # You can configure which libraries from LLVM you want to include in the |
| 417 | # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited |
| 418 | # list of LLVM components. All component names handled by llvm-config are valid. |
| 419 | if(NOT DEFINED LLVM_DYLIB_COMPONENTS) |
| 420 | set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING |
| 421 | "Semicolon-separated list of components to include in libLLVM, or \"all\".") |
| 422 | endif() |
| 423 | option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF) |
| 424 | option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF) |
| 425 | set(LLVM_BUILD_LLVM_DYLIB_default OFF) |
| 426 | if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB) |
| 427 | set(LLVM_BUILD_LLVM_DYLIB_default ON) |
| 428 | endif() |
| 429 | option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}) |
| 430 | |
| 431 | option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF) |
| 432 | if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS)) |
| 433 | set(LLVM_USE_HOST_TOOLS ON) |
| 434 | endif() |
| 435 | |
| 436 | if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900)) |
| 437 | option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE) |
| 438 | else() |
| 439 | set(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION FALSE CACHE INTERNAL "For Visual Studio 2013, manually copy natvis files to Documents\\Visual Studio 2013\\Visualizers" FORCE) |
| 440 | endif() |
| 441 | |
Vedant Kumar | d9aed82 | 2016-06-13 23:33:48 +0000 | [diff] [blame] | 442 | if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE) |
| 443 | if(NOT LLVM_PROFILE_MERGE_POOL_SIZE) |
| 444 | # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine |
| 445 | # for spining disks. Anything higher may only help on slower mediums. |
| 446 | set(LLVM_PROFILE_MERGE_POOL_SIZE "4") |
| 447 | endif() |
| 448 | if(NOT LLVM_PROFILE_FILE_PATTERN) |
| 449 | if(NOT LLVM_PROFILE_DATA_DIR) |
Vedant Kumar | 401d031 | 2016-07-23 00:38:11 +0000 | [diff] [blame^] | 450 | file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN) |
Vedant Kumar | d9aed82 | 2016-06-13 23:33:48 +0000 | [diff] [blame] | 451 | else() |
| 452 | file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN) |
| 453 | endif() |
| 454 | endif() |
| 455 | endif() |
| 456 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 457 | # All options referred to from HandleLLVMOptions have to be specified |
| 458 | # BEFORE this include, otherwise options will not be correctly set on |
| 459 | # first cmake run |
| 460 | include(config-ix) |
| 461 | |
| 462 | string(REPLACE "Native" ${LLVM_NATIVE_ARCH} |
| 463 | LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}") |
| 464 | list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) |
| 465 | |
| 466 | # By default, we target the host, but this can be overridden at CMake |
| 467 | # invocation time. |
| 468 | set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING |
| 469 | "Default target for which LLVM will generate code." ) |
| 470 | set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}") |
| 471 | |
| 472 | include(HandleLLVMOptions) |
| 473 | |
| 474 | # Verify that we can find a Python 2 interpreter. Python 3 is unsupported. |
| 475 | # FIXME: We should support systems with only Python 3, but that requires work |
| 476 | # on LLDB. |
| 477 | set(Python_ADDITIONAL_VERSIONS 2.7) |
| 478 | include(FindPythonInterp) |
| 479 | if( NOT PYTHONINTERP_FOUND ) |
| 480 | message(FATAL_ERROR |
| 481 | "Unable to find Python interpreter, required for builds and testing. |
| 482 | |
| 483 | Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") |
| 484 | endif() |
| 485 | |
| 486 | if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) |
| 487 | message(FATAL_ERROR "Python 2.7 or newer is required") |
| 488 | endif() |
| 489 | |
| 490 | ###### |
| 491 | # LLVMBuild Integration |
| 492 | # |
| 493 | # We use llvm-build to generate all the data required by the CMake based |
| 494 | # build system in one swoop: |
| 495 | # |
| 496 | # - We generate a file (a CMake fragment) in the object root which contains |
| 497 | # all the definitions that are required by CMake. |
| 498 | # |
| 499 | # - We generate the library table used by llvm-config. |
| 500 | # |
| 501 | # - We generate the dependencies for the CMake fragment, so that we will |
| 502 | # automatically reconfigure outselves. |
| 503 | |
| 504 | set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build") |
| 505 | set(LLVMCONFIGLIBRARYDEPENDENCIESINC |
| 506 | "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc") |
| 507 | set(LLVMBUILDCMAKEFRAG |
| 508 | "${LLVM_BINARY_DIR}/LLVMBuild.cmake") |
| 509 | |
| 510 | # Create the list of optional components that are enabled |
| 511 | if (LLVM_USE_INTEL_JITEVENTS) |
| 512 | set(LLVMOPTIONALCOMPONENTS IntelJITEvents) |
| 513 | endif (LLVM_USE_INTEL_JITEVENTS) |
| 514 | if (LLVM_USE_OPROFILE) |
| 515 | set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT) |
| 516 | endif (LLVM_USE_OPROFILE) |
| 517 | |
| 518 | message(STATUS "Constructing LLVMBuild project information") |
| 519 | execute_process( |
| 520 | COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL} |
| 521 | --native-target "${LLVM_NATIVE_ARCH}" |
| 522 | --enable-targets "${LLVM_TARGETS_TO_BUILD}" |
| 523 | --enable-optional-components "${LLVMOPTIONALCOMPONENTS}" |
| 524 | --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC} |
| 525 | --write-cmake-fragment ${LLVMBUILDCMAKEFRAG} |
| 526 | OUTPUT_VARIABLE LLVMBUILDOUTPUT |
| 527 | ERROR_VARIABLE LLVMBUILDERRORS |
| 528 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 529 | ERROR_STRIP_TRAILING_WHITESPACE |
| 530 | RESULT_VARIABLE LLVMBUILDRESULT) |
| 531 | |
| 532 | # On Win32, CMake doesn't properly handle piping the default output/error |
| 533 | # streams into the GUI console. So, we explicitly catch and report them. |
| 534 | if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "") |
| 535 | message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}") |
| 536 | endif() |
| 537 | if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" ) |
| 538 | message(FATAL_ERROR |
| 539 | "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}") |
| 540 | endif() |
| 541 | |
| 542 | # Include the generated CMake fragment. This will define properties from the |
| 543 | # LLVMBuild files in a format which is easy to consume from CMake, and will add |
| 544 | # the dependencies so that CMake will reconfigure properly when the LLVMBuild |
| 545 | # files change. |
| 546 | include(${LLVMBUILDCMAKEFRAG}) |
| 547 | |
| 548 | ###### |
| 549 | |
| 550 | # Configure all of the various header file fragments LLVM uses which depend on |
| 551 | # configuration variables. |
| 552 | set(LLVM_ENUM_TARGETS "") |
| 553 | set(LLVM_ENUM_ASM_PRINTERS "") |
| 554 | set(LLVM_ENUM_ASM_PARSERS "") |
| 555 | set(LLVM_ENUM_DISASSEMBLERS "") |
| 556 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 557 | set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} ) |
| 558 | |
| 559 | list(FIND LLVM_ALL_TARGETS ${t} idx) |
| 560 | list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy) |
| 561 | if( idx LESS 0 AND idy LESS 0 ) |
| 562 | message(FATAL_ERROR "The target `${t}' does not exist. |
| 563 | It should be one of\n${LLVM_ALL_TARGETS}") |
| 564 | else() |
| 565 | set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n") |
| 566 | endif() |
| 567 | |
| 568 | file(GLOB asmp_file "${td}/*AsmPrinter.cpp") |
| 569 | if( asmp_file ) |
| 570 | set(LLVM_ENUM_ASM_PRINTERS |
| 571 | "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n") |
| 572 | endif() |
| 573 | if( EXISTS ${td}/AsmParser/CMakeLists.txt ) |
| 574 | set(LLVM_ENUM_ASM_PARSERS |
| 575 | "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n") |
| 576 | endif() |
| 577 | if( EXISTS ${td}/Disassembler/CMakeLists.txt ) |
| 578 | set(LLVM_ENUM_DISASSEMBLERS |
| 579 | "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n") |
| 580 | endif() |
| 581 | endforeach(t) |
| 582 | |
| 583 | # Produce the target definition files, which provide a way for clients to easily |
| 584 | # include various classes of targets. |
| 585 | configure_file( |
| 586 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in |
| 587 | ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def |
| 588 | ) |
| 589 | configure_file( |
| 590 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in |
| 591 | ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def |
| 592 | ) |
| 593 | configure_file( |
| 594 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in |
| 595 | ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def |
| 596 | ) |
| 597 | configure_file( |
| 598 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in |
| 599 | ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def |
| 600 | ) |
| 601 | |
| 602 | # Configure the three LLVM configuration header files. |
| 603 | configure_file( |
| 604 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake |
| 605 | ${LLVM_INCLUDE_DIR}/llvm/Config/config.h) |
| 606 | configure_file( |
| 607 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake |
| 608 | ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h) |
| 609 | configure_file( |
| 610 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake |
| 611 | ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h) |
| 612 | |
| 613 | # They are not referenced. See set_output_directory(). |
| 614 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin ) |
| 615 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 616 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 617 | |
| 618 | set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) |
| 619 | if (APPLE) |
| 620 | set(CMAKE_INSTALL_NAME_DIR "@rpath") |
| 621 | set(CMAKE_INSTALL_RPATH "@executable_path/../lib") |
| 622 | else(UNIX) |
| 623 | if(NOT DEFINED CMAKE_INSTALL_RPATH) |
| 624 | set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}") |
| 625 | if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 626 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin") |
| 627 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin") |
| 628 | endif() |
| 629 | endif(NOT DEFINED CMAKE_INSTALL_RPATH) |
| 630 | endif() |
| 631 | |
| 632 | if(APPLE AND DARWIN_LTO_LIBRARY) |
| 633 | set(CMAKE_EXE_LINKER_FLAGS |
| 634 | "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") |
| 635 | set(CMAKE_SHARED_LINKER_FLAGS |
| 636 | "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") |
| 637 | set(CMAKE_MODULE_LINKER_FLAGS |
| 638 | "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") |
| 639 | endif() |
| 640 | |
| 641 | # Work around a broken bfd ld behavior. When linking a binary with a |
| 642 | # foo.so library, it will try to find any library that foo.so uses and |
| 643 | # check its symbols. This is wasteful (the check was done when foo.so |
| 644 | # was created) and can fail since it is not the dynamic linker and |
| 645 | # doesn't know how to handle search paths correctly. |
Chandler Carruth | 2aff750 | 2016-07-19 22:46:39 +0000 | [diff] [blame] | 646 | if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS|AIX") |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 647 | set(CMAKE_EXE_LINKER_FLAGS |
| 648 | "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined") |
| 649 | endif() |
| 650 | |
| 651 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 652 | |
| 653 | include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}) |
| 654 | |
| 655 | # when crosscompiling import the executable targets from a file |
| 656 | if(LLVM_USE_HOST_TOOLS) |
| 657 | include(CrossCompile) |
| 658 | endif(LLVM_USE_HOST_TOOLS) |
| 659 | if(LLVM_TARGET_IS_CROSSCOMPILE_HOST) |
| 660 | # Dummy use to avoid CMake Wraning: Manually-specified variables were not used |
| 661 | # (this is a variable that CrossCompile sets on recursive invocations) |
| 662 | endif() |
| 663 | |
| 664 | if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 665 | # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM |
| 666 | # with libxml2, iconv.h, etc., we must add /usr/local paths. |
| 667 | include_directories("/usr/local/include") |
| 668 | link_directories("/usr/local/lib") |
| 669 | endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 670 | |
| 671 | if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) |
| 672 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h") |
| 673 | endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) |
| 674 | |
| 675 | # Make sure we don't get -rdynamic in every binary. For those that need it, |
| 676 | # use export_executable_symbols(target). |
| 677 | set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") |
| 678 | |
| 679 | set(LLVM_PROFDATA_FILE "" CACHE FILEPATH |
| 680 | "Profiling data file to use when compiling in order to improve runtime performance.") |
| 681 | |
| 682 | if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE}) |
| 683 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) |
| 684 | add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}") |
| 685 | else() |
| 686 | message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang") |
| 687 | endif() |
| 688 | endif() |
| 689 | |
| 690 | include(AddLLVM) |
| 691 | include(TableGen) |
| 692 | |
| 693 | if( MINGW ) |
| 694 | # People report that -O3 is unreliable on MinGW. The traditional |
| 695 | # build also uses -O2 for that reason: |
| 696 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2") |
| 697 | endif() |
| 698 | |
| 699 | # Put this before tblgen. Else we have a circular dependence. |
| 700 | add_subdirectory(lib/Support) |
| 701 | add_subdirectory(lib/TableGen) |
| 702 | |
| 703 | add_subdirectory(utils/TableGen) |
| 704 | |
Vassil Vassilev | 488b3bd | 2016-06-30 20:35:56 +0000 | [diff] [blame] | 705 | # Force target to be built as soon as possible. Clang modules builds depend |
| 706 | # header-wise on it as they ship all headers from the umbrella folders. Building |
| 707 | # an entire module might include header, which depends on intrinsics_gen. This |
| 708 | # should be right after LLVMSupport and LLVMTableGen otherwise we introduce a |
| 709 | # circular dependence. |
| 710 | if (LLVM_ENABLE_MODULES) |
| 711 | list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen) |
| 712 | endif(LLVM_ENABLE_MODULES) |
| 713 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 714 | add_subdirectory(include/llvm) |
| 715 | |
| 716 | add_subdirectory(lib) |
| 717 | |
| 718 | if( LLVM_INCLUDE_UTILS ) |
| 719 | add_subdirectory(utils/FileCheck) |
| 720 | add_subdirectory(utils/PerfectShuffle) |
| 721 | add_subdirectory(utils/count) |
| 722 | add_subdirectory(utils/not) |
| 723 | add_subdirectory(utils/llvm-lit) |
| 724 | add_subdirectory(utils/yaml-bench) |
Michael Gottesman | 66ddd15 | 2016-07-21 21:35:23 +0000 | [diff] [blame] | 725 | add_subdirectory(utils/unittest) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 726 | else() |
| 727 | if ( LLVM_INCLUDE_TESTS ) |
| 728 | message(FATAL_ERROR "Including tests when not building utils will not work. |
| 729 | Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.") |
| 730 | endif() |
| 731 | endif() |
| 732 | |
| 733 | # Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util |
| 734 | if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION) |
| 735 | add_subdirectory(utils/LLVMVisualizers) |
| 736 | endif() |
| 737 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 738 | foreach( binding ${LLVM_BINDINGS_LIST} ) |
| 739 | if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" ) |
| 740 | add_subdirectory(bindings/${binding}) |
| 741 | endif() |
| 742 | endforeach() |
| 743 | |
| 744 | add_subdirectory(projects) |
| 745 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 746 | if( LLVM_INCLUDE_TOOLS ) |
| 747 | add_subdirectory(tools) |
| 748 | endif() |
| 749 | |
Chris Bieneman | 64adae5 | 2016-06-23 22:07:21 +0000 | [diff] [blame] | 750 | add_subdirectory(runtimes) |
| 751 | |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 752 | if( LLVM_INCLUDE_EXAMPLES ) |
| 753 | add_subdirectory(examples) |
| 754 | endif() |
| 755 | |
| 756 | if( LLVM_INCLUDE_TESTS ) |
| 757 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang) |
| 758 | include(LLVMExternalProjectUtils) |
| 759 | llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite |
| 760 | USE_TOOLCHAIN |
| 761 | EXCLUDE_FROM_ALL |
Chris Bieneman | 64adae5 | 2016-06-23 22:07:21 +0000 | [diff] [blame] | 762 | NO_INSTALL |
| 763 | ALWAYS_CLEAN) |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 764 | endif() |
| 765 | add_subdirectory(test) |
| 766 | add_subdirectory(unittests) |
| 767 | if (MSVC) |
| 768 | # This utility is used to prevent crashing tests from calling Dr. Watson on |
| 769 | # Windows. |
| 770 | add_subdirectory(utils/KillTheDoctor) |
| 771 | endif() |
| 772 | |
| 773 | # Add a global check rule now that all subdirectories have been traversed |
| 774 | # and we know the total set of lit testsuites. |
| 775 | get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES) |
| 776 | get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS) |
| 777 | get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS) |
| 778 | get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS) |
| 779 | add_lit_target(check-all |
| 780 | "Running all regression tests" |
| 781 | ${LLVM_LIT_TESTSUITES} |
| 782 | PARAMS ${LLVM_LIT_PARAMS} |
| 783 | DEPENDS ${LLVM_LIT_DEPENDS} |
| 784 | ARGS ${LLVM_LIT_EXTRA_ARGS} |
| 785 | ) |
| 786 | add_custom_target(test-depends DEPENDS ${LLVM_LIT_DEPENDS}) |
Aaron Ballman | 01a9854 | 2016-04-12 15:09:14 +0000 | [diff] [blame] | 787 | set_target_properties(test-depends PROPERTIES FOLDER "Tests") |
Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 788 | endif() |
| 789 | |
| 790 | if (LLVM_INCLUDE_DOCS) |
| 791 | add_subdirectory(docs) |
| 792 | endif() |
| 793 | |
| 794 | add_subdirectory(cmake/modules) |
| 795 | |
| 796 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 797 | install(DIRECTORY include/llvm include/llvm-c |
| 798 | DESTINATION include |
| 799 | COMPONENT llvm-headers |
| 800 | FILES_MATCHING |
| 801 | PATTERN "*.def" |
| 802 | PATTERN "*.h" |
| 803 | PATTERN "*.td" |
| 804 | PATTERN "*.inc" |
| 805 | PATTERN "LICENSE.TXT" |
| 806 | PATTERN ".svn" EXCLUDE |
| 807 | ) |
| 808 | |
| 809 | install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm |
| 810 | DESTINATION include |
| 811 | COMPONENT llvm-headers |
| 812 | FILES_MATCHING |
| 813 | PATTERN "*.def" |
| 814 | PATTERN "*.h" |
| 815 | PATTERN "*.gen" |
| 816 | PATTERN "*.inc" |
| 817 | # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def" |
| 818 | PATTERN "CMakeFiles" EXCLUDE |
| 819 | PATTERN "config.h" EXCLUDE |
| 820 | PATTERN ".svn" EXCLUDE |
| 821 | ) |
| 822 | |
| 823 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| 824 | add_custom_target(installhdrs |
| 825 | DEPENDS ${name} |
| 826 | COMMAND "${CMAKE_COMMAND}" |
| 827 | -DCMAKE_INSTALL_COMPONENT=llvm-headers |
| 828 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 829 | endif() |
| 830 | endif() |
| 831 | |
| 832 | # This must be at the end of the LLVM root CMakeLists file because it must run |
| 833 | # after all targets are created. |
| 834 | if(LLVM_DISTRIBUTION_COMPONENTS) |
| 835 | if(CMAKE_CONFIGURATION_TYPES) |
| 836 | message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)") |
| 837 | endif() |
| 838 | |
| 839 | add_custom_target(distribution) |
| 840 | add_custom_target(install-distribution) |
| 841 | foreach(target ${LLVM_DISTRIBUTION_COMPONENTS}) |
| 842 | if(TARGET ${target}) |
| 843 | add_dependencies(distribution ${target}) |
| 844 | else() |
| 845 | message(FATAL_ERROR "Specified distribution component '${target}' doesn't have a target") |
| 846 | endif() |
| 847 | |
| 848 | if(TARGET install-${target}) |
| 849 | add_dependencies(install-distribution install-${target}) |
| 850 | else() |
| 851 | message(FATAL_ERROR "Specified distribution component '${target}' doesn't have an install target") |
| 852 | endif() |
| 853 | endforeach() |
| 854 | endif() |