Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.8) |
| 2 | |
| 3 | # FIXME: It may be removed when we use 2.8.12. |
| 4 | if(CMAKE_VERSION VERSION_LESS 2.8.12) |
| 5 | # Invalidate a couple of keywords. |
| 6 | set(cmake_2_8_12_INTERFACE) |
| 7 | set(cmake_2_8_12_PRIVATE) |
| 8 | else() |
| 9 | # Use ${cmake_2_8_12_KEYWORD} intead of KEYWORD in target_link_libraries(). |
| 10 | set(cmake_2_8_12_INTERFACE INTERFACE) |
| 11 | set(cmake_2_8_12_PRIVATE PRIVATE) |
| 12 | if(POLICY CMP0022) |
| 13 | cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required |
| 14 | endif() |
| 15 | endif() |
| 16 | |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 17 | # If we are not building as a part of LLVM, build Clang as an |
| 18 | # standalone project, using LLVM as an external library: |
| 19 | if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) |
| 20 | project(Clang) |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 21 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 22 | # Rely on llvm-config. |
| 23 | set(CONFIG_OUTPUT) |
| 24 | find_program(LLVM_CONFIG "llvm-config") |
| 25 | if(LLVM_CONFIG) |
| 26 | message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}") |
| 27 | set(CONFIG_COMMAND ${LLVM_CONFIG} |
| 28 | "--assertion-mode" |
| 29 | "--bindir" |
| 30 | "--libdir" |
| 31 | "--includedir" |
| 32 | "--prefix" |
| 33 | "--src-root") |
| 34 | execute_process( |
| 35 | COMMAND ${CONFIG_COMMAND} |
| 36 | RESULT_VARIABLE HAD_ERROR |
| 37 | OUTPUT_VARIABLE CONFIG_OUTPUT |
| 38 | ) |
| 39 | if(NOT HAD_ERROR) |
| 40 | string(REGEX REPLACE |
| 41 | "[ \t]*[\r\n]+[ \t]*" ";" |
| 42 | CONFIG_OUTPUT ${CONFIG_OUTPUT}) |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 43 | else() |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 44 | string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}") |
| 45 | message(STATUS "${CONFIG_COMMAND_STR}") |
| 46 | message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 47 | endif() |
Hans Wennborg | e90340a | 2013-08-23 18:05:24 +0000 | [diff] [blame] | 48 | else() |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 49 | message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}") |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 50 | endif() |
| 51 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 52 | list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS) |
| 53 | list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR) |
| 54 | list(GET CONFIG_OUTPUT 2 LIBRARY_DIR) |
| 55 | list(GET CONFIG_OUTPUT 3 INCLUDE_DIR) |
| 56 | list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT) |
| 57 | list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR) |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 58 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 59 | if(NOT MSVC_IDE) |
| 60 | set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS} |
| 61 | CACHE BOOL "Enable assertions") |
| 62 | # Assertions should follow llvm-config's. |
| 63 | mark_as_advanced(LLVM_ENABLE_ASSERTIONS) |
| 64 | endif() |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 65 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 66 | set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin") |
| 67 | set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib") |
| 68 | set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include") |
| 69 | set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree") |
| 70 | set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") |
| 71 | |
| 72 | find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} |
| 73 | NO_DEFAULT_PATH) |
| 74 | |
| 75 | set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake") |
| 76 | set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 77 | if(EXISTS ${LLVMCONFIG_FILE}) |
| 78 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") |
| 79 | include(${LLVMCONFIG_FILE}) |
| 80 | else() |
| 81 | message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}") |
| 82 | endif() |
| 83 | |
| 84 | # They are used as destination of target generators. |
| 85 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 86 | set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
| 87 | if(WIN32 OR CYGWIN) |
| 88 | # DLL platform -- put DLLs into bin. |
| 89 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) |
| 90 | else() |
| 91 | set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| 92 | endif() |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 93 | |
| 94 | option(LLVM_INSTALL_TOOLCHAIN_ONLY |
| 95 | "Only include toolchain files in the 'install' target." OFF) |
| 96 | |
| 97 | option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN |
| 98 | "Set to ON to force using an old, unsupported host toolchain." OFF) |
Hans Wennborg | 885e36e | 2013-08-24 00:22:23 +0000 | [diff] [blame] | 99 | |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 100 | include(AddLLVM) |
| 101 | include(TableGen) |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 102 | include(HandleLLVMOptions) |
| 103 | |
| 104 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 105 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 106 | if (NOT DEFINED LLVM_INCLUDE_TESTS) |
| 107 | set(LLVM_INCLUDE_TESTS ON) |
Chandler Carruth | 9224fb8 | 2012-07-02 20:52:55 +0000 | [diff] [blame] | 108 | endif() |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 109 | |
| 110 | include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") |
| 111 | link_directories("${LLVM_LIBRARY_DIR}") |
Chandler Carruth | 9224fb8 | 2012-07-02 20:52:55 +0000 | [diff] [blame] | 112 | |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 113 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 114 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
| 115 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 116 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 117 | if(LLVM_INCLUDE_TESTS) |
| 118 | # Check prebuilt llvm/utils. |
| 119 | if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX} |
| 120 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX} |
| 121 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX}) |
| 122 | set(LLVM_UTILS_PROVIDED ON) |
| 123 | endif() |
| 124 | |
| 125 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 126 | set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 127 | if(NOT LLVM_UTILS_PROVIDED) |
| 128 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck) |
| 129 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count) |
| 130 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not) |
| 131 | set(LLVM_UTILS_PROVIDED ON) |
| 132 | set(CLANG_TEST_DEPS FileCheck count not) |
| 133 | endif() |
| 134 | set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest) |
| 135 | if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h |
| 136 | AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 137 | AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt) |
| 138 | add_subdirectory(${UNITTEST_DIR} utils/unittest) |
| 139 | endif() |
| 140 | else() |
| 141 | # Seek installed Lit. |
| 142 | find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit |
| 143 | DOC "Path to lit.py") |
| 144 | endif() |
| 145 | |
| 146 | if(LLVM_LIT) |
| 147 | # Define the default arguments to use with 'lit', and an option for the user |
| 148 | # to override. |
| 149 | set(LIT_ARGS_DEFAULT "-sv") |
| 150 | if (MSVC OR XCODE) |
| 151 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 152 | endif() |
| 153 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 154 | |
| 155 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 156 | if( WIN32 AND NOT CYGWIN ) |
| 157 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 158 | endif() |
| 159 | else() |
| 160 | set(LLVM_INCLUDE_TESTS OFF) |
| 161 | endif() |
| 162 | endif() |
| 163 | |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 164 | set( CLANG_BUILT_STANDALONE 1 ) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 165 | set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}") |
| 166 | else() |
| 167 | set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}") |
| 168 | endif() |
Douglas Gregor | a34173e | 2012-12-18 19:39:40 +0000 | [diff] [blame] | 169 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 170 | find_package(LibXml2) |
| 171 | if (LIBXML2_FOUND) |
| 172 | set(CLANG_HAVE_LIBXML 1) |
Oscar Fuentes | 67410b3 | 2011-02-03 20:57:53 +0000 | [diff] [blame] | 173 | endif() |
Douglas Gregor | 34d9ffa | 2009-09-16 21:59:05 +0000 | [diff] [blame] | 174 | |
Oscar Fuentes | 2100fe9 | 2011-02-03 22:48:20 +0000 | [diff] [blame] | 175 | set(CLANG_RESOURCE_DIR "" CACHE STRING |
| 176 | "Relative directory from the Clang binary to its resource files.") |
| 177 | |
| 178 | set(C_INCLUDE_DIRS "" CACHE STRING |
| 179 | "Colon separated list of directories clang will search for headers.") |
| 180 | |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 181 | set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." ) |
| 182 | set(DEFAULT_SYSROOT "" CACHE PATH |
| 183 | "Default <path> to all compiler invocations for --sysroot=<path>." ) |
| 184 | |
Oscar Fuentes | f752d5b | 2011-05-20 15:57:59 +0000 | [diff] [blame] | 185 | set(CLANG_VENDOR "" CACHE STRING |
| 186 | "Vendor-specific text for showing with version information.") |
| 187 | |
| 188 | if( CLANG_VENDOR ) |
| 189 | add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " ) |
| 190 | endif() |
| 191 | |
Michael Gottesman | a8c0e4f | 2013-08-15 19:22:33 +0000 | [diff] [blame] | 192 | set(CLANG_REPOSITORY_STRING "" CACHE STRING |
| 193 | "Vendor-specific text for showing the repository the source is taken from.") |
| 194 | |
| 195 | if(CLANG_REPOSITORY_STRING) |
| 196 | add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}") |
| 197 | endif() |
| 198 | |
Michael Gottesman | f353511 | 2013-08-15 19:22:36 +0000 | [diff] [blame] | 199 | set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING |
| 200 | "Vendor-specific uti.") |
| 201 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 202 | # The libdir suffix must exactly match whatever LLVM's configuration used. |
| 203 | set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}") |
| 204 | |
Daniel Dunbar | 91ee77a | 2009-09-17 00:07:10 +0000 | [diff] [blame] | 205 | set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 206 | set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 207 | |
Chandler Carruth | 63e9c0d | 2010-04-17 20:12:02 +0000 | [diff] [blame] | 208 | if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) |
| 209 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 210 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 211 | "from there, passing the path to this source directory as the last argument. " |
| 212 | "This process created the file `CMakeCache.txt' and the directory " |
| 213 | "`CMakeFiles'. Please delete them.") |
| 214 | endif() |
| 215 | |
| 216 | if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) |
| 217 | file(GLOB_RECURSE |
| 218 | tablegenned_files_on_include_dir |
| 219 | "${CLANG_SOURCE_DIR}/include/clang/*.inc") |
| 220 | if( tablegenned_files_on_include_dir ) |
| 221 | message(FATAL_ERROR "Apparently there is a previous in-source build, " |
| 222 | "probably as the result of running `configure' and `make' on " |
| 223 | "${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n" |
| 224 | "${tablegenned_files_on_include_dir}\nPlease clean the source directory.") |
| 225 | endif() |
| 226 | endif() |
| 227 | |
Daniel Dunbar | c4b8e92 | 2010-06-25 23:34:47 +0000 | [diff] [blame] | 228 | # Compute the Clang version from the LLVM version. |
Michael J. Spencer | 5a7f349 | 2010-09-10 21:13:16 +0000 | [diff] [blame] | 229 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION |
Daniel Dunbar | c4b8e92 | 2010-06-25 23:34:47 +0000 | [diff] [blame] | 230 | ${PACKAGE_VERSION}) |
Douglas Gregor | 34d9ffa | 2009-09-16 21:59:05 +0000 | [diff] [blame] | 231 | message(STATUS "Clang version: ${CLANG_VERSION}") |
Douglas Gregor | 7f7b748 | 2009-08-23 05:28:29 +0000 | [diff] [blame] | 232 | |
Daniel Dunbar | a510767 | 2010-06-25 17:33:46 +0000 | [diff] [blame] | 233 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR |
| 234 | ${CLANG_VERSION}) |
| 235 | string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR |
| 236 | ${CLANG_VERSION}) |
| 237 | if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+") |
| 238 | set(CLANG_HAS_VERSION_PATCHLEVEL 1) |
| 239 | string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL |
| 240 | ${CLANG_VERSION}) |
| 241 | else() |
| 242 | set(CLANG_HAS_VERSION_PATCHLEVEL 0) |
| 243 | endif() |
| 244 | |
| 245 | # Configure the Version.inc file. |
| 246 | configure_file( |
| 247 | ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in |
| 248 | ${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc) |
| 249 | |
Douglas Gregor | 9df3faf | 2009-09-18 14:47:57 +0000 | [diff] [blame] | 250 | # Add appropriate flags for GCC |
Oscar Fuentes | c5cd252 | 2011-05-11 13:53:30 +0000 | [diff] [blame] | 251 | if (LLVM_COMPILER_IS_GCC_COMPATIBLE) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 252 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -fno-strict-aliasing") |
Richard Smith | 19258e8 | 2013-04-22 14:51:21 +0000 | [diff] [blame] | 253 | |
| 254 | # Enable -pedantic for Clang even if it's not enabled for LLVM. |
| 255 | if (NOT LLVM_ENABLE_PEDANTIC) |
| 256 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long") |
| 257 | endif () |
Jordan Rose | 549a292 | 2013-03-02 00:49:47 +0000 | [diff] [blame] | 258 | |
| 259 | check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG) |
| 260 | if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG ) |
| 261 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" ) |
| 262 | endif() |
Douglas Gregor | 9df3faf | 2009-09-18 14:47:57 +0000 | [diff] [blame] | 263 | endif () |
| 264 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 265 | # Determine HOST_LINK_VERSION on Darwin. |
| 266 | set(HOST_LINK_VERSION) |
| 267 | if (APPLE) |
| 268 | set(LD_V_OUTPUT) |
| 269 | execute_process( |
| 270 | COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1" |
| 271 | RESULT_VARIABLE HAD_ERROR |
| 272 | OUTPUT_VARIABLE LD_V_OUTPUT |
| 273 | ) |
| 274 | if (NOT HAD_ERROR) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 275 | if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*") |
| 276 | string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) |
| 277 | elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*") |
| 278 | string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT}) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 279 | endif() |
| 280 | else() |
| 281 | message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}") |
| 282 | endif() |
| 283 | endif() |
| 284 | |
Oscar Fuentes | 2100fe9 | 2011-02-03 22:48:20 +0000 | [diff] [blame] | 285 | configure_file( |
| 286 | ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake |
| 287 | ${CLANG_BINARY_DIR}/include/clang/Config/config.h) |
| 288 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 289 | include(CMakeParseArguments) |
Oscar Fuentes | c8da1ec | 2011-02-20 22:06:32 +0000 | [diff] [blame] | 290 | |
| 291 | function(clang_tablegen) |
| 292 | # Syntax: |
| 293 | # clang_tablegen output-file [tablegen-arg ...] SOURCE source-file |
| 294 | # [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]] |
| 295 | # |
| 296 | # Generates a custom command for invoking tblgen as |
| 297 | # |
| 298 | # tblgen source-file -o=output-file tablegen-arg ... |
| 299 | # |
| 300 | # and, if cmake-target-name is provided, creates a custom target for |
| 301 | # executing the custom command depending on output-file. It is |
| 302 | # possible to list more files to depend after DEPENDS. |
| 303 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 304 | cmake_parse_arguments(CTG "" "SOURCE;TARGET" "" ${ARGN}) |
Oscar Fuentes | c8da1ec | 2011-02-20 22:06:32 +0000 | [diff] [blame] | 305 | |
| 306 | if( NOT CTG_SOURCE ) |
| 307 | message(FATAL_ERROR "SOURCE source-file required by clang_tablegen") |
| 308 | endif() |
| 309 | |
| 310 | set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} ) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 311 | tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS}) |
Oscar Fuentes | c8da1ec | 2011-02-20 22:06:32 +0000 | [diff] [blame] | 312 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 313 | if(CTG_TARGET) |
| 314 | add_public_tablegen_target(${CTG_TARGET}) |
Oscar Fuentes | a3f787c | 2011-02-20 22:06:44 +0000 | [diff] [blame] | 315 | set_target_properties( ${CTG_TARGET} PROPERTIES FOLDER "Clang tablegenning") |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 316 | set_property(GLOBAL APPEND PROPERTY CLANG_TABLEGEN_TARGETS ${CTG_TARGET}) |
Oscar Fuentes | c8da1ec | 2011-02-20 22:06:32 +0000 | [diff] [blame] | 317 | endif() |
| 318 | endfunction(clang_tablegen) |
| 319 | |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 320 | macro(add_clang_library name) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 321 | cmake_parse_arguments(ARG |
| 322 | "" |
| 323 | "" |
| 324 | "ADDITIONAL_HEADERS" |
| 325 | ${ARGN}) |
| 326 | set(srcs) |
Ted Kremenek | bf5de3f | 2009-03-25 20:34:07 +0000 | [diff] [blame] | 327 | if(MSVC_IDE OR XCODE) |
Jordan Rose | 340d0d3 | 2012-10-23 21:54:03 +0000 | [diff] [blame] | 328 | # Add public headers |
| 329 | file(RELATIVE_PATH lib_path |
| 330 | ${CLANG_SOURCE_DIR}/lib/ |
| 331 | ${CMAKE_CURRENT_SOURCE_DIR} |
| 332 | ) |
| 333 | if(NOT lib_path MATCHES "^[.][.]") |
| 334 | file( GLOB_RECURSE headers |
| 335 | ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.h |
| 336 | ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.def |
| 337 | ) |
| 338 | set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON) |
| 339 | |
| 340 | file( GLOB_RECURSE tds |
| 341 | ${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.td |
| 342 | ) |
| 343 | source_group("TableGen descriptions" FILES ${tds}) |
| 344 | set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON) |
| 345 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 346 | if(headers OR tds) |
| 347 | set(srcs ${headers} ${tds}) |
| 348 | endif() |
Jordan Rose | 340d0d3 | 2012-10-23 21:54:03 +0000 | [diff] [blame] | 349 | endif() |
Ted Kremenek | bf5de3f | 2009-03-25 20:34:07 +0000 | [diff] [blame] | 350 | endif(MSVC_IDE OR XCODE) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 351 | if(srcs OR ARG_ADDITIONAL_HEADERS) |
| 352 | set(srcs |
| 353 | ADDITIONAL_HEADERS |
| 354 | ${srcs} |
| 355 | ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args. |
| 356 | ) |
| 357 | endif() |
| 358 | llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) |
| 359 | |
| 360 | if(TARGET ${name}) |
| 361 | target_link_libraries(${name} ${cmake_2_8_12_INTERFACE} ${LLVM_COMMON_LIBS}) |
| 362 | |
| 363 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libclang") |
| 364 | install(TARGETS ${name} |
| 365 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 366 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 367 | RUNTIME DESTINATION bin) |
| 368 | endif() |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 369 | set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name}) |
Douglas Gregor | ac47bc7 | 2009-09-25 06:35:15 +0000 | [diff] [blame] | 370 | else() |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 371 | # Add empty "phony" target |
| 372 | add_custom_target(${name}) |
Hans Wennborg | 885e36e | 2013-08-24 00:22:23 +0000 | [diff] [blame] | 373 | endif() |
| 374 | |
Oscar Fuentes | a3f787c | 2011-02-20 22:06:44 +0000 | [diff] [blame] | 375 | set_target_properties(${name} PROPERTIES FOLDER "Clang libraries") |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 376 | endmacro(add_clang_library) |
| 377 | |
| 378 | macro(add_clang_executable name) |
Oscar Fuentes | 9917401 | 2011-01-03 17:00:02 +0000 | [diff] [blame] | 379 | add_llvm_executable( ${name} ${ARGN} ) |
Oscar Fuentes | a3f787c | 2011-02-20 22:06:44 +0000 | [diff] [blame] | 380 | set_target_properties(${name} PROPERTIES FOLDER "Clang executables") |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 381 | endmacro(add_clang_executable) |
| 382 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 383 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 384 | |
Oscar Fuentes | 617508f | 2011-03-17 19:03:04 +0000 | [diff] [blame] | 385 | include_directories(BEFORE |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 386 | ${CMAKE_CURRENT_BINARY_DIR}/include |
Oscar Fuentes | 617508f | 2011-03-17 19:03:04 +0000 | [diff] [blame] | 387 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 388 | ) |
| 389 | |
Hans Wennborg | 885e36e | 2013-08-24 00:22:23 +0000 | [diff] [blame] | 390 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 391 | install(DIRECTORY include/clang include/clang-c |
Hans Wennborg | 885e36e | 2013-08-24 00:22:23 +0000 | [diff] [blame] | 392 | DESTINATION include |
| 393 | FILES_MATCHING |
| 394 | PATTERN "*.def" |
| 395 | PATTERN "*.h" |
| 396 | PATTERN "config.h" EXCLUDE |
| 397 | PATTERN ".svn" EXCLUDE |
| 398 | ) |
Chris Lattner | bc6ec75 | 2008-11-11 18:39:10 +0000 | [diff] [blame] | 399 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 400 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang |
Hans Wennborg | 885e36e | 2013-08-24 00:22:23 +0000 | [diff] [blame] | 401 | DESTINATION include |
| 402 | FILES_MATCHING |
| 403 | PATTERN "CMakeFiles" EXCLUDE |
| 404 | PATTERN "*.inc" |
| 405 | ) |
| 406 | endif() |
| 407 | |
| 408 | install(DIRECTORY include/clang-c |
Kovarththanan Rajaratnam | ec700a6 | 2010-04-01 14:24:41 +0000 | [diff] [blame] | 409 | DESTINATION include |
| 410 | FILES_MATCHING |
Hans Wennborg | 885e36e | 2013-08-24 00:22:23 +0000 | [diff] [blame] | 411 | PATTERN "*.h" |
| 412 | PATTERN ".svn" EXCLUDE |
Kovarththanan Rajaratnam | ec700a6 | 2010-04-01 14:24:41 +0000 | [diff] [blame] | 413 | ) |
| 414 | |
Dylan Noblesmith | cc8a945 | 2012-02-14 15:54:49 +0000 | [diff] [blame] | 415 | add_definitions( -D_GNU_SOURCE ) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 416 | |
Jordan Rose | e638503 | 2013-08-22 15:50:02 +0000 | [diff] [blame] | 417 | option(CLANG_ENABLE_ARCMT "Build ARCMT." ON) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 418 | if (CLANG_ENABLE_ARCMT) |
| 419 | set(ENABLE_CLANG_ARCMT "1") |
| 420 | else() |
| 421 | set(ENABLE_CLANG_ARCMT "0") |
Roman Divacky | ff62d64 | 2013-05-29 21:09:18 +0000 | [diff] [blame] | 422 | endif() |
| 423 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 424 | option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON) |
| 425 | if (CLANG_ENABLE_STATIC_ANALYZER) |
| 426 | set(ENABLE_CLANG_STATIC_ANALYZER "1") |
| 427 | else() |
| 428 | set(ENABLE_CLANG_STATIC_ANALYZER "0") |
Roman Divacky | ff62d64 | 2013-05-29 21:09:18 +0000 | [diff] [blame] | 429 | endif() |
| 430 | |
Jordan Rose | e638503 | 2013-08-22 15:50:02 +0000 | [diff] [blame] | 431 | if (NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT) |
| 432 | message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT") |
| 433 | endif() |
| 434 | |
Roman Divacky | ff62d64 | 2013-05-29 21:09:18 +0000 | [diff] [blame] | 435 | if(CLANG_ENABLE_ARCMT) |
| 436 | add_definitions(-DCLANG_ENABLE_ARCMT) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 437 | add_definitions(-DCLANG_ENABLE_OBJC_REWRITER) |
Roman Divacky | ff62d64 | 2013-05-29 21:09:18 +0000 | [diff] [blame] | 438 | endif() |
| 439 | if(CLANG_ENABLE_STATIC_ANALYZER) |
| 440 | add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER) |
| 441 | endif() |
NAKAMURA Takumi | 68f22af | 2012-12-13 16:24:59 +0000 | [diff] [blame] | 442 | |
Douglas Gregor | 8435bf9 | 2011-02-25 19:24:02 +0000 | [diff] [blame] | 443 | # Clang version information |
| 444 | set(CLANG_EXECUTABLE_VERSION |
| 445 | "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING |
| 446 | "Version number that will be placed into the clang executable, in the form XX.YY") |
| 447 | set(LIBCLANG_LIBRARY_VERSION |
| 448 | "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING |
| 449 | "Version number that will be placed into the libclang library , in the form XX.YY") |
| 450 | mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION) |
| 451 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 452 | add_subdirectory(utils/TableGen) |
Douglas Gregor | 8435bf9 | 2011-02-25 19:24:02 +0000 | [diff] [blame] | 453 | |
Douglas Gregor | a393e9e | 2009-03-16 23:06:59 +0000 | [diff] [blame] | 454 | add_subdirectory(include) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 455 | |
| 456 | # All targets below may depend on all tablegen'd files. |
| 457 | get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS) |
| 458 | list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS}) |
| 459 | |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 460 | add_subdirectory(lib) |
Daniel Dunbar | cbcd98b | 2009-03-24 02:52:57 +0000 | [diff] [blame] | 461 | add_subdirectory(tools) |
Michael J. Spencer | 48263ba | 2010-12-16 03:28:42 +0000 | [diff] [blame] | 462 | add_subdirectory(runtime) |
Oscar Fuentes | d2f4e5e | 2008-10-26 00:56:18 +0000 | [diff] [blame] | 463 | |
NAKAMURA Takumi | e3120ae | 2012-07-27 06:17:48 +0000 | [diff] [blame] | 464 | option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 465 | if (CLANG_BUILD_EXAMPLES) |
| 466 | set(ENABLE_CLANG_EXAMPLES "1") |
| 467 | else() |
| 468 | set(ENABLE_CLANG_EXAMPLES "0") |
| 469 | endif() |
NAKAMURA Takumi | e3120ae | 2012-07-27 06:17:48 +0000 | [diff] [blame] | 470 | add_subdirectory(examples) |
| 471 | |
Jordan Rose | 3092d9d | 2013-02-08 01:42:37 +0000 | [diff] [blame] | 472 | option(CLANG_INCLUDE_TESTS |
| 473 | "Generate build targets for the Clang unit tests." |
Jordan Rose | 6bbaa77 | 2013-02-08 07:28:25 +0000 | [diff] [blame] | 474 | ${LLVM_INCLUDE_TESTS}) |
Jordan Rose | 3092d9d | 2013-02-08 01:42:37 +0000 | [diff] [blame] | 475 | |
| 476 | if( CLANG_INCLUDE_TESTS ) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 477 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) |
| 478 | add_subdirectory(unittests) |
| 479 | list(APPEND CLANG_TEST_DEPS ClangUnitTests) |
| 480 | list(APPEND CLANG_TEST_PARAMS |
| 481 | clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg |
| 482 | ) |
| 483 | endif() |
Michael Gottesman | 7758bb5 | 2013-08-20 07:09:54 +0000 | [diff] [blame] | 484 | add_subdirectory(test) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 485 | |
| 486 | if(CLANG_BUILT_STANDALONE) |
| 487 | # Add a global check rule now that all subdirectories have been traversed |
| 488 | # and we know the total set of lit testsuites. |
| 489 | get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES) |
| 490 | get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS) |
| 491 | get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS) |
| 492 | get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS) |
| 493 | add_lit_target(check-all |
| 494 | "Running all regression tests" |
| 495 | ${LLVM_LIT_TESTSUITES} |
| 496 | PARAMS ${LLVM_LIT_PARAMS} |
| 497 | DEPENDS ${LLVM_LIT_DEPENDS} |
| 498 | ARGS ${LLVM_LIT_EXTRA_ARGS} |
| 499 | ) |
| 500 | endif() |
Jeffrey Yasskin | 718b01d | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 501 | endif() |
NAKAMURA Takumi | 792f975 | 2011-02-16 03:07:15 +0000 | [diff] [blame] | 502 | |
Michael Gottesman | 1ab6c6c | 2013-08-28 20:29:40 +0000 | [diff] [blame] | 503 | option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs." |
| 504 | ${LLVM_INCLUDE_DOCS}) |
| 505 | if( CLANG_INCLUDE_DOCS ) |
| 506 | add_subdirectory(docs) |
| 507 | endif() |
| 508 | |
Michael Gottesman | 54b0012 | 2013-08-27 04:40:12 +0000 | [diff] [blame] | 509 | set(CLANG_ORDER_FILE "" CACHE FILEPATH |
| 510 | "Order file to use when compiling clang in order to improve startup time.") |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 511 | |
| 512 | if (CLANG_BUILT_STANDALONE) |
| 513 | # Generate a list of CMake library targets so that other CMake projects can |
| 514 | # link against them. LLVM calls its version of this file LLVMExports.cmake, but |
| 515 | # the usual CMake convention seems to be ${Project}Targets.cmake. |
| 516 | set(CLANG_INSTALL_PACKAGE_DIR share/clang/cmake) |
| 517 | set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}") |
| 518 | get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS) |
| 519 | export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake) |
| 520 | |
| 521 | # Install a <prefix>/share/clang/cmake/ClangConfig.cmake file so that |
| 522 | # find_package(Clang) works. Install the target list with it. |
| 523 | install(FILES |
| 524 | ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake |
| 525 | ${CLANG_BINARY_DIR}/share/clang/cmake/ClangTargets.cmake |
| 526 | DESTINATION share/clang/cmake) |
| 527 | |
| 528 | # Also copy ClangConfig.cmake to the build directory so that dependent projects |
| 529 | # can build against a build directory of Clang more easily. |
| 530 | configure_file( |
| 531 | ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake |
| 532 | ${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake |
| 533 | COPYONLY) |
| 534 | endif () |