| Oscar Fuentes | 34fc517 | 2009-04-04 22:52:02 +0000 | [diff] [blame] | 1 | # See docs/CMake.html for instructions about how to build LLVM with CMake. |
| 2 | |
| Cedric Venet | 1d083f4 | 2008-10-30 21:22:00 +0000 | [diff] [blame] | 3 | project(LLVM) |
| Oscar Fuentes | c677c5d | 2010-08-03 15:07:17 +0000 | [diff] [blame] | 4 | cmake_minimum_required(VERSION 2.8) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 5 | |
| Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 6 | # Add path for custom modules |
| 7 | set(CMAKE_MODULE_PATH |
| 8 | ${CMAKE_MODULE_PATH} |
| 9 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" |
| 10 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" |
| 11 | ) |
| 12 | |
| Douglas Gregor | 6b5db95 | 2010-09-23 14:19:21 +0000 | [diff] [blame] | 13 | set(PACKAGE_VERSION "2.9") |
| Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 14 | include(VersionFromVCS) |
| 15 | add_version_info_from_vcs(PACKAGE_VERSION) |
| 16 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 17 | set(PACKAGE_NAME llvm) |
| Chris Lattner | 8c46e85 | 2009-01-28 17:49:03 +0000 | [diff] [blame] | 18 | set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") |
| Oscar Fuentes | f7e73b9 | 2008-10-25 03:49:35 +0000 | [diff] [blame] | 19 | set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu") |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 20 | |
| Oscar Fuentes | 6326a0d | 2008-11-14 03:43:18 +0000 | [diff] [blame] | 21 | if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) |
| 22 | message(FATAL_ERROR "In-source builds are not allowed. |
| 23 | CMake would overwrite the makefiles distributed with LLVM. |
| 24 | Please create a directory and run cmake from there, passing the path |
| 25 | to this source directory as the last argument. |
| 26 | This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. |
| 27 | Please delete them.") |
| 28 | endif() |
| 29 | |
| NAKAMURA Takumi | d420e7b | 2010-11-27 13:10:11 +0000 | [diff] [blame] | 30 | # Run-time build mode; It is used for unittests. |
| 31 | if(MSVC_IDE) |
| 32 | # Expect "$(Configuration)", "$(OutDir)", etc. |
| 33 | # It is expanded by msbuild or similar. |
| 34 | set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}") |
| 35 | elseif(NOT CMAKE_BUILD_TYPE STREQUAL "") |
| 36 | # Expect "Release" "Debug", etc. |
| 37 | # Or unittests could not run. |
| 38 | set(RUNTIME_BUILD_MODE ${CMAKE_BUILD_TYPE}) |
| 39 | else() |
| 40 | # It might be "." |
| 41 | set(RUNTIME_BUILD_MODE "${CMAKE_CFG_INTDIR}") |
| 42 | endif() |
| 43 | |
| Oscar Fuentes | 81a8755 | 2009-06-03 15:11:25 +0000 | [diff] [blame] | 44 | string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 45 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 46 | set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| Oscar Fuentes | 980e842 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 47 | set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 48 | set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 49 | set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin) |
| 50 | set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples) |
| Oscar Fuentes | af0f65f | 2009-06-12 02:49:53 +0000 | [diff] [blame] | 51 | set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 52 | |
| Oscar Fuentes | 6761c5d | 2009-07-13 21:58:44 +0000 | [diff] [blame] | 53 | if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) |
| 54 | file(GLOB_RECURSE |
| 55 | tablegenned_files_on_include_dir |
| 56 | "${LLVM_MAIN_SRC_DIR}/include/llvm/*.gen") |
| 57 | file(GLOB_RECURSE |
| 58 | tablegenned_files_on_lib_dir |
| 59 | "${LLVM_MAIN_SRC_DIR}/lib/Target/*.inc") |
| 60 | if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir) |
| 61 | message(FATAL_ERROR "Apparently there is a previous in-source build, |
| 62 | probably as the result of running `configure' and `make' on |
| 63 | ${LLVM_MAIN_SRC_DIR}. |
| 64 | This may cause problems. The suspicious files are: |
| 65 | ${tablegenned_files_on_lib_dir} |
| 66 | ${tablegenned_files_on_include_dir} |
| 67 | Please clean the source directory.") |
| 68 | endif() |
| 69 | endif() |
| 70 | |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 71 | set(LLVM_ALL_TARGETS |
| 72 | Alpha |
| 73 | ARM |
| Jakob Stoklund Olesen | 73b7bb7 | 2009-08-02 17:32:37 +0000 | [diff] [blame] | 74 | Blackfin |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 75 | CBackend |
| 76 | CellSPU |
| 77 | CppBackend |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 78 | Mips |
| Wesley Peck | c84a956 | 2010-03-05 15:15:55 +0000 | [diff] [blame] | 79 | MBlaze |
| Richard Pennington | a51984b | 2009-07-09 20:27:09 +0000 | [diff] [blame] | 80 | MSP430 |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 81 | PowerPC |
| Oscar Fuentes | b2c70cf | 2010-09-28 14:02:36 +0000 | [diff] [blame] | 82 | PTX |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 83 | Sparc |
| Daniel Dunbar | 3f189a3 | 2009-07-20 00:24:17 +0000 | [diff] [blame] | 84 | SystemZ |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 85 | X86 |
| 86 | XCore |
| 87 | ) |
| 88 | |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 89 | if( MSVC ) |
| 90 | set(LLVM_TARGETS_TO_BUILD X86 |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 91 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 92 | else( MSVC ) |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 93 | set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} |
| 94 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 95 | endif( MSVC ) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 96 | |
| Chandler Carruth | 6b24116 | 2010-10-19 08:21:25 +0000 | [diff] [blame] | 97 | set(CLANG_RESOURCE_DIR "" CACHE STRING |
| 98 | "Relative directory from the Clang binary to its resource files.") |
| 99 | |
| Oscar Fuentes | 8e3c169 | 2009-11-12 06:48:09 +0000 | [diff] [blame] | 100 | set(C_INCLUDE_DIRS "" CACHE STRING |
| 101 | "Colon separated list of directories clang will search for headers.") |
| 102 | |
| Oscar Fuentes | a9ff139 | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 103 | set(LLVM_TARGET_ARCH "host" |
| 104 | CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.") |
| 105 | |
| NAKAMURA Takumi | e7ae70b | 2010-11-11 04:09:35 +0000 | [diff] [blame] | 106 | set(LIT_ARGS_DEFAULT "-sv") |
| 107 | if (MSVC OR XCODE) |
| 108 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 109 | endif() |
| 110 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" |
| 111 | CACHE STRING "Default options for lit") |
| 112 | |
| Oscar Fuentes | 4b44283 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 113 | option(LLVM_ENABLE_THREADS "Use threads if available." ON) |
| 114 | |
| Oscar Fuentes | 81a8755 | 2009-06-03 15:11:25 +0000 | [diff] [blame] | 115 | if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" ) |
| Oscar Fuentes | 76941b2 | 2009-06-04 09:26:16 +0000 | [diff] [blame] | 116 | option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF) |
| Oscar Fuentes | 81a8755 | 2009-06-03 15:11:25 +0000 | [diff] [blame] | 117 | else() |
| Oscar Fuentes | 76941b2 | 2009-06-04 09:26:16 +0000 | [diff] [blame] | 118 | option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON) |
| Oscar Fuentes | 81a8755 | 2009-06-03 15:11:25 +0000 | [diff] [blame] | 119 | endif() |
| 120 | |
| Oscar Fuentes | 76941b2 | 2009-06-04 09:26:16 +0000 | [diff] [blame] | 121 | if( LLVM_ENABLE_ASSERTIONS ) |
| Oscar Fuentes | af10910 | 2009-07-05 18:43:52 +0000 | [diff] [blame] | 122 | # MSVC doesn't like _DEBUG on release builds. See PR 4379. |
| Oscar Fuentes | e8c81ea | 2009-07-05 23:58:20 +0000 | [diff] [blame] | 123 | if( NOT MSVC ) |
| Oscar Fuentes | af10910 | 2009-07-05 18:43:52 +0000 | [diff] [blame] | 124 | add_definitions( -D_DEBUG ) |
| 125 | endif() |
| Oscar Fuentes | 76941b2 | 2009-06-04 09:26:16 +0000 | [diff] [blame] | 126 | # On Release builds cmake automatically defines NDEBUG, so we |
| 127 | # explicitly undefine it: |
| 128 | if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" ) |
| 129 | add_definitions( -UNDEBUG ) |
| 130 | endif() |
| 131 | else() |
| 132 | if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" ) |
| 133 | add_definitions( -DNDEBUG ) |
| 134 | endif() |
| Oscar Fuentes | 81a8755 | 2009-06-03 15:11:25 +0000 | [diff] [blame] | 135 | endif() |
| 136 | |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 137 | if( LLVM_TARGETS_TO_BUILD STREQUAL "all" ) |
| 138 | set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} ) |
| 139 | endif() |
| 140 | |
| Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 141 | set(LLVM_ENUM_TARGETS "") |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 142 | foreach(c ${LLVM_TARGETS_TO_BUILD}) |
| 143 | list(FIND LLVM_ALL_TARGETS ${c} idx) |
| 144 | if( idx LESS 0 ) |
| Gabor Greif | 9befba8 | 2009-08-12 08:37:37 +0000 | [diff] [blame] | 145 | message(FATAL_ERROR "The target `${c}' does not exist. |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 146 | It should be one of\n${LLVM_ALL_TARGETS}") |
| Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 147 | else() |
| 148 | set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${c})\n") |
| Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 149 | endif() |
| 150 | endforeach(c) |
| 151 | |
| Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 152 | # Produce llvm/Config/Targets.def |
| 153 | configure_file( |
| 154 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in |
| 155 | ${LLVM_BINARY_DIR}/include/llvm/Config/Targets.def |
| 156 | ) |
| 157 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 158 | set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm) |
| 159 | |
| Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 160 | include(AddLLVMDefinitions) |
| 161 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 162 | if(WIN32) |
| Oscar Fuentes | 4fd38b8 | 2008-10-30 17:15:54 +0000 | [diff] [blame] | 163 | if(CYGWIN) |
| 164 | set(LLVM_ON_WIN32 0) |
| 165 | set(LLVM_ON_UNIX 1) |
| 166 | else(CYGWIN) |
| 167 | set(LLVM_ON_WIN32 1) |
| 168 | set(LLVM_ON_UNIX 0) |
| 169 | endif(CYGWIN) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 170 | set(LTDL_SHLIB_EXT ".dll") |
| 171 | set(EXEEXT ".exe") |
| 172 | # Maximum path length is 160 for non-unicode paths |
| 173 | set(MAXPATHLEN 160) |
| 174 | else(WIN32) |
| 175 | if(UNIX) |
| 176 | set(LLVM_ON_WIN32 0) |
| 177 | set(LLVM_ON_UNIX 1) |
| Daniel Dunbar | 05dafd8 | 2009-09-22 06:09:37 +0000 | [diff] [blame] | 178 | if(APPLE) |
| 179 | set(LTDL_SHLIB_EXT ".dylib") |
| 180 | else(APPLE) |
| 181 | set(LTDL_SHLIB_EXT ".so") |
| 182 | endif(APPLE) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 183 | set(EXEEXT "") |
| 184 | # FIXME: Maximum path length is currently set to 'safe' fixed value |
| 185 | set(MAXPATHLEN 2024) |
| 186 | else(UNIX) |
| 187 | MESSAGE(SEND_ERROR "Unable to determine platform") |
| 188 | endif(UNIX) |
| 189 | endif(WIN32) |
| 190 | |
| Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 191 | include(config-ix) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 192 | |
| Oscar Fuentes | 1e02bf0 | 2009-08-18 15:29:35 +0000 | [diff] [blame] | 193 | option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON) |
| Oscar Fuentes | 64fb4c8 | 2008-11-20 19:13:51 +0000 | [diff] [blame] | 194 | |
| Douglas Gregor | 318de60 | 2009-06-05 23:46:34 +0000 | [diff] [blame] | 195 | set(ENABLE_PIC 0) |
| Oscar Fuentes | 64fb4c8 | 2008-11-20 19:13:51 +0000 | [diff] [blame] | 196 | if( LLVM_ENABLE_PIC ) |
| Daniel Dunbar | 3620618 | 2009-11-08 00:34:22 +0000 | [diff] [blame] | 197 | if( XCODE ) |
| 198 | # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't |
| 199 | # know how to disable this, so just force ENABLE_PIC off for now. |
| 200 | message(STATUS "Warning: -fPIC not supported with Xcode.") |
| 201 | else( XCODE ) |
| 202 | if( SUPPORTS_FPIC_FLAG ) |
| 203 | message(STATUS "Building with -fPIC") |
| 204 | add_llvm_definitions(-fPIC) |
| 205 | set(ENABLE_PIC 1) |
| 206 | else( SUPPORTS_FPIC_FLAG ) |
| 207 | message(STATUS "Warning: -fPIC not supported.") |
| 208 | endif() |
| 209 | endif() |
| Oscar Fuentes | 64fb4c8 | 2008-11-20 19:13:51 +0000 | [diff] [blame] | 210 | endif() |
| 211 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 212 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} ) |
| 213 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib ) |
| 214 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib ) |
| 215 | |
| 216 | # set(CMAKE_VERBOSE_MAKEFILE true) |
| 217 | |
| Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 218 | add_llvm_definitions( -D__STDC_LIMIT_MACROS ) |
| 219 | add_llvm_definitions( -D__STDC_CONSTANT_MACROS ) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 220 | |
| Daniel Dunbar | 9ea3a2c | 2009-12-01 19:11:36 +0000 | [diff] [blame] | 221 | # MSVC has a gazillion warnings with this. |
| 222 | if( MSVC ) |
| 223 | option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF) |
| 224 | else( MSVC ) |
| 225 | option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON) |
| 226 | endif() |
| 227 | |
| Oscar Fuentes | f12a900 | 2009-12-01 02:21:51 +0000 | [diff] [blame] | 228 | option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) |
| 229 | option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) |
| 230 | |
| Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 231 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 232 | # TODO: support other platforms and toolchains. |
| Oscar Fuentes | 6307b94 | 2008-11-19 00:10:39 +0000 | [diff] [blame] | 233 | option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) |
| 234 | if( LLVM_BUILD_32_BITS ) |
| Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 235 | message(STATUS "Building 32 bits executables and libraries.") |
| Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 236 | add_llvm_definitions( -m32 ) |
| Oscar Fuentes | 6307b94 | 2008-11-19 00:10:39 +0000 | [diff] [blame] | 237 | list(APPEND CMAKE_EXE_LINKER_FLAGS -m32) |
| 238 | list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32) |
| Oscar Fuentes | 6307b94 | 2008-11-19 00:10:39 +0000 | [diff] [blame] | 239 | endif( LLVM_BUILD_32_BITS ) |
| Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 240 | endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 241 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 242 | if( MSVC ) |
| Oscar Fuentes | 02a8f76 | 2010-08-05 01:25:48 +0000 | [diff] [blame] | 243 | include(ChooseMSVCCRT) |
| Stefanus Du Toit | 4ba3a0e | 2009-06-08 21:18:31 +0000 | [diff] [blame] | 244 | |
| Oscar Fuentes | 9a0107d | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 245 | add_llvm_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS ) |
| 246 | add_llvm_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS ) |
| 247 | add_llvm_definitions( -D_SCL_SECURE_NO_DEPRECATE ) |
| 248 | add_llvm_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 ) |
| Francois Pichet | 0b8f0a2 | 2010-11-20 15:39:03 +0000 | [diff] [blame] | 249 | add_llvm_definitions( -wd4355 -wd4715 -wd4180 -wd4345 -wd4224 -wd4267 -wd4291 ) |
| Francois Pichet | 97b2f72 | 2010-12-07 01:25:06 +0000 | [diff] [blame] | 250 | add_llvm_definitions( -wd4275 ) |
| 251 | |
| 252 | # Promote "enumerator in switch of enum is not handled" to level 1 warning. |
| 253 | add_llvm_definitions( -w14062 ) |
| Stefanus Du Toit | 4ba3a0e | 2009-06-08 21:18:31 +0000 | [diff] [blame] | 254 | |
| Daniel Dunbar | 2c4df5a | 2009-07-19 01:35:10 +0000 | [diff] [blame] | 255 | # Suppress 'new behavior: elements of array 'array' will be default initialized' |
| 256 | add_llvm_definitions( -wd4351 ) |
| 257 | |
| Oscar Fuentes | f12a900 | 2009-12-01 02:21:51 +0000 | [diff] [blame] | 258 | # Enable warnings |
| 259 | if (LLVM_ENABLE_WARNINGS) |
| 260 | add_llvm_definitions( /W4 /Wall ) |
| 261 | if (LLVM_ENABLE_PEDANTIC) |
| 262 | # No MSVC equivalent available |
| 263 | endif (LLVM_ENABLE_PEDANTIC) |
| 264 | endif (LLVM_ENABLE_WARNINGS) |
| 265 | if (LLVM_ENABLE_WERROR) |
| 266 | add_llvm_definitions( /WX ) |
| 267 | endif (LLVM_ENABLE_WERROR) |
| Oscar Fuentes | 2343b10 | 2009-11-30 23:50:14 +0000 | [diff] [blame] | 268 | elseif( CMAKE_COMPILER_IS_GNUCXX ) |
| Oscar Fuentes | f12a900 | 2009-12-01 02:21:51 +0000 | [diff] [blame] | 269 | if (LLVM_ENABLE_WARNINGS) |
| 270 | add_llvm_definitions( -Wall -W -Wno-unused-parameter -Wwrite-strings ) |
| 271 | if (LLVM_ENABLE_PEDANTIC) |
| 272 | add_llvm_definitions( -pedantic -Wno-long-long ) |
| 273 | endif (LLVM_ENABLE_PEDANTIC) |
| 274 | endif (LLVM_ENABLE_WARNINGS) |
| 275 | if (LLVM_ENABLE_WERROR) |
| 276 | add_llvm_definitions( -Werror ) |
| 277 | endif (LLVM_ENABLE_WERROR) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 278 | endif( MSVC ) |
| 279 | |
| Oscar Fuentes | 980e842 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 280 | include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR}) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 281 | |
| Edward O'Callaghan | c6cf5fe | 2009-10-12 04:00:11 +0000 | [diff] [blame] | 282 | if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) |
| Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 283 | SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-include llvm/Support/Solaris.h") |
| Edward O'Callaghan | c6cf5fe | 2009-10-12 04:00:11 +0000 | [diff] [blame] | 284 | endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS ) |
| 285 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 286 | include(AddLLVM) |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 287 | include(TableGen) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 288 | |
| Michael J. Spencer | 1c4e934 | 2010-09-11 02:13:39 +0000 | [diff] [blame] | 289 | if( MINGW ) |
| 290 | get_system_libs(LLVM_SYSTEM_LIBS_LIST) |
| 291 | foreach(l ${LLVM_SYSTEM_LIBS_LIST}) |
| 292 | set(LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS} -l${l}") |
| 293 | endforeach() |
| 294 | set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}") |
| 295 | set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}${LLVM_SYSTEM_LIBS}") |
| 296 | endif() |
| 297 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 298 | add_subdirectory(lib/Support) |
| Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 299 | |
| Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 300 | # Everything else depends on Support: |
| Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 301 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} ) |
| 302 | |
| Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 303 | set(LLVM_TABLEGEN "tblgen" CACHE |
| Oscar Fuentes | 41bdedf | 2008-11-10 02:35:55 +0000 | [diff] [blame] | 304 | STRING "Native TableGen executable. Saves building one when cross-compiling.") |
| Oscar Fuentes | 99b9489 | 2009-06-11 04:16:10 +0000 | [diff] [blame] | 305 | # Effective tblgen executable to be used: |
| 306 | set(LLVM_TABLEGEN_EXE ${LLVM_TABLEGEN}) |
| Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 307 | |
| Oscar Fuentes | 02516ba | 2008-11-10 01:32:14 +0000 | [diff] [blame] | 308 | add_subdirectory(utils/TableGen) |
| 309 | |
| Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 310 | if( CMAKE_CROSSCOMPILING ) |
| Oscar Fuentes | 02516ba | 2008-11-10 01:32:14 +0000 | [diff] [blame] | 311 | # This adds a dependency on target `tblgen', so must go after utils/TableGen |
| Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 312 | include( CrossCompileLLVM ) |
| 313 | endif( CMAKE_CROSSCOMPILING ) |
| 314 | |
| Oscar Fuentes | 422fcf3 | 2008-11-15 00:24:38 +0000 | [diff] [blame] | 315 | add_subdirectory(include/llvm) |
| Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 316 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 317 | add_subdirectory(lib/VMCore) |
| 318 | add_subdirectory(lib/CodeGen) |
| 319 | add_subdirectory(lib/CodeGen/SelectionDAG) |
| 320 | add_subdirectory(lib/CodeGen/AsmPrinter) |
| 321 | add_subdirectory(lib/Bitcode/Reader) |
| 322 | add_subdirectory(lib/Bitcode/Writer) |
| 323 | add_subdirectory(lib/Transforms/Utils) |
| 324 | add_subdirectory(lib/Transforms/Instrumentation) |
| Douglas Gregor | f1c3a86 | 2010-01-04 21:58:55 +0000 | [diff] [blame] | 325 | add_subdirectory(lib/Transforms/InstCombine) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 326 | add_subdirectory(lib/Transforms/Scalar) |
| 327 | add_subdirectory(lib/Transforms/IPO) |
| 328 | add_subdirectory(lib/Transforms/Hello) |
| 329 | add_subdirectory(lib/Linker) |
| 330 | add_subdirectory(lib/Analysis) |
| 331 | add_subdirectory(lib/Analysis/IPA) |
| Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 332 | add_subdirectory(lib/MC) |
| Daniel Dunbar | 4bd8dc3 | 2010-01-22 02:04:33 +0000 | [diff] [blame] | 333 | add_subdirectory(lib/MC/MCParser) |
| Chris Lattner | 847da55 | 2010-07-20 18:25:19 +0000 | [diff] [blame] | 334 | add_subdirectory(lib/MC/MCDisassembler) |
| Michael J. Spencer | 68b3f0c | 2010-11-15 03:21:41 +0000 | [diff] [blame] | 335 | add_subdirectory(lib/Object) |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 336 | |
| Douglas Gregor | 4d20c24 | 2009-07-20 18:30:25 +0000 | [diff] [blame] | 337 | add_subdirectory(utils/FileCheck) |
| Daniel Dunbar | 48f7ce8 | 2009-09-24 06:23:57 +0000 | [diff] [blame] | 338 | add_subdirectory(utils/count) |
| 339 | add_subdirectory(utils/not) |
| Michael J. Spencer | becf392 | 2010-09-13 17:52:38 +0000 | [diff] [blame] | 340 | add_subdirectory(utils/llvm-lit) |
| Douglas Gregor | 4d20c24 | 2009-07-20 18:30:25 +0000 | [diff] [blame] | 341 | |
| Oscar Fuentes | 75caad4 | 2009-08-14 04:55:21 +0000 | [diff] [blame] | 342 | set(LLVM_ENUM_ASM_PRINTERS "") |
| 343 | set(LLVM_ENUM_ASM_PARSERS "") |
| Daniel Dunbar | fa3f0b9 | 2009-11-25 04:30:13 +0000 | [diff] [blame] | 344 | set(LLVM_ENUM_DISASSEMBLERS "") |
| Oscar Fuentes | 75caad4 | 2009-08-14 04:55:21 +0000 | [diff] [blame] | 345 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 346 | message(STATUS "Targeting ${t}") |
| 347 | add_subdirectory(lib/Target/${t}) |
| Daniel Dunbar | b5a8c08 | 2009-07-15 07:04:27 +0000 | [diff] [blame] | 348 | add_subdirectory(lib/Target/${t}/TargetInfo) |
| Oscar Fuentes | db2c509 | 2010-11-14 21:17:13 +0000 | [diff] [blame] | 349 | set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} ) |
| 350 | file(GLOB asmp_file "${td}/*AsmPrinter.cpp") |
| 351 | if( asmp_file ) |
| Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 352 | set(LLVM_ENUM_ASM_PRINTERS |
| Chris Lattner | aeafb89 | 2010-11-14 19:12:57 +0000 | [diff] [blame] | 353 | "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n") |
| Oscar Fuentes | 14b0c05 | 2010-11-14 20:15:05 +0000 | [diff] [blame] | 354 | endif() |
| Oscar Fuentes | db2c509 | 2010-11-14 21:17:13 +0000 | [diff] [blame] | 355 | if( EXISTS ${td}/InstPrinter/CMakeLists.txt ) |
| Oscar Fuentes | bab2b01 | 2010-10-02 02:38:42 +0000 | [diff] [blame] | 356 | add_subdirectory(lib/Target/${t}/InstPrinter) |
| Oscar Fuentes | db2c509 | 2010-11-14 21:17:13 +0000 | [diff] [blame] | 357 | endif() |
| 358 | if( EXISTS ${td}/AsmParser/CMakeLists.txt ) |
| Oscar Fuentes | 75caad4 | 2009-08-14 04:55:21 +0000 | [diff] [blame] | 359 | add_subdirectory(lib/Target/${t}/AsmParser) |
| Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 360 | set(LLVM_ENUM_ASM_PARSERS |
| Oscar Fuentes | 75caad4 | 2009-08-14 04:55:21 +0000 | [diff] [blame] | 361 | "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n") |
| Oscar Fuentes | db2c509 | 2010-11-14 21:17:13 +0000 | [diff] [blame] | 362 | endif() |
| 363 | if( EXISTS ${td}/Disassembler/CMakeLists.txt ) |
| Daniel Dunbar | fa3f0b9 | 2009-11-25 04:30:13 +0000 | [diff] [blame] | 364 | add_subdirectory(lib/Target/${t}/Disassembler) |
| 365 | set(LLVM_ENUM_DISASSEMBLERS |
| 366 | "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n") |
| Oscar Fuentes | db2c509 | 2010-11-14 21:17:13 +0000 | [diff] [blame] | 367 | endif() |
| Oscar Fuentes | b78829e | 2009-08-16 05:16:43 +0000 | [diff] [blame] | 368 | set(CURRENT_LLVM_TARGET) |
| Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 369 | endforeach(t) |
| 370 | |
| Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 371 | # Produce llvm/Config/AsmPrinters.def |
| 372 | configure_file( |
| 373 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in |
| 374 | ${LLVM_BINARY_DIR}/include/llvm/Config/AsmPrinters.def |
| 375 | ) |
| 376 | |
| Daniel Dunbar | 092a9dd | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 377 | # Produce llvm/Config/AsmParsers.def |
| 378 | configure_file( |
| 379 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in |
| 380 | ${LLVM_BINARY_DIR}/include/llvm/Config/AsmParsers.def |
| 381 | ) |
| 382 | |
| Daniel Dunbar | fa3f0b9 | 2009-11-25 04:30:13 +0000 | [diff] [blame] | 383 | # Produce llvm/Config/Disassemblers.def |
| 384 | configure_file( |
| 385 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in |
| 386 | ${LLVM_BINARY_DIR}/include/llvm/Config/Disassemblers.def |
| 387 | ) |
| 388 | |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 389 | add_subdirectory(lib/ExecutionEngine) |
| 390 | add_subdirectory(lib/ExecutionEngine/Interpreter) |
| 391 | add_subdirectory(lib/ExecutionEngine/JIT) |
| Wesley Peck | b977f04 | 2010-11-17 23:35:07 +0000 | [diff] [blame] | 392 | add_subdirectory(lib/ExecutionEngine/MCJIT) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 393 | add_subdirectory(lib/Target) |
| 394 | add_subdirectory(lib/AsmParser) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 395 | add_subdirectory(lib/Archive) |
| 396 | |
| Oscar Fuentes | 5c6bf65 | 2009-03-06 01:16:52 +0000 | [diff] [blame] | 397 | add_subdirectory(projects) |
| Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 398 | |
| Oscar Fuentes | a6c1dbd | 2010-09-25 20:43:06 +0000 | [diff] [blame] | 399 | option(LLVM_BUILD_TOOLS |
| 400 | "Build the LLVM tools. If OFF, just generate build targets." ON) |
| 401 | option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON) |
| 402 | if( LLVM_INCLUDE_TOOLS ) |
| 403 | add_subdirectory(tools) |
| 404 | endif() |
| Oscar Fuentes | c81f56d | 2009-08-16 20:56:30 +0000 | [diff] [blame] | 405 | |
| Oscar Fuentes | a6c1dbd | 2010-09-25 20:43:06 +0000 | [diff] [blame] | 406 | option(LLVM_BUILD_EXAMPLES |
| 407 | "Build the LLVM example programs. If OFF, just generate build targets." OFF) |
| 408 | option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON) |
| 409 | if( LLVM_INCLUDE_EXAMPLES ) |
| 410 | add_subdirectory(examples) |
| 411 | endif() |
| Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 412 | |
| Oscar Fuentes | a6c1dbd | 2010-09-25 20:43:06 +0000 | [diff] [blame] | 413 | option(LLVM_BUILD_TESTS |
| 414 | "Build LLVM unit tests. If OFF, just generate build targes." OFF) |
| 415 | option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON) |
| 416 | if( LLVM_INCLUDE_TESTS ) |
| 417 | add_subdirectory(test) |
| 418 | add_subdirectory(utils/unittest) |
| 419 | add_subdirectory(unittests) |
| NAKAMURA Takumi | 15b337c | 2010-10-26 05:08:27 +0000 | [diff] [blame] | 420 | if (MSVC) |
| Michael J. Spencer | bbb9ea7 | 2010-10-11 19:55:38 +0000 | [diff] [blame] | 421 | # This utility is used to prevent chrashing tests from calling Dr. Watson on |
| 422 | # Windows. |
| 423 | add_subdirectory(utils/KillTheDoctor) |
| 424 | endif() |
| Oscar Fuentes | a6c1dbd | 2010-09-25 20:43:06 +0000 | [diff] [blame] | 425 | endif() |
| Michael J. Spencer | ee6944f | 2010-09-24 09:01:13 +0000 | [diff] [blame] | 426 | |
| Oscar Fuentes | 6252e98 | 2010-08-09 03:26:43 +0000 | [diff] [blame] | 427 | add_subdirectory(cmake/modules) |
| 428 | |
| Oscar Fuentes | 1d7c43b | 2009-10-27 19:57:29 +0000 | [diff] [blame] | 429 | install(DIRECTORY include/ |
| 430 | DESTINATION include |
| 431 | FILES_MATCHING |
| Oscar Fuentes | bc2eb13 | 2009-10-30 11:42:08 +0000 | [diff] [blame] | 432 | PATTERN "*.def" |
| Oscar Fuentes | 1d7c43b | 2009-10-27 19:57:29 +0000 | [diff] [blame] | 433 | PATTERN "*.h" |
| 434 | PATTERN "*.td" |
| Oscar Fuentes | a2281e7 | 2009-10-27 20:04:22 +0000 | [diff] [blame] | 435 | PATTERN "*.inc" |
| Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 436 | PATTERN ".svn" EXCLUDE |
| Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 437 | ) |
| 438 | |
| Oscar Fuentes | 1d7c43b | 2009-10-27 19:57:29 +0000 | [diff] [blame] | 439 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ |
| 440 | DESTINATION include |
| 441 | FILES_MATCHING |
| 442 | PATTERN "*.def" |
| 443 | PATTERN "*.h" |
| 444 | PATTERN "*.gen" |
| Oscar Fuentes | a2281e7 | 2009-10-27 20:04:22 +0000 | [diff] [blame] | 445 | PATTERN "*.inc" |
| Oscar Fuentes | 1d7c43b | 2009-10-27 19:57:29 +0000 | [diff] [blame] | 446 | # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def" |
| 447 | PATTERN "CMakeFiles" EXCLUDE |
| 448 | PATTERN ".svn" EXCLUDE |
| Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 449 | ) |
| 450 | |
| 451 | # TODO: make and install documentation. |
| Oscar Fuentes | 4d156d3 | 2010-10-14 21:11:51 +0000 | [diff] [blame] | 452 | |
| 453 | set(CPACK_PACKAGE_VENDOR "LLVM") |
| 454 | set(CPACK_PACKAGE_VERSION_MAJOR 2) |
| 455 | set(CPACK_PACKAGE_VERSION_MINOR 9) |
| 456 | add_version_info_from_vcs(CPACK_PACKAGE_VERSION_PATCH) |
| 457 | include(CPack) |
| NAKAMURA Takumi | 4c8710d | 2010-11-19 03:19:18 +0000 | [diff] [blame] | 458 | |
| 459 | # Workaround for MSVS10 to avoid the Dialog Hell |
| 460 | # FIXME: This could be removed with future version of CMake. |
| 461 | if(MSVC_VERSION EQUAL 1600) |
| 462 | set(LLVM_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/LLVM.sln") |
| 463 | if( EXISTS "${LLVM_SLN_FILENAME}" ) |
| 464 | file(APPEND "${LLVM_SLN_FILENAME}" "\n# This should be regenerated!\n") |
| 465 | endif() |
| 466 | endif() |