Per discussion with Sanjiv, remove the PIC16 target from mainline. When/if
[oota-llvm.git] / cmake / config-ix.cmake
1 include(CheckIncludeFile)
2 include(CheckLibraryExists)
3 include(CheckSymbolExists)
4 include(CheckFunctionExists)
5 include(CheckCXXSourceCompiles)
6
7 if( UNIX AND NOT BEOS )
8   # Used by check_symbol_exists:
9   set(CMAKE_REQUIRED_LIBRARIES m)
10 endif()
11
12 # Helper macros and functions
13 macro(add_cxx_include result files)
14   set(${result} "")
15   foreach (file_name ${files})
16      set(${result} "${${result}}#include<${file_name}>\n")
17   endforeach()
18 endmacro(add_cxx_include files result)
19
20 function(check_type_exists type files variable)
21   add_cxx_include(includes "${files}")
22   CHECK_CXX_SOURCE_COMPILES("
23     ${includes} ${type} typeVar;
24     int main() {
25         return 0;
26     }
27     " ${variable})
28 endfunction()
29
30 # include checks
31 check_include_file(argz.h HAVE_ARGZ_H)
32 check_include_file(assert.h HAVE_ASSERT_H)
33 check_include_file(dirent.h HAVE_DIRENT_H)
34 check_include_file(dl.h HAVE_DL_H)
35 check_include_file(dld.h HAVE_DLD_H)
36 check_include_file(dlfcn.h HAVE_DLFCN_H)
37 check_include_file(errno.h HAVE_ERRNO_H)
38 check_include_file(execinfo.h HAVE_EXECINFO_H)
39 check_include_file(fcntl.h HAVE_FCNTL_H)
40 check_include_file(inttypes.h HAVE_INTTYPES_H)
41 check_include_file(limits.h HAVE_LIMITS_H)
42 check_include_file(link.h HAVE_LINK_H)
43 check_include_file(malloc.h HAVE_MALLOC_H)
44 check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
45 check_include_file(memory.h HAVE_MEMORY_H)
46 check_include_file(ndir.h HAVE_NDIR_H)
47 if( NOT LLVM_ON_WIN32 )
48   check_include_file(pthread.h HAVE_PTHREAD_H)
49 endif()
50 check_include_file(setjmp.h HAVE_SETJMP_H)
51 check_include_file(signal.h HAVE_SIGNAL_H)
52 check_include_file(stdint.h HAVE_STDINT_H)
53 check_include_file(stdio.h HAVE_STDIO_H)
54 check_include_file(stdlib.h HAVE_STDLIB_H)
55 check_include_file(string.h HAVE_STRING_H)
56 check_include_file(sys/dir.h HAVE_SYS_DIR_H)
57 check_include_file(sys/dl.h HAVE_SYS_DL_H)
58 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
59 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
60 check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
61 check_include_file(sys/param.h HAVE_SYS_PARAM_H)
62 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
63 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
64 check_include_file(sys/time.h HAVE_SYS_TIME_H)
65 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
66 check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
67 check_include_file(termios.h HAVE_TERMIOS_H)
68 check_include_file(unistd.h HAVE_UNISTD_H)
69 check_include_file(utime.h HAVE_UTIME_H)
70 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
71 check_include_file(windows.h HAVE_WINDOWS_H)
72 check_include_file(fenv.h HAVE_FENV_H)
73
74 # library checks
75 if( NOT LLVM_ON_WIN32 )
76   check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
77   check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
78   check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
79   check_library_exists(dl dlopen "" HAVE_LIBDL)
80 endif()
81
82 # function checks
83 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
84 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
85 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
86 check_function_exists(isatty HAVE_ISATTY)
87 check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
88 check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
89 check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
90 check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
91 check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
92 check_symbol_exists(ceilf math.h HAVE_CEILF)
93 check_symbol_exists(floorf math.h HAVE_FLOORF)
94 check_symbol_exists(nearbyintf math.h HAVE_NEARBYINTF)
95 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
96 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
97                     HAVE_MALLOC_ZONE_STATISTICS)
98 check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
99 check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
100 check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
101 if( NOT LLVM_ON_WIN32 )
102   check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK)
103 endif()
104 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
105 check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
106 check_symbol_exists(strerror string.h HAVE_STRERROR)
107 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
108 check_symbol_exists(strerror_s string.h HAVE_STRERROR_S)
109 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
110
111 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
112 if( LLVM_USING_GLIBC )
113   add_llvm_definitions( -D_GNU_SOURCE )
114 endif()
115
116 # Type checks
117 check_type_exists(std::bidirectional_iterator<int,int> "iterator;iostream" HAVE_BI_ITERATOR)
118 check_type_exists(std::iterator<int,int,int> iterator HAVE_STD_ITERATOR)
119 check_type_exists(std::forward_iterator<int,int> iterator HAVE_FWD_ITERATOR)
120
121 set(headers "")
122 if (HAVE_SYS_TYPES_H)
123   set(headers ${headers} "sys/types.h")
124 endif()
125
126 if (HAVE_INTTYPES_H)
127   set(headers ${headers} "inttypes.h")
128 endif()
129
130 if (HAVE_STDINT_H)
131   set(headers ${headers} "stdint.h")
132 endif()
133
134 check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
135 check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
136
137 # available programs checks
138 function(llvm_find_program name)
139   string(TOUPPER ${name} NAME)
140   find_program(LLVM_PATH_${NAME} ${name})
141   mark_as_advanced(LLVM_PATH_${NAME})
142   if(LLVM_PATH_${NAME})
143     set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
144     mark_as_advanced(HAVE_${NAME})
145   else(LLVM_PATH_${NAME})
146     set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
147   endif(LLVM_PATH_${NAME})
148 endfunction()
149
150 llvm_find_program(gv)
151 llvm_find_program(circo)
152 llvm_find_program(twopi)
153 llvm_find_program(neato)
154 llvm_find_program(fdp)
155 llvm_find_program(dot)
156 llvm_find_program(dotty)
157
158 # Define LLVM_MULTITHREADED if gcc atomic builtins exists.
159 include(CheckAtomic)
160
161 include(CheckCXXCompilerFlag)
162 # On windows all code is position-independent and mingw warns if -fPIC
163 # is in the command-line.
164 if( NOT WIN32 )
165   check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
166 endif()
167
168 check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
169
170 include(GetTargetTriple)
171 get_target_triple(LLVM_HOSTTRIPLE)
172
173 # FIXME: We don't distinguish the target and the host. :(
174 set(TARGET_TRIPLE "${LLVM_HOSTTRIPLE}")
175
176 # Determine the native architecture.
177 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
178 if( LLVM_NATIVE_ARCH STREQUAL "host" )
179   string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOSTTRIPLE})
180 endif ()
181
182 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
183   set(LLVM_NATIVE_ARCH X86)
184 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
185   set(LLVM_NATIVE_ARCH X86)
186 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
187   set(LLVM_NATIVE_ARCH X86)
188 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
189   set(LLVM_NATIVE_ARCH X86)
190 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
191   set(LLVM_NATIVE_ARCH Sparc)
192 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
193   set(LLVM_NATIVE_ARCH PowerPC)
194 elseif (LLVM_NATIVE_ARCH MATCHES "alpha")
195   set(LLVM_NATIVE_ARCH Alpha)
196 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
197   set(LLVM_NATIVE_ARCH ARM)
198 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
199   set(LLVM_NATIVE_ARCH Mips)
200 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
201   set(LLVM_NATIVE_ARCH XCore)
202 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
203   set(LLVM_NATIVE_ARCH MSP430)
204 else ()
205   message(STATUS
206     "Unknown architecture ${LLVM_NATIVE_ARCH}; lli will not JIT code")
207   set(LLVM_NATIVE_ARCH)
208 endif ()
209
210 if (LLVM_NATIVE_ARCH)
211   list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
212   if (NATIVE_ARCH_IDX EQUAL -1)
213     message(STATUS
214       "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
215     set(LLVM_NATIVE_ARCH)
216   else ()
217     message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
218     set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
219     set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
220     set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
221   endif ()
222 endif()
223
224 if( MINGW )
225   set(HAVE_LIBIMAGEHLP 1)
226   set(HAVE_LIBPSAPI 1)
227   # TODO: Check existence of libraries.
228   #   include(CheckLibraryExists)
229   #   CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
230 endif( MINGW )
231
232 if( MSVC )
233   set(error_t int)
234   set(mode_t "unsigned short")
235   set(LTDL_SHLIBPATH_VAR "PATH")
236   set(LTDL_SYSSEARCHPATH "")
237   set(LTDL_DLOPEN_DEPLIBS 1)
238   set(SHLIBEXT ".lib")
239   set(LTDL_OBJDIR "_libs")
240   set(HAVE_STRTOLL 1)
241   set(strtoll "_strtoi64")
242   set(strtoull "_strtoui64")
243   set(stricmp "_stricmp")
244   set(strdup "_strdup")
245 else( MSVC )
246   set(LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH")
247   set(LTDL_SYSSEARCHPATH "") # TODO
248   set(LTDL_DLOPEN_DEPLIBS 0)  # TODO
249 endif( MSVC )
250
251 # FIXME: Signal handler return type, currently hardcoded to 'void'
252 set(RETSIGTYPE void)
253
254 if( LLVM_ENABLE_THREADS )
255   if( HAVE_PTHREAD_H OR WIN32 )
256     set(ENABLE_THREADS 1)
257   endif()
258 endif()
259
260 if( ENABLE_THREADS )
261   message(STATUS "Threads enabled.")
262 else( ENABLE_THREADS )
263   message(STATUS "Threads disabled.")
264 endif()
265
266 set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
267
268 configure_file(
269   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
270   ${LLVM_BINARY_DIR}/include/llvm/Config/config.h
271   )
272
273 configure_file(
274   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
275   ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h
276   )
277
278 configure_file(
279   ${LLVM_MAIN_INCLUDE_DIR}/llvm/System/DataTypes.h.cmake
280   ${LLVM_BINARY_DIR}/include/llvm/System/DataTypes.h
281   )
282