1 include(CheckIncludeFile)
2 include(CheckLibraryExists)
3 include(CheckSymbolExists)
4 include(CheckFunctionExists)
5 include(CheckCXXSourceCompiles)
8 # Used by check_symbol_exists:
9 set(CMAKE_REQUIRED_LIBRARIES m)
12 # Helper macros and functions
13 macro(add_cxx_include result files)
15 foreach (file_name ${files})
16 set(${result} "${${result}}#include<${file_name}>\n")
18 endmacro(add_cxx_include files result)
20 function(check_type_exists type files variable)
21 add_cxx_include(includes "${files}")
22 CHECK_CXX_SOURCE_COMPILES("
23 ${includes} ${type} typeVar;
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)
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(windows.h HAVE_WINDOWS_H)
73 if( NOT LLVM_ON_WIN32 )
74 check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
75 check_library_exists(pthread pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
76 check_library_exists(pthread pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
77 check_library_exists(dl dlopen "" HAVE_LIBDL)
81 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
82 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
83 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
84 check_function_exists(isatty HAVE_ISATTY)
85 check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
86 check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
87 check_symbol_exists(finite ieeefp.h HAVE_FINITE_IN_IEEEFP_H)
88 check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
89 check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
90 check_symbol_exists(ceilf math.h HAVE_CEILF)
91 check_symbol_exists(floorf math.h HAVE_FLOORF)
92 check_symbol_exists(nearbyintf math.h HAVE_NEARBYINTF)
93 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
94 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
95 HAVE_MALLOC_ZONE_STATISTICS)
96 check_symbol_exists(mkdtemp "stdlib.h;unistd.h" HAVE_MKDTEMP)
97 check_symbol_exists(mkstemp "stdlib.h;unistd.h" HAVE_MKSTEMP)
98 check_symbol_exists(mktemp "stdlib.h;unistd.h" HAVE_MKTEMP)
99 if( NOT LLVM_ON_WIN32 )
100 check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK)
102 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
103 check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
104 check_symbol_exists(strerror string.h HAVE_STRERROR)
105 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
106 check_symbol_exists(strerror_s string.h HAVE_STRERROR_S)
107 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
109 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
110 if( LLVM_USING_GLIBC )
111 add_llvm_definitions( -D_GNU_SOURCE )
115 check_type_exists(std::bidirectional_iterator<int,int> "iterator;iostream" HAVE_BI_ITERATOR)
116 check_type_exists(std::iterator<int,int,int> iterator HAVE_STD_ITERATOR)
117 check_type_exists(std::forward_iterator<int,int> iterator HAVE_FWD_ITERATOR)
120 if (HAVE_SYS_TYPES_H)
121 set(headers ${headers} "sys/types.h")
125 set(headers ${headers} "inttypes.h")
129 set(headers ${headers} "stdint.h")
132 check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
133 check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
135 # available programs checks
136 function(llvm_find_program name)
137 string(TOUPPER ${name} NAME)
138 find_program(LLVM_PATH_${NAME} ${name})
139 mark_as_advanced(LLVM_PATH_${NAME})
140 if(LLVM_PATH_${NAME})
141 set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
142 mark_as_advanced(HAVE_${NAME})
143 else(LLVM_PATH_${NAME})
144 set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
145 endif(LLVM_PATH_${NAME})
148 llvm_find_program(gv)
149 llvm_find_program(circo)
150 llvm_find_program(twopi)
151 llvm_find_program(neato)
152 llvm_find_program(fdp)
153 llvm_find_program(dot)
154 llvm_find_program(dotty)
156 # Define LLVM_MULTITHREADED if gcc atomic builtins exists.
159 include(CheckCXXCompilerFlag)
160 # On windows all code is position-independent and mingw warns if -fPIC
161 # is in the command-line.
163 check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
166 include(GetTargetTriple)
167 get_target_triple(LLVM_HOSTTRIPLE)
169 # FIXME: We don't distinguish the target and the host. :(
170 set(TARGET_TRIPLE "${LLVM_HOSTTRIPLE}")
172 # Determine the native architecture.
173 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
174 if( LLVM_NATIVE_ARCH STREQUAL "host" )
175 string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOSTTRIPLE})
178 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
179 set(LLVM_NATIVE_ARCH X86)
180 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
181 set(LLVM_NATIVE_ARCH X86)
182 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
183 set(LLVM_NATIVE_ARCH X86)
184 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
185 set(LLVM_NATIVE_ARCH X86)
186 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
187 set(LLVM_NATIVE_ARCH Sparc)
188 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
189 set(LLVM_NATIVE_ARCH PowerPC)
190 elseif (LLVM_NATIVE_ARCH MATCHES "alpha")
191 set(LLVM_NATIVE_ARCH Alpha)
192 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
193 set(LLVM_NATIVE_ARCH ARM)
194 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
195 set(LLVM_NATIVE_ARCH Mips)
196 elseif (LLVM_NATIVE_ARCH MATCHES "pic16")
197 set(LLVM_NATIVE_ARCH "PIC16")
198 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
199 set(LLVM_NATIVE_ARCH XCore)
200 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
201 set(LLVM_NATIVE_ARCH MSP430)
204 "Unknown architecture ${LLVM_NATIVE_ARCH}; lli will not JIT code")
205 set(LLVM_NATIVE_ARCH)
208 if (LLVM_NATIVE_ARCH)
209 list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
210 if (NATIVE_ARCH_IDX EQUAL -1)
212 "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
213 set(LLVM_NATIVE_ARCH)
215 message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
220 set(HAVE_LIBIMAGEHLP 1)
222 # TODO: Check existence of libraries.
223 # include(CheckLibraryExists)
224 # CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
229 set(mode_t "unsigned short")
230 set(LTDL_SHLIBPATH_VAR "PATH")
231 set(LTDL_SYSSEARCHPATH "")
232 set(LTDL_DLOPEN_DEPLIBS 1)
234 set(LTDL_OBJDIR "_libs")
236 set(strtoll "_strtoi64")
237 set(strtoull "_strtoui64")
238 set(stricmp "_stricmp")
239 set(strdup "_strdup")
241 set(LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH")
242 set(LTDL_SYSSEARCHPATH "") # TODO
243 set(LTDL_DLOPEN_DEPLIBS 0) # TODO
246 # FIXME: Signal handler return type, currently hardcoded to 'void'
249 if( LLVM_ENABLE_THREADS )
250 if( HAVE_PTHREAD_H OR WIN32 )
251 set(ENABLE_THREADS 1)
256 message(STATUS "Threads enabled.")
257 else( ENABLE_THREADS )
258 message(STATUS "Threads disabled.")
262 ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
263 ${LLVM_BINARY_DIR}/include/llvm/Config/config.h
267 ${LLVM_MAIN_INCLUDE_DIR}/llvm/System/DataTypes.h.cmake
268 ${LLVM_BINARY_DIR}/include/llvm/System/DataTypes.h