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 | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 41 | if( MSVC ) |
| 42 | set(LLVM_TARGETS_TO_BUILD X86 |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 43 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 44 | else( MSVC ) |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 45 | set(LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} |
| 46 | CACHE STRING "Semicolon-separated list of targets to build, or \"all\".") |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 47 | endif( MSVC ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 48 | |
Oscar Fuentes | 4f21c13 | 2008-11-10 01:47:07 +0000 | [diff] [blame] | 49 | if( LLVM_TARGETS_TO_BUILD STREQUAL "all" ) |
| 50 | set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} ) |
| 51 | endif() |
| 52 | |
| 53 | foreach(c ${LLVM_TARGETS_TO_BUILD}) |
| 54 | list(FIND LLVM_ALL_TARGETS ${c} idx) |
| 55 | if( idx LESS 0 ) |
| 56 | message(FATAL_ERROR "The target `${c}' does not exists. |
| 57 | It should be one of\n${LLVM_ALL_TARGETS}") |
| 58 | endif() |
| 59 | endforeach(c) |
| 60 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 61 | set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm) |
| 62 | |
| 63 | # Add path for custom modules |
| 64 | set(CMAKE_MODULE_PATH |
| 65 | ${CMAKE_MODULE_PATH} |
| 66 | "${LLVM_MAIN_SRC_DIR}/cmake" |
| 67 | "${LLVM_MAIN_SRC_DIR}/cmake/modules" |
| 68 | ) |
| 69 | |
| 70 | if(WIN32) |
Oscar Fuentes | 4fd38b8 | 2008-10-30 17:15:54 +0000 | [diff] [blame] | 71 | if(CYGWIN) |
| 72 | set(LLVM_ON_WIN32 0) |
| 73 | set(LLVM_ON_UNIX 1) |
| 74 | else(CYGWIN) |
| 75 | set(LLVM_ON_WIN32 1) |
| 76 | set(LLVM_ON_UNIX 0) |
| 77 | endif(CYGWIN) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 78 | set(LTDL_SHLIB_EXT ".dll") |
| 79 | set(EXEEXT ".exe") |
| 80 | # Maximum path length is 160 for non-unicode paths |
| 81 | set(MAXPATHLEN 160) |
| 82 | else(WIN32) |
| 83 | if(UNIX) |
| 84 | set(LLVM_ON_WIN32 0) |
| 85 | set(LLVM_ON_UNIX 1) |
| 86 | set(LTDL_SHLIB_EXT ".so") |
| 87 | set(EXEEXT "") |
| 88 | # FIXME: Maximum path length is currently set to 'safe' fixed value |
| 89 | set(MAXPATHLEN 2024) |
| 90 | else(UNIX) |
| 91 | MESSAGE(SEND_ERROR "Unable to determine platform") |
| 92 | endif(UNIX) |
| 93 | endif(WIN32) |
| 94 | |
| 95 | if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config ) |
| 96 | set(HAVE_LLVM_CONFIG 1) |
| 97 | endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config ) |
| 98 | # find_file(HAVE_LLVM_CONFIG llvm-config ${LLVM_TOOLS_BINARY_DIR}) |
| 99 | # message(STATUS ${HAVE_LLVM_CONFIG}) |
| 100 | |
Oscar Fuentes | de98db3 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 101 | include(config-ix) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 102 | |
| 103 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} ) |
| 104 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib ) |
| 105 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib ) |
| 106 | |
| 107 | # set(CMAKE_VERBOSE_MAKEFILE true) |
| 108 | |
| 109 | add_definitions( -D__STDC_LIMIT_MACROS ) |
Oscar Fuentes | 0a48698 | 2008-10-30 17:21:37 +0000 | [diff] [blame] | 110 | add_definitions( -D__STDC_CONSTANT_MACROS ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 111 | |
Oscar Fuentes | b0c5699 | 2008-11-04 03:27:24 +0000 | [diff] [blame] | 112 | set(LLVM_PLO_FLAGS "" CACHE |
| 113 | STRING "Flags for creating partially linked objects.") |
| 114 | |
| 115 | if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 116 | # TODO: support other platforms and toolchains. |
| 117 | option(BUILD_32_BITS "Build 32 bits executables and libraries." OFF) |
| 118 | if( BUILD_32_BITS ) |
| 119 | message(STATUS "Building 32 bits executables and libraries.") |
| 120 | add_definitions( -m32 ) |
| 121 | set( CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}" ) |
| 122 | set( CMAKE_LINK_LIBRARY_FLAG "-m32 ${CMAKE_LINK_LIBRARY_FLAG}" ) |
| 123 | set( LLVM_PLO_FLAGS -melf_i386 ${LLVM_PLO_FLAGS} ) |
| 124 | endif( BUILD_32_BITS ) |
| 125 | endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) |
| 126 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 127 | if( MSVC ) |
| 128 | add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS ) |
| 129 | add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS ) |
| 130 | add_definitions( -D_SCL_SECURE_NO_DEPRECATE ) |
Oscar Fuentes | a789af2 | 2008-09-24 19:27:54 +0000 | [diff] [blame] | 131 | add_definitions( -wd4146 -wd4503 -wd4996 -wd4800 -wd4244 -wd4624 ) |
| 132 | add_definitions( -wd4355 -wd4715 ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 133 | endif( MSVC ) |
| 134 | |
Oscar Fuentes | 980e842 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 135 | include_directories( ${LLVM_BINARY_DIR}/include ${LLVM_MAIN_INCLUDE_DIR}) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 136 | #link_directories( d:/dev/lib ) |
| 137 | |
| 138 | #add_subdirectory(lib) |
| 139 | |
| 140 | include(AddLLVM) |
| 141 | include(AddPartiallyLinkedObject) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 142 | include(TableGen) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 143 | |
| 144 | add_subdirectory(lib/Support) |
| 145 | add_subdirectory(lib/System) |
Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 146 | |
| 147 | # Everything else depends on Support and System: |
| 148 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} ) |
| 149 | |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 150 | set(LLVM_TABLEGEN "tblgen" CACHE |
Oscar Fuentes | 41bdedf | 2008-11-10 02:35:55 +0000 | [diff] [blame] | 151 | STRING "Native TableGen executable. Saves building one when cross-compiling.") |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 152 | |
Oscar Fuentes | 02516ba | 2008-11-10 01:32:14 +0000 | [diff] [blame] | 153 | add_subdirectory(utils/TableGen) |
| 154 | |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 155 | if( CMAKE_CROSSCOMPILING ) |
Oscar Fuentes | 02516ba | 2008-11-10 01:32:14 +0000 | [diff] [blame] | 156 | # 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] | 157 | include( CrossCompileLLVM ) |
| 158 | endif( CMAKE_CROSSCOMPILING ) |
| 159 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 160 | add_custom_command(OUTPUT ${llvm_builded_incs_dir}/Intrinsics.gen |
Oscar Fuentes | 3ab40ca | 2008-11-09 18:53:19 +0000 | [diff] [blame] | 161 | COMMAND ${LLVM_TABLEGEN} -gen-intrinsic -I ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}/llvm/Intrinsics.td -o ${llvm_builded_incs_dir}/Intrinsics.gen |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 162 | DEPENDS tblgen |
| 163 | COMMENT "Building intrinsics.gen...") |
| 164 | |
| 165 | add_custom_target(intrinsics_gen ALL |
| 166 | DEPENDS ${llvm_builded_incs_dir}/Intrinsics.gen) |
| 167 | |
Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 168 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} intrinsics_gen ) |
| 169 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 170 | add_subdirectory(lib/VMCore) |
| 171 | add_subdirectory(lib/CodeGen) |
| 172 | add_subdirectory(lib/CodeGen/SelectionDAG) |
| 173 | add_subdirectory(lib/CodeGen/AsmPrinter) |
| 174 | add_subdirectory(lib/Bitcode/Reader) |
| 175 | add_subdirectory(lib/Bitcode/Writer) |
| 176 | add_subdirectory(lib/Transforms/Utils) |
| 177 | add_subdirectory(lib/Transforms/Instrumentation) |
| 178 | add_subdirectory(lib/Transforms/Scalar) |
| 179 | add_subdirectory(lib/Transforms/IPO) |
| 180 | add_subdirectory(lib/Transforms/Hello) |
| 181 | add_subdirectory(lib/Linker) |
| 182 | add_subdirectory(lib/Analysis) |
| 183 | add_subdirectory(lib/Analysis/IPA) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 184 | |
| 185 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 186 | message(STATUS "Targeting ${t}") |
| 187 | add_subdirectory(lib/Target/${t}) |
| 188 | if( EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt ) |
| 189 | add_subdirectory(lib/Target/${t}/AsmPrinter) |
| 190 | endif( EXISTS ${CMAKE_SOURCE_DIR}/lib/Target/${t}/AsmPrinter/CMakeLists.txt ) |
| 191 | endforeach(t) |
| 192 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 193 | add_subdirectory(lib/ExecutionEngine) |
| 194 | add_subdirectory(lib/ExecutionEngine/Interpreter) |
| 195 | add_subdirectory(lib/ExecutionEngine/JIT) |
| 196 | add_subdirectory(lib/Target) |
| 197 | add_subdirectory(lib/AsmParser) |
| 198 | add_subdirectory(lib/Debugger) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 199 | add_subdirectory(lib/Archive) |
| 200 | |
| 201 | add_subdirectory(tools) |
| 202 | |
| 203 | add_subdirectory(examples) |
Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 204 | |
| 205 | install(DIRECTORY include |
| 206 | DESTINATION . |
| 207 | PATTERN ".svn" EXCLUDE |
| 208 | PATTERN "*.cmake" EXCLUDE |
| 209 | PATTERN "*.in" EXCLUDE |
| 210 | ) |
| 211 | |
| 212 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include |
| 213 | DESTINATION . |
| 214 | ) |
| 215 | |
| 216 | # TODO: make and install documentation. |