| 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 | |
| Shoaib Meenai | c542c3e | 2017-11-02 20:33:36 +0000 | [diff] [blame] | 5 | # CMake 3.1 and higher include generator expressions of the form |
| 6 | # $<TARGETLIB:obj> in the SOURCES property. These need to be |
| 7 | # stripped everywhere that access the SOURCES property, so we just |
| 8 | # defer to the OLD behavior of not including generator expressions |
| 9 | # in the output for now. |
| 10 | cmake_policy(SET CMP0051 OLD) |
| Shoaib Meenai | 72404b8 | 2017-10-31 01:30:46 +0000 | [diff] [blame] | 11 | |
| Don Hinton | 32ff659 | 2018-01-25 04:55:18 +0000 | [diff] [blame] | 12 | if(POLICY CMP0068) |
| 13 | cmake_policy(SET CMP0068 NEW) |
| 14 | set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON) |
| 15 | endif() |
| 16 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 17 | if(NOT DEFINED LLVM_VERSION_MAJOR) |
| Hans Wennborg | 721c9e5 | 2018-08-01 13:25:30 +0000 | [diff] [blame] | 18 | set(LLVM_VERSION_MAJOR 8) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 19 | endif() |
| 20 | if(NOT DEFINED LLVM_VERSION_MINOR) |
| Hans Wennborg | c714d7c | 2016-07-18 17:51:04 +0000 | [diff] [blame] | 21 | set(LLVM_VERSION_MINOR 0) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 22 | endif() |
| 23 | if(NOT DEFINED LLVM_VERSION_PATCH) |
| 24 | set(LLVM_VERSION_PATCH 0) |
| 25 | endif() |
| 26 | if(NOT DEFINED LLVM_VERSION_SUFFIX) |
| 27 | set(LLVM_VERSION_SUFFIX svn) |
| 28 | endif() |
| 29 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 30 | if (NOT PACKAGE_VERSION) |
| 31 | set(PACKAGE_VERSION |
| 32 | "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}") |
| 33 | endif() |
| 34 | |
| Aaron Ballman | 472278a | 2017-05-25 21:01:30 +0000 | [diff] [blame] | 35 | if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL "")) |
| 36 | message(WARNING "Visual Studio generators use the x86 host compiler by " |
| 37 | "default, even for 64-bit targets. This can result in linker " |
| 38 | "instability and out of memory errors. To use the 64-bit " |
| 39 | "host compiler, pass -Thost=x64 on the CMake command line.") |
| 40 | endif() |
| 41 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 42 | project(LLVM |
| Shoaib Meenai | c542c3e | 2017-11-02 20:33:36 +0000 | [diff] [blame] | 43 | VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH} |
| 44 | LANGUAGES C CXX ASM) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 45 | |
| Chris Bieneman | 69f289c | 2016-08-18 18:17:28 +0000 | [diff] [blame] | 46 | if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 47 | message(STATUS "No build type selected, default to Debug") |
| Shoaib Meenai | d54da37 | 2016-11-02 06:10:03 +0000 | [diff] [blame] | 48 | set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)" FORCE) |
| Chris Bieneman | 69f289c | 2016-08-18 18:17:28 +0000 | [diff] [blame] | 49 | endif() |
| 50 | |
| Chris Bieneman | f4a56a7 | 2016-07-25 23:46:08 +0000 | [diff] [blame] | 51 | # This should only apply if you are both on an Apple host, and targeting Apple. |
| 52 | if(CMAKE_HOST_APPLE AND APPLE) |
| Chris Bieneman | 7a7db84 | 2017-02-07 23:32:56 +0000 | [diff] [blame] | 53 | # if CMAKE_LIBTOOL is not set, try and find it with xcrun or find_program |
| 54 | if(NOT CMAKE_LIBTOOL) |
| 55 | if(NOT CMAKE_XCRUN) |
| 56 | find_program(CMAKE_XCRUN NAMES xcrun) |
| 57 | endif() |
| 58 | if(CMAKE_XCRUN) |
| 59 | execute_process(COMMAND ${CMAKE_XCRUN} -find libtool |
| 60 | OUTPUT_VARIABLE CMAKE_LIBTOOL |
| 61 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 62 | endif() |
| Chris Bieneman | f4a56a7 | 2016-07-25 23:46:08 +0000 | [diff] [blame] | 63 | |
| Chris Bieneman | 7a7db84 | 2017-02-07 23:32:56 +0000 | [diff] [blame] | 64 | if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL) |
| 65 | find_program(CMAKE_LIBTOOL NAMES libtool) |
| 66 | endif() |
| Chris Bieneman | 6108658 | 2016-04-28 20:14:19 +0000 | [diff] [blame] | 67 | endif() |
| Chris Bieneman | f4a56a7 | 2016-07-25 23:46:08 +0000 | [diff] [blame] | 68 | |
| 69 | get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) |
| Chris Bieneman | 6108658 | 2016-04-28 20:14:19 +0000 | [diff] [blame] | 70 | if(CMAKE_LIBTOOL) |
| 71 | set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable") |
| 72 | message(STATUS "Found libtool - ${CMAKE_LIBTOOL}") |
| Kuba Mracek | fde4a45 | 2016-12-05 05:21:44 +0000 | [diff] [blame] | 73 | |
| 74 | execute_process(COMMAND ${CMAKE_LIBTOOL} -V |
| 75 | OUTPUT_VARIABLE LIBTOOL_V_OUTPUT |
| 76 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 77 | if("${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*") |
| 78 | string(REGEX REPLACE ".*cctools-([0-9.]+).*" "\\1" LIBTOOL_VERSION |
| 79 | ${LIBTOOL_V_OUTPUT}) |
| 80 | if(NOT LIBTOOL_VERSION VERSION_LESS "862") |
| 81 | set(LIBTOOL_NO_WARNING_FLAG "-no_warning_for_no_symbols") |
| 82 | endif() |
| 83 | endif() |
| Ekaterina Vaartis | 2d5ab69 | 2017-06-22 10:38:49 +0000 | [diff] [blame] | 84 | |
| Chris Bieneman | 6108658 | 2016-04-28 20:14:19 +0000 | [diff] [blame] | 85 | foreach(lang ${languages}) |
| 86 | set(CMAKE_${lang}_CREATE_STATIC_LIBRARY |
| Jordan Rose | d71614a | 2018-06-13 18:21:47 +0000 | [diff] [blame] | 87 | "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o <TARGET> \ |
| Kuba Mracek | fde4a45 | 2016-12-05 05:21:44 +0000 | [diff] [blame] | 88 | <LINK_FLAGS> <OBJECTS> ") |
| Chris Bieneman | 6108658 | 2016-04-28 20:14:19 +0000 | [diff] [blame] | 89 | endforeach() |
| 90 | endif() |
| Chris Bieneman | f4a56a7 | 2016-07-25 23:46:08 +0000 | [diff] [blame] | 91 | |
| 92 | # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands |
| 93 | if(DYLD_LIBRARY_PATH) |
| 94 | set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}") |
| 95 | foreach(lang ${languages}) |
| 96 | foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY}) |
| 97 | list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW |
| 98 | "${dyld_envar} ${cmd}") |
| 99 | endforeach() |
| 100 | set(CMAKE_${lang}_CREATE_STATIC_LIBRARY |
| 101 | ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW}) |
| 102 | endforeach() |
| 103 | endif() |
| Chris Bieneman | 6108658 | 2016-04-28 20:14:19 +0000 | [diff] [blame] | 104 | endif() |
| 105 | |
| Mehdi Amini | 1eed06a | 2016-11-07 22:13:38 +0000 | [diff] [blame] | 106 | # Side-by-side subprojects layout: automatically set the |
| 107 | # LLVM_EXTERNAL_${project}_SOURCE_DIR using LLVM_ALL_PROJECTS |
| 108 | # This allows an easy way of setting up a build directory for llvm and another |
| 109 | # one for llvm+clang+... using the same sources. |
| Don Hinton | 49777fa | 2017-12-12 17:06:08 +0000 | [diff] [blame] | 110 | set(LLVM_ALL_PROJECTS "clang;libcxx;libcxxabi;lldb;compiler-rt;lld;polly;debuginfo-tests") |
| Mehdi Amini | 1eed06a | 2016-11-07 22:13:38 +0000 | [diff] [blame] | 111 | set(LLVM_ENABLE_PROJECTS "" CACHE STRING |
| 112 | "Semicolon-separated list of projects to build (${LLVM_ALL_PROJECTS}), or \"all\".") |
| 113 | if( LLVM_ENABLE_PROJECTS STREQUAL "all" ) |
| 114 | set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS}) |
| 115 | endif() |
| 116 | foreach(proj ${LLVM_ENABLE_PROJECTS}) |
| 117 | set(PROJ_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") |
| 118 | if(NOT EXISTS "${PROJ_DIR}" OR NOT IS_DIRECTORY "${PROJ_DIR}") |
| 119 | message(FATAL_ERROR "LLVM_ENABLE_PROJECTS requests ${proj} but directory not found: ${PROJ_DIR}") |
| 120 | endif() |
| 121 | string(TOUPPER "${proj}" upper_proj) |
| Mehdi Amini | 03c6265 | 2016-11-09 00:23:20 +0000 | [diff] [blame] | 122 | STRING(REGEX REPLACE "-" "_" upper_proj ${upper_proj}) |
| Mehdi Amini | 1eed06a | 2016-11-07 22:13:38 +0000 | [diff] [blame] | 123 | set(LLVM_EXTERNAL_${upper_proj}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${proj}") |
| 124 | # There is a widely spread opinion that clang-tools-extra should be merged |
| 125 | # into clang. The following simulates it by always enabling clang-tools-extra |
| 126 | # when enabling clang. |
| 127 | if (proj STREQUAL "clang") |
| 128 | set(LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../clang-tools-extra") |
| 129 | endif() |
| 130 | endforeach() |
| 131 | |
| Sumanth Gundapaneni | 9f4dc98 | 2016-08-01 21:28:03 +0000 | [diff] [blame] | 132 | # Build llvm with ccache if the package is present |
| 133 | set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build") |
| 134 | if(LLVM_CCACHE_BUILD) |
| 135 | find_program(CCACHE_PROGRAM ccache) |
| 136 | if(CCACHE_PROGRAM) |
| Paul Robinson | 052f14e | 2018-01-24 18:15:08 +0000 | [diff] [blame] | 137 | set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache") |
| Sumanth Gundapaneni | 9f4dc98 | 2016-08-01 21:28:03 +0000 | [diff] [blame] | 138 | set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data") |
| Justin Bogner | 1e871bc | 2018-02-09 23:25:23 +0000 | [diff] [blame] | 139 | set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes" |
| 140 | CACHE STRING "Parameters to pass through to ccache") |
| 141 | |
| 142 | set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}") |
| Paul Robinson | 052f14e | 2018-01-24 18:15:08 +0000 | [diff] [blame] | 143 | if (LLVM_CCACHE_MAXSIZE) |
| 144 | set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}") |
| Sumanth Gundapaneni | 9f4dc98 | 2016-08-01 21:28:03 +0000 | [diff] [blame] | 145 | endif() |
| 146 | if (LLVM_CCACHE_DIR) |
| 147 | set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}") |
| 148 | endif() |
| 149 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) |
| 150 | else() |
| 151 | message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF") |
| 152 | endif() |
| 153 | endif() |
| 154 | |
| Chris Bieneman | 8036e0b | 2016-11-17 04:36:59 +0000 | [diff] [blame] | 155 | option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF) |
| 156 | |
| 157 | # Some features of the LLVM build may be disallowed when dependency debugging is |
| 158 | # enabled. In particular you cannot use ccache because we want to force compile |
| 159 | # operations to always happen. |
| 160 | if(LLVM_DEPENDENCY_DEBUGGING) |
| 161 | if(NOT CMAKE_HOST_APPLE) |
| 162 | message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.") |
| 163 | endif() |
| 164 | if(LLVM_CCACHE_BUILD) |
| 165 | message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.") |
| 166 | endif() |
| 167 | endif() |
| 168 | |
| Aditya Nandakumar | bb0483b | 2017-02-14 18:32:41 +0000 | [diff] [blame] | 169 | option(LLVM_ENABLE_DAGISEL_COV "Debug: Prints tablegen patterns that were used for selecting" OFF) |
| Daniel Sanders | f76f315 | 2017-11-16 00:46:35 +0000 | [diff] [blame] | 170 | option(LLVM_ENABLE_GISEL_COV "Enable collection of GlobalISel rule coverage" OFF) |
| 171 | if(LLVM_ENABLE_GISEL_COV) |
| 172 | set(LLVM_GISEL_COV_PREFIX "${CMAKE_BINARY_DIR}/gisel-coverage-" CACHE STRING "Provide a filename prefix to collect the GlobalISel rule coverage") |
| 173 | endif() |
| Aditya Nandakumar | bb0483b | 2017-02-14 18:32:41 +0000 | [diff] [blame] | 174 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 175 | # Add path for custom modules |
| 176 | set(CMAKE_MODULE_PATH |
| 177 | ${CMAKE_MODULE_PATH} |
| 178 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 179 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" |
| 180 | ) |
| 181 | |
| 182 | # Generate a CompilationDatabase (compile_commands.json file) for our build, |
| 183 | # for use by clang_complete, YouCompleteMe, etc. |
| 184 | set(CMAKE_EXPORT_COMPILE_COMMANDS 1) |
| 185 | |
| Shoaib Meenai | 08bb38f | 2017-11-02 21:43:32 +0000 | [diff] [blame] | 186 | option(LLVM_INSTALL_BINUTILS_SYMLINKS |
| 187 | "Install symlinks from the binutils tool names to the corresponding LLVM tools." OFF) |
| 188 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 189 | option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF) |
| 190 | |
| 191 | option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF) |
| 192 | |
| 193 | option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON) |
| 194 | if ( LLVM_USE_FOLDERS ) |
| 195 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 196 | endif() |
| 197 | |
| 198 | include(VersionFromVCS) |
| 199 | |
| 200 | option(LLVM_APPEND_VC_REV |
| Rafael Espindola | cd6d9f3 | 2017-06-30 18:48:33 +0000 | [diff] [blame] | 201 | "Embed the version control system revision id in LLVM" ON) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 202 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 203 | set(PACKAGE_NAME LLVM) |
| 204 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| Shoaib Meenai | 5e23768 | 2018-01-25 19:16:46 +0000 | [diff] [blame] | 205 | set(PACKAGE_BUGREPORT "https://bugs.llvm.org/") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 206 | |
| 207 | set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING |
| 208 | "Default URL where bug reports are to be submitted.") |
| 209 | |
| 210 | # Configure CPack. |
| 211 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM") |
| 212 | set(CPACK_PACKAGE_VENDOR "LLVM") |
| 213 | set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) |
| 214 | set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 215 | set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH}) |
| 216 | set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) |
| 217 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT") |
| 218 | set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32") |
| 219 | if(WIN32 AND NOT UNIX) |
| 220 | set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM") |
| 221 | set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp") |
| 222 | set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico") |
| 223 | set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico") |
| 224 | set(CPACK_NSIS_MODIFY_PATH "ON") |
| 225 | set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 226 | if( CMAKE_CL_64 ) |
| 227 | set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") |
| 228 | endif() |
| 229 | endif() |
| 230 | include(CPack) |
| 231 | |
| 232 | # Sanity check our source directory to make sure that we are not trying to |
| Brian Gesiak | 88f2aa1 | 2017-09-27 21:37:33 +0000 | [diff] [blame] | 233 | # generate an in-source build (unless on MSVC_IDE, where it is ok), and to make |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 234 | # sure that we don't have any stray generated files lying around in the tree |
| 235 | # (which would end up getting picked up by header search, instead of the correct |
| 236 | # versions). |
| Chris Bieneman | 2a0a8fb | 2017-10-19 00:43:48 +0000 | [diff] [blame] | 237 | if( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE ) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 238 | message(FATAL_ERROR "In-source builds are not allowed. |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 239 | Please create a directory and run cmake from there, passing the path |
| 240 | to this source directory as the last argument. |
| 241 | This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. |
| 242 | Please delete them.") |
| 243 | endif() |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 244 | |
| 245 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 246 | |
| 247 | if (CMAKE_BUILD_TYPE AND |
| 248 | NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$") |
| 249 | message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") |
| 250 | endif() |
| 251 | |
| 252 | set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) |
| 253 | |
| Chris Bieneman | 2724f14 | 2016-06-08 21:19:26 +0000 | [diff] [blame] | 254 | set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") |
| 255 | mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) |
| 256 | |
| Don Hinton | 435d650 | 2018-01-19 17:02:12 +0000 | [diff] [blame] | 257 | set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING |
| Tom Stellard | edd69bc | 2017-07-05 12:57:30 +0000 | [diff] [blame] | 258 | "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") |
| Don Hinton | 435d650 | 2018-01-19 17:02:12 +0000 | [diff] [blame] | 259 | mark_as_advanced(LLVM_UTILS_INSTALL_DIR) |
| Tom Stellard | edd69bc | 2017-07-05 12:57:30 +0000 | [diff] [blame] | 260 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 261 | # They are used as destination of target generators. |
| 262 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) |
| 263 | set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
| 264 | if(WIN32 OR CYGWIN) |
| 265 | # DLL platform -- put DLLs into bin. |
| 266 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) |
| 267 | else() |
| 268 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| 269 | endif() |
| 270 | |
| 271 | # Each of them corresponds to llvm-config's. |
| 272 | set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir |
| 273 | set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir |
| 274 | set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) # --src-root |
| 275 | set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir |
| 276 | set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) # --prefix |
| 277 | |
| Michal Gorny | e22b7f5 | 2016-10-19 12:18:34 +0000 | [diff] [blame] | 278 | # Note: LLVM_CMAKE_PATH does not include generated files |
| 279 | set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 280 | set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples) |
| 281 | set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) |
| 282 | |
| Alex Bradbury | f1af56c | 2017-08-13 18:49:33 +0000 | [diff] [blame] | 283 | # List of all targets to be built by default: |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 284 | set(LLVM_ALL_TARGETS |
| 285 | AArch64 |
| 286 | AMDGPU |
| 287 | ARM |
| 288 | BPF |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 289 | Hexagon |
| Jacques Pienaar | 3721837 | 2016-08-23 01:06:44 +0000 | [diff] [blame] | 290 | Lanai |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 291 | Mips |
| 292 | MSP430 |
| 293 | NVPTX |
| 294 | PowerPC |
| 295 | Sparc |
| 296 | SystemZ |
| 297 | X86 |
| 298 | XCore |
| 299 | ) |
| 300 | |
| 301 | # List of targets with JIT support: |
| 302 | set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ) |
| 303 | |
| 304 | set(LLVM_TARGETS_TO_BUILD "all" |
| 305 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
| 306 | |
| 307 | set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD "" |
| 308 | CACHE STRING "Semicolon-separated list of experimental targets to build.") |
| 309 | |
| 310 | option(BUILD_SHARED_LIBS |
| 311 | "Build all libraries as shared libraries instead of static" OFF) |
| 312 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 313 | option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON) |
| 314 | if(LLVM_ENABLE_BACKTRACES) |
| 315 | set(ENABLE_BACKTRACES 1) |
| 316 | endif() |
| 317 | |
| 318 | option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON) |
| 319 | if(LLVM_ENABLE_CRASH_OVERRIDES) |
| 320 | set(ENABLE_CRASH_OVERRIDES 1) |
| 321 | endif() |
| 322 | |
| Reid Kleckner | 5313193 | 2018-08-20 16:49:54 +0000 | [diff] [blame^] | 323 | option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently only implemented on Windows." OFF) |
| 324 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 325 | option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF) |
| 326 | set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so") |
| 327 | set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h") |
| 328 | |
| 329 | set(LLVM_TARGET_ARCH "host" |
| 330 | CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.") |
| 331 | |
| 332 | option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON) |
| 333 | |
| Hans Wennborg | 88e6e18 | 2017-11-14 22:32:49 +0000 | [diff] [blame] | 334 | set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON") |
| Eric Beckmann | 7d50c389 | 2017-07-20 21:42:04 +0000 | [diff] [blame] | 335 | |
| Yichao Yu | 4497a28 | 2016-11-18 01:25:49 +0000 | [diff] [blame] | 336 | option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON) |
| 337 | |
| Clement Courbet | 23db174 | 2018-04-11 07:32:43 +0000 | [diff] [blame] | 338 | option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON) |
| 339 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 340 | option(LLVM_ENABLE_THREADS "Use threads if available." ON) |
| 341 | |
| 342 | option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON) |
| 343 | |
| 344 | if( LLVM_TARGETS_TO_BUILD STREQUAL "all" ) |
| 345 | set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} ) |
| 346 | endif() |
| 347 | |
| 348 | set(LLVM_TARGETS_TO_BUILD |
| 349 | ${LLVM_TARGETS_TO_BUILD} |
| 350 | ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}) |
| 351 | list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) |
| 352 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 353 | option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON) |
| 354 | option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) |
| 355 | option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF) |
| Adrian Prantl | 48e7cbd | 2016-06-30 01:46:49 +0000 | [diff] [blame] | 356 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| Adrian Prantl | 9f4ef63 | 2016-06-30 17:15:44 +0000 | [diff] [blame] | 357 | option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON) |
| Adrian Prantl | 48e7cbd | 2016-06-30 01:46:49 +0000 | [diff] [blame] | 358 | option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." OFF) |
| 359 | else() |
| Adrian Prantl | 9f4ef63 | 2016-06-30 17:15:44 +0000 | [diff] [blame] | 360 | option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF) |
| Adrian Prantl | 48e7cbd | 2016-06-30 01:46:49 +0000 | [diff] [blame] | 361 | option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON) |
| 362 | endif() |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 363 | option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF) |
| Vassil Vassilev | d335233 | 2017-06-09 22:09:57 +0000 | [diff] [blame] | 364 | option(LLVM_ENABLE_CXX1Z "Compile with C++1z enabled." OFF) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 365 | option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF) |
| Eugene Zelenko | bbbf7b5 | 2016-07-29 00:46:13 +0000 | [diff] [blame] | 366 | option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 367 | option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 368 | option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 369 | |
| Don Hinton | 25e64a1 | 2017-12-07 22:55:40 +0000 | [diff] [blame] | 370 | option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF) |
| Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 371 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 372 | if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) |
| 373 | option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF) |
| 374 | else() |
| 375 | option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON) |
| 376 | endif() |
| 377 | |
| Don Hinton | 53eb637 | 2017-09-27 21:19:56 +0000 | [diff] [blame] | 378 | option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF) |
| Matthias Braun | c9e458c | 2017-09-26 02:36:58 +0000 | [diff] [blame] | 379 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 380 | set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING |
| 381 | "Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.") |
| 382 | |
| 383 | option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN |
| 384 | "Set to ON to force using an old, unsupported host toolchain." OFF) |
| 385 | |
| 386 | option(LLVM_USE_INTEL_JITEVENTS |
| 387 | "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code" |
| 388 | OFF) |
| 389 | |
| 390 | if( LLVM_USE_INTEL_JITEVENTS ) |
| 391 | # Verify we are on a supported platform |
| 392 | if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 393 | message(FATAL_ERROR |
| 394 | "Intel JIT API support is available on Linux and Windows only.") |
| 395 | endif() |
| 396 | endif( LLVM_USE_INTEL_JITEVENTS ) |
| 397 | |
| 398 | option(LLVM_USE_OPROFILE |
| 399 | "Use opagent JIT interface to inform OProfile about JIT code" OFF) |
| 400 | |
| 401 | option(LLVM_EXTERNALIZE_DEBUGINFO |
| 402 | "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF) |
| 403 | |
| Justin Bogner | 8fa2608 | 2018-07-10 17:32:48 +0000 | [diff] [blame] | 404 | option(LLVM_CODESIGNING_IDENTITY |
| 405 | "Sign executables and dylibs with the given identity (Darwin Only)" OFF) |
| 406 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 407 | # If enabled, verify we are on a platform that supports oprofile. |
| 408 | if( LLVM_USE_OPROFILE ) |
| 409 | if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 410 | message(FATAL_ERROR "OProfile support is available on Linux only.") |
| 411 | endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 412 | endif( LLVM_USE_OPROFILE ) |
| 413 | |
| Andres Freund | 376a3d3 | 2018-07-24 00:54:06 +0000 | [diff] [blame] | 414 | option(LLVM_USE_PERF |
| 415 | "Use perf JIT interface to inform perf about JIT code" OFF) |
| 416 | |
| 417 | # If enabled, verify we are on a platform that supports perf. |
| 418 | if( LLVM_USE_PERF ) |
| 419 | if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 420 | message(FATAL_ERROR "perf support is available on Linux only.") |
| 421 | endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" ) |
| 422 | endif( LLVM_USE_PERF ) |
| 423 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 424 | set(LLVM_USE_SANITIZER "" CACHE STRING |
| 425 | "Define the sanitizer used to build binaries and tests.") |
| Chris Bieneman | c2e8e20 | 2018-05-17 16:55:29 +0000 | [diff] [blame] | 426 | option(LLVM_OPTIMIZE_SANITIZED_BUILDS "Pass -O1 on debug sanitizer builds" ON) |
| Matt Morehouse | 5436866 | 2017-10-12 21:58:41 +0000 | [diff] [blame] | 427 | set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH |
| 428 | "Path to fuzzing library for linking with fuzz targets") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 429 | |
| 430 | option(LLVM_USE_SPLIT_DWARF |
| 431 | "Use -gsplit-dwarf when compiling llvm." OFF) |
| 432 | |
| Tobias Grosser | 3b32616 | 2016-05-04 20:04:40 +0000 | [diff] [blame] | 433 | option(LLVM_POLLY_LINK_INTO_TOOLS "Statically link Polly into tools (if available)" ON) |
| 434 | option(LLVM_POLLY_BUILD "Build LLVM with Polly" ON) |
| 435 | |
| 436 | if (EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt) |
| 437 | set(POLLY_IN_TREE TRUE) |
| Hongbin Zheng | 78550e39 | 2016-10-07 21:32:47 +0000 | [diff] [blame] | 438 | elseif(LLVM_EXTERNAL_POLLY_SOURCE_DIR) |
| 439 | set(POLLY_IN_TREE TRUE) |
| Tobias Grosser | 3b32616 | 2016-05-04 20:04:40 +0000 | [diff] [blame] | 440 | else() |
| 441 | set(POLLY_IN_TREE FALSE) |
| 442 | endif() |
| 443 | |
| 444 | if (LLVM_POLLY_BUILD AND POLLY_IN_TREE) |
| 445 | set(WITH_POLLY ON) |
| 446 | else() |
| 447 | set(WITH_POLLY OFF) |
| 448 | endif() |
| 449 | |
| 450 | if (LLVM_POLLY_LINK_INTO_TOOLS AND WITH_POLLY) |
| 451 | set(LINK_POLLY_INTO_TOOLS ON) |
| 452 | else() |
| 453 | set(LINK_POLLY_INTO_TOOLS OFF) |
| 454 | endif() |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 455 | |
| 456 | # Define an option controlling whether we should build for 32-bit on 64-bit |
| 457 | # platforms, where supported. |
| 458 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 459 | # TODO: support other platforms and toolchains. |
| 460 | option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) |
| 461 | endif() |
| 462 | |
| 463 | # Define the default arguments to use with 'lit', and an option for the user to |
| 464 | # override. |
| 465 | set(LIT_ARGS_DEFAULT "-sv") |
| 466 | if (MSVC_IDE OR XCODE) |
| 467 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 468 | endif() |
| 469 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 470 | |
| 471 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 472 | if( WIN32 AND NOT CYGWIN ) |
| 473 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 474 | endif() |
| 475 | |
| 476 | # Define options to control the inclusion and default build behavior for |
| 477 | # components which may not strictly be necessary (tools, examples, and tests). |
| 478 | # |
| 479 | # This is primarily to support building smaller or faster project files. |
| 480 | option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON) |
| 481 | option(LLVM_BUILD_TOOLS |
| 482 | "Build the LLVM tools. If OFF, just generate build targets." ON) |
| 483 | |
| 484 | option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON) |
| Michael Gottesman | be5b787 | 2016-07-10 02:43:47 +0000 | [diff] [blame] | 485 | option(LLVM_BUILD_UTILS |
| 486 | "Build LLVM utility binaries. If OFF, just generate build targets." ON) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 487 | |
| Petr Hosek | 2705226 | 2017-03-23 22:40:10 +0000 | [diff] [blame] | 488 | option(LLVM_INCLUDE_RUNTIMES "Generate build targets for the LLVM runtimes." ON) |
| 489 | option(LLVM_BUILD_RUNTIMES |
| 490 | "Build the LLVM runtimes. If OFF, just generate build targets." ON) |
| 491 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 492 | option(LLVM_BUILD_RUNTIME |
| 493 | "Build the LLVM runtime libraries." ON) |
| 494 | option(LLVM_BUILD_EXAMPLES |
| 495 | "Build the LLVM example programs. If OFF, just generate build targets." OFF) |
| 496 | option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON) |
| 497 | |
| 498 | option(LLVM_BUILD_TESTS |
| 499 | "Build LLVM unit tests. If OFF, just generate build targets." OFF) |
| 500 | option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON) |
| 501 | option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON) |
| 502 | |
| 503 | option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF) |
| 504 | option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON) |
| 505 | option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF) |
| 506 | option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) |
| Peter Zotov | b2a1275 | 2016-08-23 18:07:16 +0000 | [diff] [blame] | 507 | option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) |
| Vassil Vassilev | ce73760 | 2018-05-20 08:37:54 +0000 | [diff] [blame] | 508 | option (LLVM_ENABLE_BINDINGS "Build bindings." ON) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 509 | |
| Michal Gorny | c496c50 | 2016-09-27 19:52:29 +0000 | [diff] [blame] | 510 | set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" |
| 511 | CACHE STRING "Doxygen-generated HTML documentation install directory") |
| 512 | set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" |
| 513 | CACHE STRING "OCamldoc-generated HTML documentation install directory") |
| 514 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 515 | option (LLVM_BUILD_EXTERNAL_COMPILER_RT |
| 516 | "Build compiler-rt as an external project." OFF) |
| 517 | |
| Xin Tong | 59cb778 | 2017-04-19 00:03:36 +0000 | [diff] [blame] | 518 | option (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO |
| 519 | "Show target and host info when tools are invoked with --version." ON) |
| 520 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 521 | # You can configure which libraries from LLVM you want to include in the |
| 522 | # shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited |
| 523 | # list of LLVM components. All component names handled by llvm-config are valid. |
| 524 | if(NOT DEFINED LLVM_DYLIB_COMPONENTS) |
| 525 | set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING |
| 526 | "Semicolon-separated list of components to include in libLLVM, or \"all\".") |
| 527 | endif() |
| 528 | option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF) |
| David Bolvansky | ab2cbad | 2018-08-07 15:54:50 +0000 | [diff] [blame] | 529 | if(MSVC) |
| 530 | option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" OFF) |
| 531 | else() |
| 532 | option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF) |
| 533 | endif() |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 534 | set(LLVM_BUILD_LLVM_DYLIB_default OFF) |
| David Bolvansky | ab2cbad | 2018-08-07 15:54:50 +0000 | [diff] [blame] | 535 | if(LLVM_LINK_LLVM_DYLIB OR (LLVM_BUILD_LLVM_C_DYLIB AND NOT MSVC)) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 536 | set(LLVM_BUILD_LLVM_DYLIB_default ON) |
| 537 | endif() |
| 538 | option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}) |
| 539 | |
| 540 | option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF) |
| Daniil Fukalov | fb50133 | 2016-11-28 17:12:09 +0000 | [diff] [blame] | 541 | if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES))) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 542 | set(LLVM_USE_HOST_TOOLS ON) |
| 543 | endif() |
| 544 | |
| 545 | if (MSVC_IDE AND NOT (MSVC_VERSION LESS 1900)) |
| 546 | option(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION "Configure project to use Visual Studio native visualizers" TRUE) |
| 547 | else() |
| 548 | 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) |
| 549 | endif() |
| 550 | |
| Vedant Kumar | 9aaaeb3 | 2017-09-20 17:16:01 +0000 | [diff] [blame] | 551 | if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE OR |
| 552 | LLVM_ENABLE_IR_PGO) |
| Vedant Kumar | d9aed82 | 2016-06-13 23:33:48 +0000 | [diff] [blame] | 553 | if(NOT LLVM_PROFILE_MERGE_POOL_SIZE) |
| 554 | # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine |
| 555 | # for spining disks. Anything higher may only help on slower mediums. |
| 556 | set(LLVM_PROFILE_MERGE_POOL_SIZE "4") |
| 557 | endif() |
| 558 | if(NOT LLVM_PROFILE_FILE_PATTERN) |
| 559 | if(NOT LLVM_PROFILE_DATA_DIR) |
| Vedant Kumar | 9aaaeb3 | 2017-09-20 17:16:01 +0000 | [diff] [blame] | 560 | file(TO_NATIVE_PATH "${LLVM_BINARY_DIR}/profiles" LLVM_PROFILE_DATA_DIR) |
| Vedant Kumar | d9aed82 | 2016-06-13 23:33:48 +0000 | [diff] [blame] | 561 | endif() |
| Vedant Kumar | 9aaaeb3 | 2017-09-20 17:16:01 +0000 | [diff] [blame] | 562 | file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN) |
| Vedant Kumar | d9aed82 | 2016-06-13 23:33:48 +0000 | [diff] [blame] | 563 | endif() |
| 564 | endif() |
| 565 | |
| Pavel Labath | 10849a8 | 2016-11-17 11:22:23 +0000 | [diff] [blame] | 566 | if (LLVM_BUILD_STATIC) |
| 567 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") |
| 568 | endif() |
| 569 | |
| NAKAMURA Takumi | fc7f3b7 | 2017-06-17 03:19:08 +0000 | [diff] [blame] | 570 | # Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV. |
| 571 | set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.") |
| 572 | mark_as_advanced(LLVM_TARGET_TRIPLE_ENV) |
| 573 | |
| Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 574 | set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL |
| 575 | "Enable per-target runtimes directory") |
| 576 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 577 | # All options referred to from HandleLLVMOptions have to be specified |
| 578 | # BEFORE this include, otherwise options will not be correctly set on |
| 579 | # first cmake run |
| 580 | include(config-ix) |
| 581 | |
| 582 | string(REPLACE "Native" ${LLVM_NATIVE_ARCH} |
| 583 | LLVM_TARGETS_TO_BUILD "${LLVM_TARGETS_TO_BUILD}") |
| 584 | list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD) |
| 585 | |
| 586 | # By default, we target the host, but this can be overridden at CMake |
| 587 | # invocation time. |
| 588 | set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING |
| 589 | "Default target for which LLVM will generate code." ) |
| 590 | set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}") |
| Chris Bieneman | 0775a23 | 2016-09-27 18:08:40 +0000 | [diff] [blame] | 591 | message(STATUS "LLVM host triple: ${LLVM_HOST_TRIPLE}") |
| 592 | message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 593 | |
| 594 | include(HandleLLVMOptions) |
| 595 | |
| 596 | # Verify that we can find a Python 2 interpreter. Python 3 is unsupported. |
| 597 | # FIXME: We should support systems with only Python 3, but that requires work |
| 598 | # on LLDB. |
| 599 | set(Python_ADDITIONAL_VERSIONS 2.7) |
| 600 | include(FindPythonInterp) |
| 601 | if( NOT PYTHONINTERP_FOUND ) |
| 602 | message(FATAL_ERROR |
| 603 | "Unable to find Python interpreter, required for builds and testing. |
| 604 | |
| 605 | Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") |
| 606 | endif() |
| 607 | |
| 608 | if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) |
| 609 | message(FATAL_ERROR "Python 2.7 or newer is required") |
| 610 | endif() |
| 611 | |
| 612 | ###### |
| 613 | # LLVMBuild Integration |
| 614 | # |
| 615 | # We use llvm-build to generate all the data required by the CMake based |
| 616 | # build system in one swoop: |
| 617 | # |
| 618 | # - We generate a file (a CMake fragment) in the object root which contains |
| 619 | # all the definitions that are required by CMake. |
| 620 | # |
| 621 | # - We generate the library table used by llvm-config. |
| 622 | # |
| 623 | # - We generate the dependencies for the CMake fragment, so that we will |
| Stephen Kelly | ed4f517 | 2018-08-09 20:15:13 +0000 | [diff] [blame] | 624 | # automatically reconfigure ourselves. |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 625 | |
| 626 | set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build") |
| 627 | set(LLVMCONFIGLIBRARYDEPENDENCIESINC |
| 628 | "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc") |
| 629 | set(LLVMBUILDCMAKEFRAG |
| 630 | "${LLVM_BINARY_DIR}/LLVMBuild.cmake") |
| 631 | |
| 632 | # Create the list of optional components that are enabled |
| 633 | if (LLVM_USE_INTEL_JITEVENTS) |
| 634 | set(LLVMOPTIONALCOMPONENTS IntelJITEvents) |
| 635 | endif (LLVM_USE_INTEL_JITEVENTS) |
| 636 | if (LLVM_USE_OPROFILE) |
| 637 | set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT) |
| 638 | endif (LLVM_USE_OPROFILE) |
| Andres Freund | 376a3d3 | 2018-07-24 00:54:06 +0000 | [diff] [blame] | 639 | if (LLVM_USE_PERF) |
| 640 | set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} PerfJITEvents) |
| 641 | endif (LLVM_USE_PERF) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 642 | |
| 643 | message(STATUS "Constructing LLVMBuild project information") |
| 644 | execute_process( |
| Vassil Vassilev | a2285eb | 2017-03-23 14:54:34 +0000 | [diff] [blame] | 645 | COMMAND ${PYTHON_EXECUTABLE} -B ${LLVMBUILDTOOL} |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 646 | --native-target "${LLVM_NATIVE_ARCH}" |
| 647 | --enable-targets "${LLVM_TARGETS_TO_BUILD}" |
| 648 | --enable-optional-components "${LLVMOPTIONALCOMPONENTS}" |
| 649 | --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC} |
| 650 | --write-cmake-fragment ${LLVMBUILDCMAKEFRAG} |
| 651 | OUTPUT_VARIABLE LLVMBUILDOUTPUT |
| 652 | ERROR_VARIABLE LLVMBUILDERRORS |
| 653 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 654 | ERROR_STRIP_TRAILING_WHITESPACE |
| 655 | RESULT_VARIABLE LLVMBUILDRESULT) |
| 656 | |
| 657 | # On Win32, CMake doesn't properly handle piping the default output/error |
| 658 | # streams into the GUI console. So, we explicitly catch and report them. |
| 659 | if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "") |
| 660 | message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}") |
| 661 | endif() |
| 662 | if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" ) |
| 663 | message(FATAL_ERROR |
| 664 | "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}") |
| 665 | endif() |
| 666 | |
| 667 | # Include the generated CMake fragment. This will define properties from the |
| 668 | # LLVMBuild files in a format which is easy to consume from CMake, and will add |
| 669 | # the dependencies so that CMake will reconfigure properly when the LLVMBuild |
| 670 | # files change. |
| 671 | include(${LLVMBUILDCMAKEFRAG}) |
| 672 | |
| 673 | ###### |
| 674 | |
| 675 | # Configure all of the various header file fragments LLVM uses which depend on |
| 676 | # configuration variables. |
| 677 | set(LLVM_ENUM_TARGETS "") |
| 678 | set(LLVM_ENUM_ASM_PRINTERS "") |
| 679 | set(LLVM_ENUM_ASM_PARSERS "") |
| 680 | set(LLVM_ENUM_DISASSEMBLERS "") |
| 681 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 682 | set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} ) |
| 683 | |
| 684 | list(FIND LLVM_ALL_TARGETS ${t} idx) |
| 685 | list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy) |
| Don Hinton | 0fa52c7 | 2017-12-18 19:15:15 +0000 | [diff] [blame] | 686 | # At this point, LLVMBUILDTOOL already checked all the targets passed in |
| 687 | # LLVM_TARGETS_TO_BUILD and LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, so |
| 688 | # this test just makes sure that any experimental targets were passed via |
| 689 | # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD. |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 690 | if( idx LESS 0 AND idy LESS 0 ) |
| Don Hinton | 0fa52c7 | 2017-12-18 19:15:15 +0000 | [diff] [blame] | 691 | message(FATAL_ERROR "The target `${t}' is experimental and must be passed " |
| 692 | "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 693 | else() |
| 694 | set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n") |
| 695 | endif() |
| 696 | |
| 697 | file(GLOB asmp_file "${td}/*AsmPrinter.cpp") |
| 698 | if( asmp_file ) |
| 699 | set(LLVM_ENUM_ASM_PRINTERS |
| 700 | "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n") |
| 701 | endif() |
| 702 | if( EXISTS ${td}/AsmParser/CMakeLists.txt ) |
| 703 | set(LLVM_ENUM_ASM_PARSERS |
| 704 | "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n") |
| 705 | endif() |
| 706 | if( EXISTS ${td}/Disassembler/CMakeLists.txt ) |
| 707 | set(LLVM_ENUM_DISASSEMBLERS |
| 708 | "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n") |
| 709 | endif() |
| 710 | endforeach(t) |
| 711 | |
| 712 | # Produce the target definition files, which provide a way for clients to easily |
| 713 | # include various classes of targets. |
| 714 | configure_file( |
| 715 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in |
| 716 | ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def |
| 717 | ) |
| 718 | configure_file( |
| 719 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in |
| 720 | ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def |
| 721 | ) |
| 722 | configure_file( |
| 723 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in |
| 724 | ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def |
| 725 | ) |
| 726 | configure_file( |
| 727 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in |
| 728 | ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def |
| 729 | ) |
| 730 | |
| 731 | # Configure the three LLVM configuration header files. |
| 732 | configure_file( |
| 733 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake |
| 734 | ${LLVM_INCLUDE_DIR}/llvm/Config/config.h) |
| 735 | configure_file( |
| 736 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake |
| 737 | ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h) |
| 738 | configure_file( |
| Mehdi Amini | 28dd54c | 2016-11-28 22:23:53 +0000 | [diff] [blame] | 739 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake |
| 740 | ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 741 | |
| Tom Stellard | b208f71 | 2017-03-06 14:26:50 +0000 | [diff] [blame] | 742 | # Add target for generating source rpm package. |
| 743 | set(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in |
| 744 | CACHE FILEPATH ".spec file to use for srpm generation") |
| 745 | set(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec) |
| 746 | set(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm") |
| 747 | |
| 748 | # SVN_REVISION and GIT_COMMIT get set by the call to add_version_info_from_vcs. |
| 749 | # DUMMY_VAR contains a version string which we don't care about. |
| 750 | add_version_info_from_vcs(DUMMY_VAR) |
| 751 | if ( SVN_REVISION ) |
| 752 | set(LLVM_RPM_SPEC_REVISION "r${SVN_REVISION}") |
| 753 | elseif ( GIT_COMMIT ) |
| 754 | set (LLVM_RPM_SPEC_REVISION "g${GIT_COMMIT}") |
| 755 | endif() |
| 756 | |
| 757 | configure_file( |
| 758 | ${LLVM_SRPM_USER_BINARY_SPECFILE} |
| 759 | ${LLVM_SRPM_BINARY_SPECFILE} @ONLY) |
| 760 | |
| 761 | add_custom_target(srpm |
| 762 | COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES |
| 763 | COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) |
| Aaron Ballman | a5ee69a | 2017-11-04 19:59:14 +0000 | [diff] [blame] | 764 | set_target_properties(srpm PROPERTIES FOLDER "Misc") |
| Tom Stellard | b208f71 | 2017-03-06 14:26:50 +0000 | [diff] [blame] | 765 | |
| Brian Gesiak | 615a3bb | 2017-09-29 19:50:41 +0000 | [diff] [blame] | 766 | |
| 767 | # They are not referenced. See set_output_directory(). |
| 768 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin ) |
| 769 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 770 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 771 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 772 | if(APPLE AND DARWIN_LTO_LIBRARY) |
| 773 | set(CMAKE_EXE_LINKER_FLAGS |
| 774 | "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") |
| 775 | set(CMAKE_SHARED_LINKER_FLAGS |
| 776 | "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") |
| 777 | set(CMAKE_MODULE_LINKER_FLAGS |
| 778 | "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") |
| 779 | endif() |
| 780 | |
| 781 | # Work around a broken bfd ld behavior. When linking a binary with a |
| 782 | # foo.so library, it will try to find any library that foo.so uses and |
| 783 | # check its symbols. This is wasteful (the check was done when foo.so |
| 784 | # was created) and can fail since it is not the dynamic linker and |
| 785 | # doesn't know how to handle search paths correctly. |
| Chandler Carruth | 2aff750 | 2016-07-19 22:46:39 +0000 | [diff] [blame] | 786 | 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] | 787 | set(CMAKE_EXE_LINKER_FLAGS |
| 788 | "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined") |
| 789 | endif() |
| 790 | |
| 791 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 792 | |
| 793 | include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}) |
| 794 | |
| 795 | # when crosscompiling import the executable targets from a file |
| 796 | if(LLVM_USE_HOST_TOOLS) |
| 797 | include(CrossCompile) |
| 798 | endif(LLVM_USE_HOST_TOOLS) |
| 799 | if(LLVM_TARGET_IS_CROSSCOMPILE_HOST) |
| Brian Gesiak | 16b86e7 | 2017-09-29 02:48:07 +0000 | [diff] [blame] | 800 | # Dummy use to avoid CMake Warning: Manually-specified variables were not used |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 801 | # (this is a variable that CrossCompile sets on recursive invocations) |
| 802 | endif() |
| 803 | |
| 804 | if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 805 | # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM |
| 806 | # with libxml2, iconv.h, etc., we must add /usr/local paths. |
| Matthias Braun | cf3ab11 | 2017-10-16 23:03:21 +0000 | [diff] [blame] | 807 | include_directories(SYSTEM "/usr/local/include") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 808 | link_directories("/usr/local/lib") |
| 809 | endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 810 | |
| 811 | if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) |
| Kamil Rytarowski | 25374a6 | 2017-06-22 13:18:46 +0000 | [diff] [blame] | 812 | # special hack for Solaris to handle crazy system sys/regset.h |
| 813 | include_directories("${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/Solaris") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 814 | endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) |
| 815 | |
| 816 | # Make sure we don't get -rdynamic in every binary. For those that need it, |
| 817 | # use export_executable_symbols(target). |
| 818 | set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") |
| 819 | |
| 820 | set(LLVM_PROFDATA_FILE "" CACHE FILEPATH |
| 821 | "Profiling data file to use when compiling in order to improve runtime performance.") |
| 822 | |
| 823 | if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE}) |
| 824 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) |
| 825 | add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}") |
| 826 | else() |
| 827 | message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang") |
| 828 | endif() |
| 829 | endif() |
| 830 | |
| 831 | include(AddLLVM) |
| 832 | include(TableGen) |
| 833 | |
| Martell Malone | 0b75eee | 2018-02-08 07:13:17 +0000 | [diff] [blame] | 834 | if( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 835 | # People report that -O3 is unreliable on MinGW. The traditional |
| 836 | # build also uses -O2 for that reason: |
| 837 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2") |
| 838 | endif() |
| 839 | |
| 840 | # Put this before tblgen. Else we have a circular dependence. |
| Rafael Espindola | ec73f5d | 2016-09-06 20:16:19 +0000 | [diff] [blame] | 841 | add_subdirectory(lib/Demangle) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 842 | add_subdirectory(lib/Support) |
| 843 | add_subdirectory(lib/TableGen) |
| 844 | |
| 845 | add_subdirectory(utils/TableGen) |
| 846 | |
| 847 | add_subdirectory(include/llvm) |
| 848 | |
| 849 | add_subdirectory(lib) |
| 850 | |
| 851 | if( LLVM_INCLUDE_UTILS ) |
| 852 | add_subdirectory(utils/FileCheck) |
| 853 | add_subdirectory(utils/PerfectShuffle) |
| 854 | add_subdirectory(utils/count) |
| 855 | add_subdirectory(utils/not) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 856 | add_subdirectory(utils/yaml-bench) |
| 857 | else() |
| 858 | if ( LLVM_INCLUDE_TESTS ) |
| 859 | message(FATAL_ERROR "Including tests when not building utils will not work. |
| 860 | Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.") |
| 861 | endif() |
| 862 | endif() |
| 863 | |
| 864 | # Use LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION instead of LLVM_INCLUDE_UTILS because it is not really a util |
| 865 | if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION) |
| 866 | add_subdirectory(utils/LLVMVisualizers) |
| 867 | endif() |
| 868 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 869 | foreach( binding ${LLVM_BINDINGS_LIST} ) |
| 870 | if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" ) |
| 871 | add_subdirectory(bindings/${binding}) |
| 872 | endif() |
| 873 | endforeach() |
| 874 | |
| 875 | add_subdirectory(projects) |
| 876 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 877 | if( LLVM_INCLUDE_TOOLS ) |
| 878 | add_subdirectory(tools) |
| 879 | endif() |
| 880 | |
| Petr Hosek | 2705226 | 2017-03-23 22:40:10 +0000 | [diff] [blame] | 881 | if( LLVM_INCLUDE_RUNTIMES ) |
| 882 | add_subdirectory(runtimes) |
| 883 | endif() |
| Chris Bieneman | 64adae5 | 2016-06-23 22:07:21 +0000 | [diff] [blame] | 884 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 885 | if( LLVM_INCLUDE_EXAMPLES ) |
| 886 | add_subdirectory(examples) |
| 887 | endif() |
| 888 | |
| 889 | if( LLVM_INCLUDE_TESTS ) |
| Zachary Turner | 79708b5 | 2017-11-21 01:20:28 +0000 | [diff] [blame] | 890 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 891 | include(LLVMExternalProjectUtils) |
| Zachary Turner | 79708b5 | 2017-11-21 01:20:28 +0000 | [diff] [blame] | 892 | llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite |
| 893 | USE_TOOLCHAIN |
| 894 | EXCLUDE_FROM_ALL |
| 895 | NO_INSTALL |
| 896 | ALWAYS_CLEAN) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 897 | endif() |
| Reid Kleckner | 7a2274a | 2017-08-02 17:16:25 +0000 | [diff] [blame] | 898 | add_subdirectory(utils/lit) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 899 | add_subdirectory(test) |
| 900 | add_subdirectory(unittests) |
| Vassil Vassilev | cb28894 | 2017-06-09 16:37:39 +0000 | [diff] [blame] | 901 | if( LLVM_INCLUDE_UTILS ) |
| 902 | add_subdirectory(utils/unittest) |
| 903 | endif() |
| 904 | |
| Reid Kleckner | 143a937 | 2016-12-22 19:11:42 +0000 | [diff] [blame] | 905 | if (WIN32) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 906 | # This utility is used to prevent crashing tests from calling Dr. Watson on |
| 907 | # Windows. |
| 908 | add_subdirectory(utils/KillTheDoctor) |
| 909 | endif() |
| 910 | |
| 911 | # Add a global check rule now that all subdirectories have been traversed |
| 912 | # and we know the total set of lit testsuites. |
| 913 | get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES) |
| 914 | get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS) |
| 915 | get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS) |
| 916 | get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS) |
| Chris Bieneman | 342134e | 2016-09-01 18:26:01 +0000 | [diff] [blame] | 917 | get_property(LLVM_ADDITIONAL_TEST_TARGETS |
| 918 | GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_TARGETS) |
| 919 | get_property(LLVM_ADDITIONAL_TEST_DEPENDS |
| 920 | GLOBAL PROPERTY LLVM_ADDITIONAL_TEST_DEPENDS) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 921 | add_lit_target(check-all |
| 922 | "Running all regression tests" |
| 923 | ${LLVM_LIT_TESTSUITES} |
| 924 | PARAMS ${LLVM_LIT_PARAMS} |
| Chris Bieneman | 342134e | 2016-09-01 18:26:01 +0000 | [diff] [blame] | 925 | DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_TARGETS} |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 926 | ARGS ${LLVM_LIT_EXTRA_ARGS} |
| 927 | ) |
| Chris Bieneman | 2e4dde9 | 2016-08-25 17:18:41 +0000 | [diff] [blame] | 928 | if(TARGET check-runtimes) |
| 929 | add_dependencies(check-all check-runtimes) |
| 930 | endif() |
| Chris Bieneman | 342134e | 2016-09-01 18:26:01 +0000 | [diff] [blame] | 931 | add_custom_target(test-depends |
| 932 | DEPENDS ${LLVM_LIT_DEPENDS} ${LLVM_ADDITIONAL_TEST_DEPENDS}) |
| Aaron Ballman | 01a9854 | 2016-04-12 15:09:14 +0000 | [diff] [blame] | 933 | set_target_properties(test-depends PROPERTIES FOLDER "Tests") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 934 | endif() |
| 935 | |
| 936 | if (LLVM_INCLUDE_DOCS) |
| 937 | add_subdirectory(docs) |
| 938 | endif() |
| 939 | |
| 940 | add_subdirectory(cmake/modules) |
| 941 | |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 942 | # Do this last so that all lit targets have already been created. |
| 943 | if (LLVM_INCLUDE_UTILS) |
| 944 | add_subdirectory(utils/llvm-lit) |
| 945 | endif() |
| 946 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 947 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 948 | install(DIRECTORY include/llvm include/llvm-c |
| 949 | DESTINATION include |
| 950 | COMPONENT llvm-headers |
| 951 | FILES_MATCHING |
| 952 | PATTERN "*.def" |
| 953 | PATTERN "*.h" |
| 954 | PATTERN "*.td" |
| 955 | PATTERN "*.inc" |
| 956 | PATTERN "LICENSE.TXT" |
| 957 | PATTERN ".svn" EXCLUDE |
| 958 | ) |
| 959 | |
| David Blaikie | c72984f | 2018-03-21 18:21:57 +0000 | [diff] [blame] | 960 | install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 961 | DESTINATION include |
| 962 | COMPONENT llvm-headers |
| 963 | FILES_MATCHING |
| 964 | PATTERN "*.def" |
| 965 | PATTERN "*.h" |
| 966 | PATTERN "*.gen" |
| 967 | PATTERN "*.inc" |
| 968 | # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def" |
| 969 | PATTERN "CMakeFiles" EXCLUDE |
| 970 | PATTERN "config.h" EXCLUDE |
| 971 | PATTERN ".svn" EXCLUDE |
| 972 | ) |
| 973 | |
| Justin Bogner | b631099 | 2016-10-24 21:58:58 +0000 | [diff] [blame] | 974 | # Installing the headers needs to depend on generating any public |
| 975 | # tablegen'd headers. |
| 976 | add_custom_target(llvm-headers DEPENDS intrinsics_gen) |
| Aaron Ballman | a5ee69a | 2017-11-04 19:59:14 +0000 | [diff] [blame] | 977 | set_target_properties(llvm-headers PROPERTIES FOLDER "Misc") |
| Justin Bogner | b631099 | 2016-10-24 21:58:58 +0000 | [diff] [blame] | 978 | |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 979 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 980 | add_llvm_install_targets(install-llvm-headers |
| Justin Bogner | 0af77da | 2018-06-11 23:05:28 +0000 | [diff] [blame] | 981 | DEPENDS llvm-headers |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 982 | COMPONENT llvm-headers) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 983 | endif() |
| 984 | endif() |
| 985 | |
| 986 | # This must be at the end of the LLVM root CMakeLists file because it must run |
| 987 | # after all targets are created. |
| 988 | if(LLVM_DISTRIBUTION_COMPONENTS) |
| 989 | if(CMAKE_CONFIGURATION_TYPES) |
| 990 | message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)") |
| 991 | endif() |
| 992 | |
| 993 | add_custom_target(distribution) |
| 994 | add_custom_target(install-distribution) |
| Shoaib Meenai | d907351 | 2017-12-08 19:44:45 +0000 | [diff] [blame] | 995 | add_custom_target(install-distribution-stripped) |
| Chris Bieneman | 8a534b0 | 2018-05-17 16:58:44 +0000 | [diff] [blame] | 996 | foreach(target ${LLVM_DISTRIBUTION_COMPONENTS} ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS}) |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 997 | if(TARGET ${target}) |
| 998 | add_dependencies(distribution ${target}) |
| 999 | else() |
| Shoaib Meenai | 909f5c9 | 2017-11-02 01:07:37 +0000 | [diff] [blame] | 1000 | message(SEND_ERROR "Specified distribution component '${target}' doesn't have a target") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 1001 | endif() |
| 1002 | |
| 1003 | if(TARGET install-${target}) |
| 1004 | add_dependencies(install-distribution install-${target}) |
| 1005 | else() |
| Shoaib Meenai | 909f5c9 | 2017-11-02 01:07:37 +0000 | [diff] [blame] | 1006 | message(SEND_ERROR "Specified distribution component '${target}' doesn't have an install target") |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 1007 | endif() |
| Shoaib Meenai | d907351 | 2017-12-08 19:44:45 +0000 | [diff] [blame] | 1008 | |
| 1009 | if(TARGET install-${target}-stripped) |
| 1010 | add_dependencies(install-distribution-stripped install-${target}-stripped) |
| 1011 | else() |
| 1012 | message(SEND_ERROR "Specified distribution component '${target}' doesn't have an install-stripped target." |
| 1013 | " Its installation target creation should be changed to use add_llvm_install_targets," |
| 1014 | " or you should manually create the 'install-${target}-stripped' target.") |
| 1015 | endif() |
| Reid Kleckner | a2a07f9 | 2016-03-28 18:19:32 +0000 | [diff] [blame] | 1016 | endforeach() |
| 1017 | endif() |
| Vadim Chugunov | cfd0b6f | 2017-01-28 07:39:52 +0000 | [diff] [blame] | 1018 | |
| 1019 | # This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake |
| Hans Wennborg | 5df524f | 2018-08-09 08:41:03 +0000 | [diff] [blame] | 1020 | if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES) |
| Vadim Chugunov | cfd0b6f | 2017-01-28 07:39:52 +0000 | [diff] [blame] | 1021 | include(InstallRequiredSystemLibraries) |
| 1022 | endif() |