320335cf0fe037fcd95ee55140b6b94c11596bc2
[oota-llvm.git] / cmake / config-ix.cmake
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()
24
25 # include checks
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)
48 check_include_file(string.h HAVE_STRING_H)
49 check_include_file(sys/dir.h HAVE_SYS_DIR_H)
50 check_include_file(sys/dl.h HAVE_SYS_DL_H)
51 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
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)
59 check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
60 check_include_file(termios.h HAVE_TERMIOS_H)
61 check_include_file(unistd.h HAVE_UNISTD_H)
62 check_include_file(utime.h HAVE_UTIME_H)
63 check_include_file(windows.h HAVE_WINDOWS_H)
64
65 # library checks
66 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
67 check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
68 check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
69 check_library_exists(dl dlopen "" HAVE_LIBDL)
70
71 # function checks
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)
75 check_function_exists(isatty HAVE_ISATTY)
76 check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
77 check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
78 check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
79 check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
80 check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
81 check_symbol_exists(ceilf math.h HAVE_CEILF)
82 check_symbol_exists(floorf math.h HAVE_FLOORF)
83 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
84 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
85                     HAVE_MALLOC_ZONE_STATISTICS)
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)
89 check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK)
90 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
91 check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
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)
95 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
96
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
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
123 # Define LLVM_MULTITHREADED if gcc atomic builtins exists.
124 include(CheckAtomic)
125
126 include(CheckCXXCompilerFlag)
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()
132
133 include(GetTargetTriple)
134 get_target_triple(LLVM_HOSTTRIPLE)
135 message(STATUS "LLVM_HOSTTRIPLE: ${LLVM_HOSTTRIPLE}")
136
137 # Determine the native architecture.
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
143 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
144   set(LLVM_NATIVE_ARCH X86)
145 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
146   set(LLVM_NATIVE_ARCH X86)
147 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
148   set(LLVM_NATIVE_ARCH X86)
149 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
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)
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
184 if( MINGW )
185   set(HAVE_LIBIMAGEHLP 1)
186   set(HAVE_LIBPSAPI 1)
187   # TODO: Check existence of libraries.
188   #   include(CheckLibraryExists)
189   #   CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
190 endif( MINGW )
191
192 if( MSVC )
193   set(error_t int)
194   set(mode_t "unsigned short")
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
211 # FIXME: Signal handler return type, currently hardcoded to 'void'
212 set(RETSIGTYPE void)
213
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()
225
226 configure_file(
227   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
228   ${LLVM_BINARY_DIR}/include/llvm/Config/config.h
229   )
230
231 configure_file(
232   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
233   ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h
234   )
235