]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - cmake/config-ix.cmake
Platform tests for `sys/uio.h' header and `writev' function.
[opencl/llvm.git] / cmake / config-ix.cmake
1 include(CheckIncludeFile)
2 include(CheckLibraryExists)
3 include(CheckSymbolExists)
4 include(CheckFunctionExists)
5 include(CheckCXXSourceCompiles)
6 include(TestBigEndian)
8 if( UNIX AND NOT BEOS )
9   # Used by check_symbol_exists:
10   set(CMAKE_REQUIRED_LIBRARIES m)
11 endif()
13 # Helper macros and functions
14 macro(add_cxx_include result files)
15   set(${result} "")
16   foreach (file_name ${files})
17      set(${result} "${${result}}#include<${file_name}>\n")
18   endforeach()
19 endmacro(add_cxx_include files result)
21 function(check_type_exists type files variable)
22   add_cxx_include(includes "${files}")
23   CHECK_CXX_SOURCE_COMPILES("
24     ${includes} ${type} typeVar;
25     int main() {
26         return 0;
27     }
28     " ${variable})
29 endfunction()
31 # include checks
32 check_include_file(argz.h HAVE_ARGZ_H)
33 check_include_file(assert.h HAVE_ASSERT_H)
34 check_include_file(ctype.h HAVE_CTYPE_H)
35 check_include_file(dirent.h HAVE_DIRENT_H)
36 check_include_file(dl.h HAVE_DL_H)
37 check_include_file(dld.h HAVE_DLD_H)
38 check_include_file(dlfcn.h HAVE_DLFCN_H)
39 check_include_file(errno.h HAVE_ERRNO_H)
40 check_include_file(execinfo.h HAVE_EXECINFO_H)
41 check_include_file(fcntl.h HAVE_FCNTL_H)
42 check_include_file(inttypes.h HAVE_INTTYPES_H)
43 check_include_file(limits.h HAVE_LIMITS_H)
44 check_include_file(link.h HAVE_LINK_H)
45 check_include_file(malloc.h HAVE_MALLOC_H)
46 check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
47 check_include_file(memory.h HAVE_MEMORY_H)
48 check_include_file(ndir.h HAVE_NDIR_H)
49 if( NOT LLVM_ON_WIN32 )
50   check_include_file(pthread.h HAVE_PTHREAD_H)
51 endif()
52 check_include_file(setjmp.h HAVE_SETJMP_H)
53 check_include_file(signal.h HAVE_SIGNAL_H)
54 check_include_file(stdint.h HAVE_STDINT_H)
55 check_include_file(stdio.h HAVE_STDIO_H)
56 check_include_file(stdlib.h HAVE_STDLIB_H)
57 check_include_file(string.h HAVE_STRING_H)
58 check_include_file(strings.h HAVE_STRINGS_H)
59 check_include_file(sys/dir.h HAVE_SYS_DIR_H)
60 check_include_file(sys/dl.h HAVE_SYS_DL_H)
61 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
62 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
63 check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
64 check_include_file(sys/param.h HAVE_SYS_PARAM_H)
65 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
66 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
67 check_include_file(sys/time.h HAVE_SYS_TIME_H)
68 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
69 check_include_file(sys/uio.h HAVE_SYS_UIO_H)
70 check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
71 check_include_file(termios.h HAVE_TERMIOS_H)
72 check_include_file(unistd.h HAVE_UNISTD_H)
73 check_include_file(utime.h HAVE_UTIME_H)
74 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
75 check_include_file(windows.h HAVE_WINDOWS_H)
76 check_include_file(fenv.h HAVE_FENV_H)
77 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
78 check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
80 # library checks
81 if( NOT LLVM_ON_WIN32 )
82   check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
83   check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
84   check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
85   check_library_exists(dl dlopen "" HAVE_LIBDL)
86 endif()
88 # function checks
89 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
90 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
91 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
92 check_function_exists(isatty HAVE_ISATTY)
93 check_symbol_exists(index strings.h HAVE_INDEX)
94 check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
95 check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
96 check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
97 check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
98 check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
99 check_symbol_exists(ceilf math.h HAVE_CEILF)
100 check_symbol_exists(floorf math.h HAVE_FLOORF)
101 check_symbol_exists(fmodf math.h HAVE_FMODF)
102 if( HAVE_SETJMP_H )
103   check_symbol_exists(longjmp setjmp.h HAVE_LONGJMP)
104   check_symbol_exists(setjmp setjmp.h HAVE_SETJMP)
105   check_symbol_exists(siglongjmp setjmp.h HAVE_SIGLONGJMP)
106   check_symbol_exists(sigsetjmp setjmp.h HAVE_SIGSETJMP)
107 endif()
108 if( HAVE_SYS_UIO_H )
109   check_symbol_exists(writev sys/uio.h HAVE_WRITEV)
110 endif()
111 check_symbol_exists(nearbyintf math.h HAVE_NEARBYINTF)
112 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
113 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
114                     HAVE_MALLOC_ZONE_STATISTICS)
115 check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
116 check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
117 check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
118 check_symbol_exists(closedir "sys/types.h;dirent.h" HAVE_CLOSEDIR)
119 check_symbol_exists(opendir "sys/types.h;dirent.h" HAVE_OPENDIR)
120 check_symbol_exists(readdir "sys/types.h;dirent.h" HAVE_READDIR)
121 check_symbol_exists(getcwd unistd.h HAVE_GETCWD)
122 check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
123 check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
124 check_symbol_exists(rindex strings.h HAVE_RINDEX)
125 check_symbol_exists(strchr string.h HAVE_STRCHR)
126 check_symbol_exists(strcmp string.h HAVE_STRCMP)
127 check_symbol_exists(strdup string.h HAVE_STRDUP)
128 check_symbol_exists(strrchr string.h HAVE_STRRCHR)
129 if( NOT LLVM_ON_WIN32 )
130   check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK)
131 endif()
132 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
133 check_symbol_exists(srand48 stdlib.h HAVE_RAND48_SRAND48)
134 if( HAVE_RAND48_SRAND48 )
135   check_symbol_exists(lrand48 stdlib.h HAVE_RAND48_LRAND48)
136   if( HAVE_RAND48_LRAND48 )
137     check_symbol_exists(drand48 stdlib.h HAVE_RAND48_DRAND48)
138     if( HAVE_RAND48_DRAND48 )
139       set(HAVE_RAND48 1 CACHE INTERNAL "are srand48/lrand48/drand48 available?")
140     endif()
141   endif()
142 endif()
143 check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
144 check_symbol_exists(strtoq stdlib.h HAVE_STRTOQ)
145 check_symbol_exists(strerror string.h HAVE_STRERROR)
146 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
147 check_symbol_exists(strerror_s string.h HAVE_STRERROR_S)
148 check_symbol_exists(memcpy string.h HAVE_MEMCPY)
149 check_symbol_exists(memmove string.h HAVE_MEMMOVE)
150 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
151 if ( LLVM_ON_WIN32 )
152   check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
153 endif()
154 if( HAVE_ARGZ_H )
155   check_symbol_exists(argz_append argz.h HAVE_ARGZ_APPEND)
156   check_symbol_exists(argz_create_sep argz.h HAVE_ARGZ_CREATE_SEP)
157   check_symbol_exists(argz_insert argz.h HAVE_ARGZ_INSERT)
158   check_symbol_exists(argz_next argz.h HAVE_ARGZ_NEXT)
159   check_symbol_exists(argz_stringify argz.h HAVE_ARGZ_STRINGIFY)
160 endif()
161 if( HAVE_DLFCN_H )
162   if( HAVE_LIBDL )
163     list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
164   endif()
165   check_symbol_exists(dlerror dlfcn.h HAVE_DLERROR)
166   check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
167   if( HAVE_LIBDL )
168     list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
169   endif()
170 endif()
172 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
173 if( LLVM_USING_GLIBC )
174   add_llvm_definitions( -D_GNU_SOURCE )
175 endif()
177 # Type checks
178 check_type_exists(std::bidirectional_iterator<int,int> "iterator;iostream" HAVE_BI_ITERATOR)
179 check_type_exists(std::iterator<int,int,int> iterator HAVE_STD_ITERATOR)
180 check_type_exists(std::forward_iterator<int,int> iterator HAVE_FWD_ITERATOR)
182 set(headers "")
183 if (HAVE_SYS_TYPES_H)
184   set(headers ${headers} "sys/types.h")
185 endif()
187 if (HAVE_INTTYPES_H)
188   set(headers ${headers} "inttypes.h")
189 endif()
191 if (HAVE_STDINT_H)
192   set(headers ${headers} "stdint.h")
193 endif()
195 check_type_exists(int64_t "${headers}" HAVE_INT64_T)
196 check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
197 check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
198 check_type_exists(error_t errno.h HAVE_ERROR_T)
200 # available programs checks
201 function(llvm_find_program name)
202   string(TOUPPER ${name} NAME)
203   find_program(LLVM_PATH_${NAME} ${name})
204   mark_as_advanced(LLVM_PATH_${NAME})
205   if(LLVM_PATH_${NAME})
206     set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
207     mark_as_advanced(HAVE_${NAME})
208   else(LLVM_PATH_${NAME})
209     set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
210   endif(LLVM_PATH_${NAME})
211 endfunction()
213 llvm_find_program(gv)
214 llvm_find_program(circo)
215 llvm_find_program(twopi)
216 llvm_find_program(neato)
217 llvm_find_program(fdp)
218 llvm_find_program(dot)
219 llvm_find_program(dotty)
221 if( LLVM_ENABLE_FFI )
222   find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
223   if( FFI_INCLUDE_PATH )
224     set(FFI_HEADER ffi.h CACHE INTERNAL "")
225     set(HAVE_FFI_H 1 CACHE INTERNAL "")
226   else()
227     find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
228     if( FFI_INCLUDE_PATH )
229       set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
230       set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
231     endif()
232   endif()
234   if( NOT FFI_HEADER )
235     message(FATAL_ERROR "libffi includes are not found.")
236   endif()
238   find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
239   if( NOT FFI_LIBRARY_PATH )
240     message(FATAL_ERROR "libffi is not found.")
241   endif()
243   list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
244   list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
245   check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
246   list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
247   list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
248 endif( LLVM_ENABLE_FFI )
250 # Define LLVM_MULTITHREADED if gcc atomic builtins exists.
251 include(CheckAtomic)
253 if( LLVM_ENABLE_PIC )
254   set(ENABLE_PIC 1)
255 else()
256   set(ENABLE_PIC 0)
257 endif()
259 include(CheckCXXCompilerFlag)
261 check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
263 include(GetTargetTriple)
264 get_target_triple(LLVM_HOSTTRIPLE)
266 # FIXME: We don't distinguish the target and the host. :(
267 set(TARGET_TRIPLE "${LLVM_HOSTTRIPLE}")
269 # Determine the native architecture.
270 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
271 if( LLVM_NATIVE_ARCH STREQUAL "host" )
272   string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOSTTRIPLE})
273 endif ()
275 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
276   set(LLVM_NATIVE_ARCH X86)
277 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
278   set(LLVM_NATIVE_ARCH X86)
279 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
280   set(LLVM_NATIVE_ARCH X86)
281 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
282   set(LLVM_NATIVE_ARCH X86)
283 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
284   set(LLVM_NATIVE_ARCH Sparc)
285 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
286   set(LLVM_NATIVE_ARCH PowerPC)
287 elseif (LLVM_NATIVE_ARCH MATCHES "alpha")
288   set(LLVM_NATIVE_ARCH Alpha)
289 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
290   set(LLVM_NATIVE_ARCH ARM)
291 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
292   set(LLVM_NATIVE_ARCH Mips)
293 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
294   set(LLVM_NATIVE_ARCH XCore)
295 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
296   set(LLVM_NATIVE_ARCH MSP430)
297 else ()
298   message(STATUS
299     "Unknown architecture ${LLVM_NATIVE_ARCH}; lli will not JIT code")
300   set(LLVM_NATIVE_ARCH)
301 endif ()
303 if (LLVM_NATIVE_ARCH)
304   list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
305   if (NATIVE_ARCH_IDX EQUAL -1)
306     message(STATUS
307       "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
308     set(LLVM_NATIVE_ARCH)
309   else ()
310     message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
311     set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
312     set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
313     set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
314   endif ()
315 endif()
317 if( MINGW )
318   set(HAVE_LIBIMAGEHLP 1)
319   set(HAVE_LIBPSAPI 1)
320   # TODO: Check existence of libraries.
321   #   include(CheckLibraryExists)
322   #   CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
323 endif( MINGW )
325 if( MSVC )
326   set(error_t int)
327   set(mode_t "unsigned short")
328   set(LTDL_SHLIBPATH_VAR "PATH")
329   set(LTDL_SYSSEARCHPATH "")
330   set(LTDL_DLOPEN_DEPLIBS 1)
331   set(SHLIBEXT ".lib")
332   set(LTDL_OBJDIR "_libs")
333   set(HAVE_STRTOLL 1)
334   set(strtoll "_strtoi64")
335   set(strtoull "_strtoui64")
336   set(stricmp "_stricmp")
337   set(strdup "_strdup")
338 else( MSVC )
339   set(LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH")
340   set(LTDL_SYSSEARCHPATH "") # TODO
341   set(LTDL_DLOPEN_DEPLIBS 0)  # TODO
342 endif( MSVC )
344 # FIXME: Signal handler return type, currently hardcoded to 'void'
345 set(RETSIGTYPE void)
347 if( LLVM_ENABLE_THREADS )
348   if( HAVE_PTHREAD_H OR WIN32 )
349     set(ENABLE_THREADS 1)
350   endif()
351 endif()
353 if( ENABLE_THREADS )
354   message(STATUS "Threads enabled.")
355 else( ENABLE_THREADS )
356   message(STATUS "Threads disabled.")
357 endif()
359 set(LLVM_PREFIX ${CMAKE_INSTALL_PREFIX})
361 configure_file(
362   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
363   ${LLVM_BINARY_DIR}/include/llvm/Config/config.h
364   )
366 configure_file(
367   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
368   ${LLVM_BINARY_DIR}/include/llvm/Config/llvm-config.h
369   )
371 configure_file(
372   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
373   ${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h
374   )