Cedric Venet | 1d083f4 | 2008-10-30 21:22:00 +0000 | [diff] [blame] | 1 | project(LLVM) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 2 | cmake_minimum_required(VERSION 2.6.1) |
| 3 | |
| 4 | set(PACKAGE_NAME llvm) |
| 5 | set(PACKAGE_VERSION svn) |
Oscar Fuentes | f7e73b9 | 2008-10-25 03:49:35 +0000 | [diff] [blame] | 6 | set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 7 | |
Oscar Fuentes | 6326a0d | 2008-11-14 03:43:18 +0000 | [diff] [blame] | 8 | if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) |
| 9 | message(FATAL_ERROR "In-source builds are not allowed. |
| 10 | CMake would overwrite the makefiles distributed with LLVM. |
| 11 | Please create a directory and run cmake from there, passing the path |
| 12 | to this source directory as the last argument. |
| 13 | This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. |
| 14 | Please delete them.") |
| 15 | endif() |
| 16 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 17 | include(FindPerl) |
| 18 | |
| 19 | set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Oscar Fuentes | 980e842 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 20 | set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 21 | set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 22 | set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin) |
| 23 | set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples) |
| 24 | |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 25 | set(LLVM_ALL_TARGETS |
| 26 | Alpha |
| 27 | ARM |
| 28 | CBackend |
| 29 | CellSPU |
| 30 | CppBackend |
| 31 | IA64 |
| 32 | Mips |
| 33 | MSIL |
| 34 | PIC16 |
| 35 | PowerPC |
| 36 | Sparc |
| 37 | X86 |
| 38 | XCore |
| 39 | ) |
| 40 | |
Oscar Fuentes | 7f6f21e | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 41 | # List of targets whose asmprinters need to be forced to link |
| 42 | # into executables on some platforms (i.e. Windows): |
| 43 | set(LLVM_ASMPRINTERS_FORCE_LINK X86 PowerPC) |
| 44 | |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 45 | if( MSVC ) |
| 46 | set(LLVM_TARGETS_TO_BUILD X86 |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 47 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 48 | else( MSVC ) |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 49 | set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} |
| 50 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 51 | endif( MSVC ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 52 | |
Oscar Fuentes | 4b44283 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 53 | option(LLVM_ENABLE_THREADS "Use threads if available." ON) |
| 54 | |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 55 | if( LLVM_TARGETS_TO_BUILD STREQUAL "all" ) |
| 56 | set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} ) |
| 57 | endif() |
| 58 | |
| 59 | foreach(c ${LLVM_TARGETS_TO_BUILD}) |
| 60 | list(FIND LLVM_ALL_TARGETS ${c} idx) |
| 61 | if( idx LESS 0 ) |
| 62 | message(FATAL_ERROR "The target `${c}' does not exists. |
| 63 | It should be one of\n${LLVM_ALL_TARGETS}") |
| 64 | endif() |
| 65 | endforeach(c) |
| 66 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 67 | set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm) |
| 68 | |
| 69 | # Add path for custom modules |
| 70 | set(CMAKE_MODULE_PATH |
| 71 | ${CMAKE_MODULE_PATH} |
| 72 | "${LLVM_MAIN_SRC_DIR}/cmake" |
| 73 | "${LLVM_MAIN_SRC_DIR}/cmake/modules" |
| 74 | ) |
| 75 | |
| 76 | if(WIN32) |
Oscar Fuentes | 4fd38b8 | 2008-10-30 17:15:54 +0000 | [diff] [blame] | 77 | if(CYGWIN) |
| 78 | set(LLVM_ON_WIN32 0) |
| 79 | set(LLVM_ON_UNIX 1) |
| 80 | else(CYGWIN) |
| 81 | set(LLVM_ON_WIN32 1) |
| 82 | set(LLVM_ON_UNIX 0) |
| 83 | endif(CYGWIN) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 84 | set(LTDL_SHLIB_EXT ".dll") |
| 85 | set(EXEEXT ".exe") |
| 86 | # Maximum path length is 160 for non-unicode paths |
| 87 | set(MAXPATHLEN 160) |
| 88 | else(WIN32) |
| 89 | if(UNIX) |
| 90 | set(LLVM_ON_WIN32 0) |
| 91 | set(LLVM_ON_UNIX 1) |
| 92 | set(LTDL_SHLIB_EXT ".so") |
| 93 | set(EXEEXT "") |
| 94 | # FIXME: Maximum path length is currently set to 'safe' fixed value |
| 95 | set(MAXPATHLEN 2024) |
| 96 | else(UNIX) |
| 97 | MESSAGE(SEND_ERROR "Unable to determine platform") |
| 98 | endif(UNIX) |
| 99 | endif(WIN32) |
| 100 | |
| 101 | if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config ) |
| 102 | set(HAVE_LLVM_CONFIG 1) |
| 103 | endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 104 | |
Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 105 | include(config-ix) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 106 | |
Oscar Fuentes | 64fb4c8 | 2008-11-20 19:13:51 +0000 | [diff] [blame] | 107 | option(LLVM_ENABLE_PIC "Build Position-Independent Code" OFF) |
| 108 | |
| 109 | if( LLVM_ENABLE_PIC ) |
| 110 | if( SUPPORTS_FPIC_FLAG ) |
| 111 | message(STATUS "Building with -fPIC") |
| 112 | add_definitions(-fPIC) |
| 113 | else( SUPPORTS_FPIC_FLAG ) |
| 114 | message(STATUS "Warning: -fPIC not supported.") |
| 115 | endif() |
| 116 | endif() |
| 117 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 118 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} ) |
| 119 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib ) |
| 120 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib ) |
| 121 | |
| 122 | # set(CMAKE_VERBOSE_MAKEFILE true) |
| 123 | |
| 124 | add_definitions( -D__STDC_LIMIT_MACROS ) |
Oscar Fuentes | 0a48698 | 2008-10-30 17:21:37 +0000 | [diff] [blame] | 125 | add_definitions( -D__STDC_CONSTANT_MACROS ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 126 | |
Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 127 | set(LLVM_PLO_FLAGS "" CACHE |
| 128 | STRING "Flags for creating partially linked objects.") |
| 129 | |
| 130 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 131 | # TODO: support other platforms and toolchains. |
Oscar Fuentes | 6307b94 | 2008-11-19 00:10:39 +0000 | [diff] [blame] | 132 | option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) |
| 133 | if( LLVM_BUILD_32_BITS ) |
Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 134 | message(STATUS "Building 32 bits executables and libraries.") |
| 135 | add_definitions( -m32 ) |
Oscar Fuentes | 6307b94 | 2008-11-19 00:10:39 +0000 | [diff] [blame] | 136 | list(APPEND CMAKE_EXE_LINKER_FLAGS -m32) |
| 137 | list(APPEND CMAKE_SHARED_LINKER_FLAGS -m32) |
Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 138 | set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} ) |
Oscar Fuentes | 6307b94 | 2008-11-19 00:10:39 +0000 | [diff] [blame] | 139 | endif( LLVM_BUILD_32_BITS ) |
Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 140 | endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 141 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 142 | if( MSVC ) |
| 143 | add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS ) |
| 144 | add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS ) |
| 145 | add_definitions( -D_SCL_SECURE_NO_DEPRECATE ) |
Oscar Fuentes | a789af2 | 2008-09-24 19:27:54 +0000 | [diff] [blame] | 146 | add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 ) |
| 147 | add_definitions( -wd4355 -wd4715 ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 148 | endif( MSVC ) |
| 149 | |
Oscar Fuentes | 980e842 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 150 | include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR}) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 151 | |
| 152 | include(AddLLVM) |
| 153 | include(AddPartiallyLinkedObject) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 154 | include(TableGen) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 155 | |
| 156 | add_subdirectory(lib/Support) |
| 157 | add_subdirectory(lib/System) |
Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 158 | |
| 159 | # Everything else depends on Support and System: |
| 160 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} ) |
| 161 | |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 162 | set(LLVM_TABLEGEN "tblgen" CACHE |
Oscar Fuentes | 41bdedf | 2008-11-10 02:35:55 +0000 | [diff] [blame] | 163 | STRING "Native TableGen executable. Saves building one when cross-compiling.") |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 164 | |
Oscar Fuentes | 02516ba | 2008-11-10 01:32:14 +0000 | [diff] [blame] | 165 | add_subdirectory(utils/TableGen) |
| 166 | |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 167 | if( CMAKE_CROSSCOMPILING ) |
Oscar Fuentes | 02516ba | 2008-11-10 01:32:14 +0000 | [diff] [blame] | 168 | # 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] | 169 | include( CrossCompileLLVM ) |
| 170 | endif( CMAKE_CROSSCOMPILING ) |
| 171 | |
Oscar Fuentes | 422fcf3 | 2008-11-15 00:24:38 +0000 | [diff] [blame] | 172 | add_subdirectory(include/llvm) |
Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 173 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 174 | add_subdirectory(lib/VMCore) |
| 175 | add_subdirectory(lib/CodeGen) |
| 176 | add_subdirectory(lib/CodeGen/SelectionDAG) |
| 177 | add_subdirectory(lib/CodeGen/AsmPrinter) |
| 178 | add_subdirectory(lib/Bitcode/Reader) |
| 179 | add_subdirectory(lib/Bitcode/Writer) |
| 180 | add_subdirectory(lib/Transforms/Utils) |
| 181 | add_subdirectory(lib/Transforms/Instrumentation) |
| 182 | add_subdirectory(lib/Transforms/Scalar) |
| 183 | add_subdirectory(lib/Transforms/IPO) |
| 184 | add_subdirectory(lib/Transforms/Hello) |
| 185 | add_subdirectory(lib/Linker) |
| 186 | add_subdirectory(lib/Analysis) |
| 187 | add_subdirectory(lib/Analysis/IPA) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 188 | |
| 189 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 190 | message(STATUS "Targeting ${t}") |
| 191 | add_subdirectory(lib/Target/${t}) |
Oscar Fuentes | cccecb8 | 2008-11-14 22:21:02 +0000 | [diff] [blame] | 192 | if( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt ) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 193 | add_subdirectory(lib/Target/${t}/AsmPrinter) |
Oscar Fuentes | cccecb8 | 2008-11-14 22:21:02 +0000 | [diff] [blame] | 194 | endif( EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt ) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 195 | endforeach(t) |
| 196 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 197 | add_subdirectory(lib/ExecutionEngine) |
| 198 | add_subdirectory(lib/ExecutionEngine/Interpreter) |
| 199 | add_subdirectory(lib/ExecutionEngine/JIT) |
| 200 | add_subdirectory(lib/Target) |
| 201 | add_subdirectory(lib/AsmParser) |
| 202 | add_subdirectory(lib/Debugger) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 203 | add_subdirectory(lib/Archive) |
| 204 | |
| 205 | add_subdirectory(tools) |
| 206 | |
| 207 | add_subdirectory(examples) |
Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 208 | |
| 209 | install(DIRECTORY include |
| 210 | DESTINATION . |
| 211 | PATTERN ".svn" EXCLUDE |
| 212 | PATTERN "*.cmake" EXCLUDE |
| 213 | PATTERN "*.in" EXCLUDE |
| 214 | ) |
| 215 | |
| 216 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include |
| 217 | DESTINATION . |
| 218 | ) |
| 219 | |
| 220 | # TODO: make and install documentation. |