Douglas Gregor | 0f9678e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 1 | include(CheckIncludeFile) |
| 2 | include(CheckLibraryExists) |
| 3 | include(CheckSymbolExists) |
| 4 | include(CheckFunctionExists) |
| 5 | include(CheckCXXSourceCompiles) |
| 6 | |
| 7 | # Helper macros and functions |
| 8 | macro(add_cxx_include result files) |
| 9 | set(${result} "") |
| 10 | foreach (file_name ${files}) |
| 11 | set(${result} "${${result}}#include<${file_name}>\n") |
| 12 | endforeach() |
| 13 | endmacro(add_cxx_include files result) |
| 14 | |
| 15 | function(check_type_exists type files variable) |
| 16 | add_cxx_include(includes "${files}") |
| 17 | CHECK_CXX_SOURCE_COMPILES(" |
| 18 | ${includes} ${type} typeVar; |
| 19 | int main() { |
| 20 | return 0; |
| 21 | } |
| 22 | " ${variable}) |
| 23 | endfunction() |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 24 | |
| 25 | # include checks |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 26 | check_include_file(argz.h HAVE_ARGZ_H) |
| 27 | check_include_file(assert.h HAVE_ASSERT_H) |
| 28 | check_include_file(dirent.h HAVE_DIRENT_H) |
| 29 | check_include_file(dl.h HAVE_DL_H) |
| 30 | check_include_file(dld.h HAVE_DLD_H) |
| 31 | check_include_file(dlfcn.h HAVE_DLFCN_H) |
| 32 | check_include_file(errno.h HAVE_ERRNO_H) |
| 33 | check_include_file(execinfo.h HAVE_EXECINFO_H) |
| 34 | check_include_file(fcntl.h HAVE_FCNTL_H) |
| 35 | check_include_file(inttypes.h HAVE_INTTYPES_H) |
| 36 | check_include_file(limits.h HAVE_LIMITS_H) |
| 37 | check_include_file(link.h HAVE_LINK_H) |
| 38 | check_include_file(malloc.h HAVE_MALLOC_H) |
| 39 | check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H) |
| 40 | check_include_file(memory.h HAVE_MEMORY_H) |
| 41 | check_include_file(ndir.h HAVE_NDIR_H) |
| 42 | check_include_file(pthread.h HAVE_PTHREAD_H) |
| 43 | check_include_file(setjmp.h HAVE_SETJMP_H) |
| 44 | check_include_file(signal.h HAVE_SIGNAL_H) |
| 45 | check_include_file(stdint.h HAVE_STDINT_H) |
| 46 | check_include_file(stdio.h HAVE_STDIO_H) |
| 47 | check_include_file(stdlib.h HAVE_STDLIB_H) |
Oscar Fuentes | ab46963 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 48 | check_include_file(string.h HAVE_STRING_H) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 49 | check_include_file(sys/dir.h HAVE_SYS_DIR_H) |
| 50 | check_include_file(sys/dl.h HAVE_SYS_DL_H) |
Douglas Gregor | d1e1dbc | 2009-05-11 18:05:52 +0000 | [diff] [blame] | 51 | check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 52 | check_include_file(sys/mman.h HAVE_SYS_MMAN_H) |
| 53 | check_include_file(sys/ndir.h HAVE_SYS_NDIR_H) |
| 54 | check_include_file(sys/param.h HAVE_SYS_PARAM_H) |
| 55 | check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H) |
| 56 | check_include_file(sys/stat.h HAVE_SYS_STAT_H) |
| 57 | check_include_file(sys/time.h HAVE_SYS_TIME_H) |
| 58 | check_include_file(sys/types.h HAVE_SYS_TYPES_H) |
Douglas Gregor | 5d8931b | 2009-06-05 23:46:34 +0000 | [diff] [blame] | 59 | check_include_file(sys/wait.h HAVE_SYS_WAIT_H) |
Douglas Gregor | 6230bee | 2009-05-18 17:21:34 +0000 | [diff] [blame] | 60 | check_include_file(termios.h HAVE_TERMIOS_H) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 61 | check_include_file(unistd.h HAVE_UNISTD_H) |
| 62 | check_include_file(utime.h HAVE_UTIME_H) |
Oscar Fuentes | ab46963 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 63 | check_include_file(windows.h HAVE_WINDOWS_H) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 64 | |
Oscar Fuentes | 693fcdb | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 65 | # library checks |
Oscar Fuentes | 693fcdb | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 66 | check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) |
Douglas Gregor | f4d8469 | 2009-06-29 16:25:22 +0000 | [diff] [blame] | 67 | check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC) |
| 68 | check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT) |
Oscar Fuentes | 9574c30 | 2009-05-23 02:37:24 +0000 | [diff] [blame] | 69 | check_library_exists(dl dlopen "" HAVE_LIBDL) |
Oscar Fuentes | 693fcdb | 2009-05-06 14:40:37 +0000 | [diff] [blame] | 70 | |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 71 | # function checks |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 72 | check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) |
| 73 | check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE) |
| 74 | check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT) |
Douglas Gregor | d1e1dbc | 2009-05-11 18:05:52 +0000 | [diff] [blame] | 75 | check_function_exists(isatty HAVE_ISATTY) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 76 | check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH) |
| 77 | check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H) |
Edward O'Callaghan | 84354c7 | 2009-10-12 04:00:11 +0000 | [diff] [blame] | 78 | check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 79 | check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH) |
| 80 | check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H) |
Oscar Fuentes | ab46963 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 81 | check_symbol_exists(ceilf math.h HAVE_CEILF) |
| 82 | check_symbol_exists(floorf math.h HAVE_FLOORF) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 83 | check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) |
Douglas Gregor | 97cf1a8 | 2009-06-04 17:22:52 +0000 | [diff] [blame] | 84 | check_symbol_exists(malloc_zone_statistics malloc/malloc.h |
| 85 | HAVE_MALLOC_ZONE_STATISTICS) |
Douglas Gregor | d61302a | 2009-07-27 18:23:41 +0000 | [diff] [blame] | 86 | check_symbol_exists(mkdtemp unistd.h HAVE_MKDTEMP) |
| 87 | check_symbol_exists(mkstemp unistd.h HAVE_MKSTEMP) |
| 88 | check_symbol_exists(mktemp unistd.h HAVE_MKTEMP) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 89 | check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK) |
Edward O'Callaghan | 4b1adaa | 2009-10-05 23:05:32 +0000 | [diff] [blame] | 90 | check_symbol_exists(sbrk unistd.h HAVE_SBRK) |
Oscar Fuentes | ab46963 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 91 | check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL) |
Jeffrey Yasskin | 6f4c705 | 2009-07-01 18:11:20 +0000 | [diff] [blame] | 92 | check_symbol_exists(strerror string.h HAVE_STRERROR) |
| 93 | check_symbol_exists(strerror_r string.h HAVE_STRERROR_R) |
| 94 | check_symbol_exists(strerror_s string.h HAVE_STRERROR_S) |
Jeffrey Yasskin | 41a338b | 2009-09-25 21:07:20 +0000 | [diff] [blame] | 95 | check_symbol_exists(setenv stdlib.h HAVE_SETENV) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 96 | |
Oscar Fuentes | a737458 | 2009-04-04 22:41:07 +0000 | [diff] [blame] | 97 | check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) |
| 98 | if( LLVM_USING_GLIBC ) |
| 99 | add_llvm_definitions( -D_GNU_SOURCE ) |
| 100 | endif() |
| 101 | |
Douglas Gregor | 0f9678e | 2009-10-01 17:25:36 +0000 | [diff] [blame] | 102 | # Type checks |
| 103 | check_type_exists(std::bidirectional_iterator<int,int> "iterator;iostream" HAVE_BI_ITERATOR) |
| 104 | check_type_exists(std::iterator<int,int,int> iterator HAVE_STD_ITERATOR) |
| 105 | check_type_exists(std::forward_iterator<int,int> iterator HAVE_FWD_ITERATOR) |
| 106 | |
| 107 | set(headers "") |
| 108 | if (HAVE_SYS_TYPES_H) |
| 109 | set(headers ${headers} "sys/types.h") |
| 110 | endif() |
| 111 | |
| 112 | if (HAVE_INTTYPES_H) |
| 113 | set(headers ${headers} "inttypes.h") |
| 114 | endif() |
| 115 | |
| 116 | if (HAVE_STDINT_H) |
| 117 | set(headers ${headers} "stdint.h") |
| 118 | endif() |
| 119 | |
| 120 | check_type_exists(uint64_t "${headers}" HAVE_UINT64_T) |
| 121 | check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T) |
| 122 | |
Xerxes Ranby | cdcf979 | 2009-07-17 19:22:41 +0000 | [diff] [blame] | 123 | # Define LLVM_MULTITHREADED if gcc atomic builtins exists. |
| 124 | include(CheckAtomic) |
| 125 | |
Oscar Fuentes | 0a06ee1 | 2008-11-20 03:10:17 +0000 | [diff] [blame] | 126 | include(CheckCXXCompilerFlag) |
Oscar Fuentes | 644cdc3 | 2009-08-26 17:05:06 +0000 | [diff] [blame] | 127 | # On windows all code is position-independent and mingw warns if -fPIC |
| 128 | # is in the command-line. |
| 129 | if( NOT WIN32 ) |
| 130 | check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG) |
| 131 | endif() |
Oscar Fuentes | 0a06ee1 | 2008-11-20 03:10:17 +0000 | [diff] [blame] | 132 | |
Oscar Fuentes | 5afe9b4 | 2008-10-26 00:47:52 +0000 | [diff] [blame] | 133 | include(GetTargetTriple) |
| 134 | get_target_triple(LLVM_HOSTTRIPLE) |
| 135 | message(STATUS "LLVM_HOSTTRIPLE: ${LLVM_HOSTTRIPLE}") |
| 136 | |
Douglas Gregor | d061a39 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 137 | # Determine the native architecture. |
Oscar Fuentes | 453222b | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 138 | string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH) |
| 139 | if( LLVM_NATIVE_ARCH STREQUAL "host" ) |
| 140 | string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOSTTRIPLE}) |
| 141 | endif () |
| 142 | |
Douglas Gregor | d061a39 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 143 | if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86") |
| 144 | set(LLVM_NATIVE_ARCH X86) |
Oscar Fuentes | 453222b | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 145 | elseif (LLVM_NATIVE_ARCH STREQUAL "x86") |
Douglas Gregor | d061a39 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 146 | set(LLVM_NATIVE_ARCH X86) |
Oscar Fuentes | 453222b | 2009-09-13 22:18:38 +0000 | [diff] [blame] | 147 | elseif (LLVM_NATIVE_ARCH STREQUAL "amd64") |
| 148 | set(LLVM_NATIVE_ARCH X86) |
| 149 | elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64") |
Douglas Gregor | d061a39 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 150 | set(LLVM_NATIVE_ARCH X86) |
| 151 | elseif (LLVM_NATIVE_ARCH MATCHES "sparc") |
| 152 | set(LLVM_NATIVE_ARCH Sparc) |
| 153 | elseif (LLVM_NATIVE_ARCH MATCHES "powerpc") |
| 154 | set(LLVM_NATIVE_ARCH PowerPC) |
| 155 | elseif (LLVM_NATIVE_ARCH MATCHES "alpha") |
| 156 | set(LLVM_NATIVE_ARCH Alpha) |
Douglas Gregor | d061a39 | 2009-06-17 17:01:56 +0000 | [diff] [blame] | 157 | elseif (LLVM_NATIVE_ARCH MATCHES "arm") |
| 158 | set(LLVM_NATIVE_ARCH ARM) |
| 159 | elseif (LLVM_NATIVE_ARCH MATCHES "mips") |
| 160 | set(LLVM_NATIVE_ARCH Mips) |
| 161 | elseif (LLVM_NATIVE_ARCH MATCHES "pic16") |
| 162 | set(LLVM_NATIVE_ARCH "PIC16") |
| 163 | elseif (LLVM_NATIVE_ARCH MATCHES "xcore") |
| 164 | set(LLVM_NATIVE_ARCH XCore) |
| 165 | elseif (LLVM_NATIVE_ARCH MATCHES "msp430") |
| 166 | set(LLVM_NATIVE_ARCH MSP430) |
| 167 | else () |
| 168 | message(STATUS |
| 169 | "Unknown architecture ${LLVM_NATIVE_ARCH}; lli will not JIT code") |
| 170 | set(LLVM_NATIVE_ARCH) |
| 171 | endif () |
| 172 | |
| 173 | if (LLVM_NATIVE_ARCH) |
| 174 | list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX) |
| 175 | if (NATIVE_ARCH_IDX EQUAL -1) |
| 176 | message(STATUS |
| 177 | "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code") |
| 178 | set(LLVM_NATIVE_ARCH) |
| 179 | else () |
| 180 | message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}") |
| 181 | endif () |
| 182 | endif() |
| 183 | |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 184 | if( MINGW ) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 185 | set(HAVE_LIBIMAGEHLP 1) |
| 186 | set(HAVE_LIBPSAPI 1) |
Oscar Fuentes | 3ae2f20 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 187 | # TODO: Check existence of libraries. |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 188 | # include(CheckLibraryExists) |
| 189 | # CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP) |
| 190 | endif( MINGW ) |
| 191 | |
Oscar Fuentes | ab46963 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 192 | if( MSVC ) |
| 193 | set(error_t int) |
Cédric Venet | f9e2eba | 2009-02-14 16:13:26 +0000 | [diff] [blame] | 194 | set(mode_t "unsigned short") |
Oscar Fuentes | ab46963 | 2008-10-25 03:29:36 +0000 | [diff] [blame] | 195 | set(LTDL_SHLIBPATH_VAR "PATH") |
| 196 | set(LTDL_SYSSEARCHPATH "") |
| 197 | set(LTDL_DLOPEN_DEPLIBS 1) |
| 198 | set(SHLIBEXT ".lib") |
| 199 | set(LTDL_OBJDIR "_libs") |
| 200 | set(HAVE_STRTOLL 1) |
| 201 | set(strtoll "_strtoi64") |
| 202 | set(strtoull "_strtoui64") |
| 203 | set(stricmp "_stricmp") |
| 204 | set(strdup "_strdup") |
| 205 | else( MSVC ) |
| 206 | set(LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH") |
| 207 | set(LTDL_SYSSEARCHPATH "") # TODO |
| 208 | set(LTDL_DLOPEN_DEPLIBS 0) # TODO |
| 209 | endif( MSVC ) |
| 210 | |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 211 | # FIXME: Signal handler return type, currently hardcoded to 'void' |
| 212 | set(RETSIGTYPE void) |
| 213 | |
Oscar Fuentes | aa3b315 | 2008-11-18 23:45:21 +0000 | [diff] [blame] | 214 | if( LLVM_ENABLE_THREADS ) |
| 215 | if( HAVE_PTHREAD_H OR WIN32 ) |
| 216 | set(ENABLE_THREADS 1) |
| 217 | endif() |
| 218 | endif() |
| 219 | |
| 220 | if( ENABLE_THREADS ) |
| 221 | message(STATUS "Threads enabled.") |
| 222 | else( ENABLE_THREADS ) |
| 223 | message(STATUS "Threads disabled.") |
| 224 | endif() |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 225 | |
| 226 | configure_file( |
Oscar Fuentes | 3ae2f20 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 227 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 228 | ${LLVM_BINARY_DIR}/include/llvm/Config/config.h |
| 229 | ) |
| 230 | |
| 231 | configure_file( |
Oscar Fuentes | 3ae2f20 | 2008-10-29 02:33:15 +0000 | [diff] [blame] | 232 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 233 | ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h |
| 234 | ) |
| 235 | |