1 | include(CheckIncludeFile)
|
---|
2 | include(CheckLibraryExists)
|
---|
3 | include(CheckSymbolExists)
|
---|
4 | include(CheckFunctionExists)
|
---|
5 | include(CheckCXXSourceCompiles)
|
---|
6 |
|
---|
7 | if( UNIX )
|
---|
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(windows.h HAVE_WINDOWS_H)
|
---|
71 |
|
---|
72 | # library checks
|
---|
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)
|
---|
78 | endif()
|
---|
79 |
|
---|
80 | # function checks
|
---|
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)
|
---|
101 | endif()
|
---|
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)
|
---|
108 |
|
---|
109 | check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
|
---|
110 | if( LLVM_USING_GLIBC )
|
---|
111 | add_llvm_definitions( -D_GNU_SOURCE )
|
---|
112 | endif()
|
---|
113 |
|
---|
114 | # Type checks
|
---|
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)
|
---|
118 |
|
---|
119 | set(headers "")
|
---|
120 | if (HAVE_SYS_TYPES_H)
|
---|
121 | set(headers ${headers} "sys/types.h")
|
---|
122 | endif()
|
---|
123 |
|
---|
124 | if (HAVE_INTTYPES_H)
|
---|
125 | set(headers ${headers} "inttypes.h")
|
---|
126 | endif()
|
---|
127 |
|
---|
128 | if (HAVE_STDINT_H)
|
---|
129 | set(headers ${headers} "stdint.h")
|
---|
130 | endif()
|
---|
131 |
|
---|
132 | check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
|
---|
133 | check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
|
---|
134 |
|
---|
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})
|
---|
146 | endfunction()
|
---|
147 |
|
---|
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)
|
---|
155 |
|
---|
156 | # Define LLVM_MULTITHREADED if gcc atomic builtins exists.
|
---|
157 | include(CheckAtomic)
|
---|
158 |
|
---|
159 | include(CheckCXXCompilerFlag)
|
---|
160 | # On windows all code is position-independent and mingw warns if -fPIC
|
---|
161 | # is in the command-line.
|
---|
162 | if( NOT WIN32 )
|
---|
163 | check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
|
---|
164 | endif()
|
---|
165 |
|
---|
166 | include(GetTargetTriple)
|
---|
167 | get_target_triple(LLVM_HOSTTRIPLE)
|
---|
168 |
|
---|
169 | # FIXME: We don't distinguish the target and the host. :(
|
---|
170 | set(TARGET_TRIPLE "${LLVM_HOSTTRIPLE}")
|
---|
171 |
|
---|
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})
|
---|
176 | endif ()
|
---|
177 |
|
---|
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)
|
---|
202 | else ()
|
---|
203 | message(STATUS
|
---|
204 | "Unknown architecture ${LLVM_NATIVE_ARCH}; lli will not JIT code")
|
---|
205 | set(LLVM_NATIVE_ARCH)
|
---|
206 | endif ()
|
---|
207 |
|
---|
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)
|
---|
211 | message(STATUS
|
---|
212 | "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
|
---|
213 | set(LLVM_NATIVE_ARCH)
|
---|
214 | else ()
|
---|
215 | message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
|
---|
216 | endif ()
|
---|
217 | endif()
|
---|
218 |
|
---|
219 | if( MINGW )
|
---|
220 | set(HAVE_LIBIMAGEHLP 1)
|
---|
221 | set(HAVE_LIBPSAPI 1)
|
---|
222 | # TODO: Check existence of libraries.
|
---|
223 | # include(CheckLibraryExists)
|
---|
224 | # CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
|
---|
225 | endif( MINGW )
|
---|
226 |
|
---|
227 | if( MSVC )
|
---|
228 | set(error_t int)
|
---|
229 | set(mode_t "unsigned short")
|
---|
230 | set(LTDL_SHLIBPATH_VAR "PATH")
|
---|
231 | set(LTDL_SYSSEARCHPATH "")
|
---|
232 | set(LTDL_DLOPEN_DEPLIBS 1)
|
---|
233 | set(SHLIBEXT ".lib")
|
---|
234 | set(LTDL_OBJDIR "_libs")
|
---|
235 | set(HAVE_STRTOLL 1)
|
---|
236 | set(strtoll "_strtoi64")
|
---|
237 | set(strtoull "_strtoui64")
|
---|
238 | set(stricmp "_stricmp")
|
---|
239 | set(strdup "_strdup")
|
---|
240 | else( MSVC )
|
---|
241 | set(LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH")
|
---|
242 | set(LTDL_SYSSEARCHPATH "") # TODO
|
---|
243 | set(LTDL_DLOPEN_DEPLIBS 0) # TODO
|
---|
244 | endif( MSVC )
|
---|
245 |
|
---|
246 | # FIXME: Signal handler return type, currently hardcoded to 'void'
|
---|
247 | set(RETSIGTYPE void)
|
---|
248 |
|
---|
249 | if( LLVM_ENABLE_THREADS )
|
---|
250 | if( HAVE_PTHREAD_H OR WIN32 )
|
---|
251 | set(ENABLE_THREADS 1)
|
---|
252 | endif()
|
---|
253 | endif()
|
---|
254 |
|
---|
255 | if( ENABLE_THREADS )
|
---|
256 | message(STATUS "Threads enabled.")
|
---|
257 | else( ENABLE_THREADS )
|
---|
258 | message(STATUS "Threads disabled.")
|
---|
259 | endif()
|
---|
260 |
|
---|
261 | configure_file(
|
---|
262 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
|
---|
263 | ${LLVM_BINARY_DIR}/include/llvm/Config/config.h
|
---|
264 | )
|
---|
265 |
|
---|
266 | configure_file(
|
---|
267 | ${LLVM_MAIN_INCLUDE_DIR}/llvm/System/DataTypes.h.cmake
|
---|
268 | ${LLVM_BINARY_DIR}/include/llvm/System/DataTypes.h
|
---|
269 | )
|
---|
270 |
|
---|