[ARM] Better OR's for MVE compares
[llvm-core.git] / cmake / config-ix.cmake
blob0218d42eb8910be28a4be6d655978dbe5d98c51d
1 if( WIN32 AND NOT CYGWIN )
2   # We consider Cygwin as another Unix
3   set(PURE_WINDOWS 1)
4 endif()
6 include(CheckIncludeFile)
7 include(CheckLibraryExists)
8 include(CheckSymbolExists)
9 include(CheckFunctionExists)
10 include(CheckStructHasMember)
11 include(CheckCCompilerFlag)
13 include(CheckCompilerVersion)
14 include(HandleLLVMStdlib)
16 if( UNIX AND NOT (BEOS OR HAIKU) )
17   # Used by check_symbol_exists:
18   list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
19 endif()
20 # x86_64 FreeBSD 9.2 requires libcxxrt to be specified explicitly.
21 if( CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE" AND
22     CMAKE_SIZEOF_VOID_P EQUAL 8 )
23   list(APPEND CMAKE_REQUIRED_LIBRARIES "cxxrt")
24 endif()
26 # Do checks with _XOPEN_SOURCE and large-file API on AIX, because we will build
27 # with those too.
28 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
29           list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=700")
30           list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_LARGE_FILE_API")
31 endif()
33 # include checks
34 check_include_file(dlfcn.h HAVE_DLFCN_H)
35 check_include_file(errno.h HAVE_ERRNO_H)
36 check_include_file(fcntl.h HAVE_FCNTL_H)
37 check_include_file(link.h HAVE_LINK_H)
38 check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
39 if( NOT PURE_WINDOWS )
40   check_include_file(pthread.h HAVE_PTHREAD_H)
41 endif()
42 check_include_file(signal.h HAVE_SIGNAL_H)
43 check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
44 check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
45 check_include_file(sys/param.h HAVE_SYS_PARAM_H)
46 check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
47 check_include_file(sys/stat.h HAVE_SYS_STAT_H)
48 check_include_file(sys/time.h HAVE_SYS_TIME_H)
49 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
50 check_include_file(termios.h HAVE_TERMIOS_H)
51 check_include_file(unistd.h HAVE_UNISTD_H)
52 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
53 check_include_file(zlib.h HAVE_ZLIB_H)
54 check_include_file(fenv.h HAVE_FENV_H)
55 check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
56 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
58 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
59 check_include_file(histedit.h HAVE_HISTEDIT_H)
60 check_include_file(CrashReporterClient.h HAVE_CRASHREPORTERCLIENT_H)
61 if(APPLE)
62   include(CheckCSourceCompiles)
63   CHECK_C_SOURCE_COMPILES("
64      static const char *__crashreporter_info__ = 0;
65      asm(\".desc ___crashreporter_info__, 0x10\");
66      int main() { return 0; }"
67     HAVE_CRASHREPORTER_INFO)
68 endif()
70 if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
71   check_include_file(linux/magic.h HAVE_LINUX_MAGIC_H)
72   if(NOT HAVE_LINUX_MAGIC_H)
73     # older kernels use split files
74     check_include_file(linux/nfs_fs.h HAVE_LINUX_NFS_FS_H)
75     check_include_file(linux/smb.h HAVE_LINUX_SMB_H)
76   endif()
77 endif()
79 # library checks
80 if( NOT PURE_WINDOWS )
81   check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
82   if (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(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
86   else()
87     # this could be Android
88     check_library_exists(c pthread_create "" PTHREAD_IN_LIBC)
89     if (PTHREAD_IN_LIBC)
90       check_library_exists(c pthread_getspecific "" HAVE_PTHREAD_GETSPECIFIC)
91       check_library_exists(c pthread_rwlock_init "" HAVE_PTHREAD_RWLOCK_INIT)
92       check_library_exists(c pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
93     endif()
94   endif()
95   check_library_exists(dl dlopen "" HAVE_LIBDL)
96   check_library_exists(rt clock_gettime "" HAVE_LIBRT)
97 endif()
99 # Check for libpfm.
100 include(FindLibpfm)
102 if(HAVE_LIBPTHREAD)
103   # We want to find pthreads library and at the moment we do want to
104   # have it reported as '-l<lib>' instead of '-pthread'.
105   # TODO: switch to -pthread once the rest of the build system can deal with it.
106   set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
107   set(THREADS_HAVE_PTHREAD_ARG Off)
108   find_package(Threads REQUIRED)
109   set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
110 endif()
112 # Don't look for these libraries if we're using MSan, since uninstrumented third
113 # party code may call MSan interceptors like strlen, leading to false positives.
114 if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
115   set(HAVE_LIBZ 0)
116   if(LLVM_ENABLE_ZLIB)
117     foreach(library z zlib_static zlib)
118       string(TOUPPER ${library} library_suffix)
119       check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix})
120       if(HAVE_LIBZ_${library_suffix})
121         set(HAVE_LIBZ 1)
122         set(ZLIB_LIBRARIES "${library}")
123         break()
124       endif()
125     endforeach()
126   endif()
128   # Don't look for these libraries on Windows.
129   if (NOT PURE_WINDOWS)
130     # Skip libedit if using ASan as it contains memory leaks.
131     if (LLVM_ENABLE_LIBEDIT AND HAVE_HISTEDIT_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*")
132       check_library_exists(edit el_init "" HAVE_LIBEDIT)
133     else()
134       set(HAVE_LIBEDIT 0)
135     endif()
136     if(LLVM_ENABLE_TERMINFO)
137       set(HAVE_TERMINFO 0)
138       foreach(library terminfo tinfo curses ncurses ncursesw)
139         string(TOUPPER ${library} library_suffix)
140         check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
141         if(HAVE_TERMINFO_${library_suffix})
142           set(HAVE_TERMINFO 1)
143           set(TERMINFO_LIBS "${library}")
144           break()
145         endif()
146       endforeach()
147     else()
148       set(HAVE_TERMINFO 0)
149     endif()
151     find_library(ICONV_LIBRARY_PATH NAMES iconv libiconv libiconv-2 c)
152     set(LLVM_LIBXML2_ENABLED 0)
153     set(LIBXML2_FOUND 0)
154     if((LLVM_ENABLE_LIBXML2) AND ((CMAKE_SYSTEM_NAME MATCHES "Linux") AND (ICONV_LIBRARY_PATH) OR APPLE))
155       find_package(LibXml2)
156       if (LIBXML2_FOUND)
157         set(LLVM_LIBXML2_ENABLED 1)
158         if ((CMAKE_OSX_SYSROOT) AND (EXISTS ${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR}))
159           include_directories(${CMAKE_OSX_SYSROOT}/${LIBXML2_INCLUDE_DIR})
160         else()
161           include_directories(${LIBXML2_INCLUDE_DIR})
162         endif()
163         set(LIBXML2_LIBS "xml2")
164       endif()
165     endif()
166   endif()
167 endif()
169 if (LLVM_ENABLE_LIBXML2 STREQUAL "FORCE_ON" AND NOT LLVM_LIBXML2_ENABLED)
170   message(FATAL_ERROR "Failed to congifure libxml2")
171 endif()
173 check_library_exists(xar xar_open "" HAVE_LIBXAR)
174 if(HAVE_LIBXAR)
175   set(XAR_LIB xar)
176 endif()
178 # function checks
179 check_symbol_exists(arc4random "stdlib.h" HAVE_DECL_ARC4RANDOM)
180 find_package(Backtrace)
181 set(HAVE_BACKTRACE ${Backtrace_FOUND})
182 set(BACKTRACE_HEADER ${Backtrace_HEADER})
184 # Prevent check_symbol_exists from using API that is not supported for a given
185 # deployment target.
186 check_c_compiler_flag("-Werror=unguarded-availability-new" "C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW")
187 if(C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW)
188   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability-new")
189 endif()
191 check_symbol_exists(_Unwind_Backtrace "unwind.h" HAVE__UNWIND_BACKTRACE)
192 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
193 check_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
194 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
195 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
196 check_symbol_exists(isatty unistd.h HAVE_ISATTY)
197 check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
198 check_symbol_exists(futimes sys/time.h HAVE_FUTIMES)
199 check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE)
200 # AddressSanitizer conflicts with lib/Support/Unix/Signals.inc
201 # Avoid sigaltstack on Apple platforms, where backtrace() cannot handle it
202 # (rdar://7089625) and _Unwind_Backtrace is unusable because it cannot unwind
203 # past the signal handler after an assertion failure (rdar://29866587).
204 if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE )
205   check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK)
206 endif()
207 set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE")
208 check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64)
209 set(CMAKE_REQUIRED_DEFINITIONS "")
210 check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL)
211 check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
212 check_symbol_exists(malloc_zone_statistics malloc/malloc.h
213                     HAVE_MALLOC_ZONE_STATISTICS)
214 check_symbol_exists(getrlimit "sys/types.h;sys/time.h;sys/resource.h" HAVE_GETRLIMIT)
215 check_symbol_exists(posix_spawn spawn.h HAVE_POSIX_SPAWN)
216 check_symbol_exists(pread unistd.h HAVE_PREAD)
217 check_symbol_exists(sbrk unistd.h HAVE_SBRK)
218 check_symbol_exists(strerror string.h HAVE_STRERROR)
219 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
220 check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
221 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
222 if( PURE_WINDOWS )
223   check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
225   check_function_exists(_alloca HAVE__ALLOCA)
226   check_function_exists(__alloca HAVE___ALLOCA)
227   check_function_exists(__chkstk HAVE___CHKSTK)
228   check_function_exists(__chkstk_ms HAVE___CHKSTK_MS)
229   check_function_exists(___chkstk HAVE____CHKSTK)
230   check_function_exists(___chkstk_ms HAVE____CHKSTK_MS)
232   check_function_exists(__ashldi3 HAVE___ASHLDI3)
233   check_function_exists(__ashrdi3 HAVE___ASHRDI3)
234   check_function_exists(__divdi3 HAVE___DIVDI3)
235   check_function_exists(__fixdfdi HAVE___FIXDFDI)
236   check_function_exists(__fixsfdi HAVE___FIXSFDI)
237   check_function_exists(__floatdidf HAVE___FLOATDIDF)
238   check_function_exists(__lshrdi3 HAVE___LSHRDI3)
239   check_function_exists(__moddi3 HAVE___MODDI3)
240   check_function_exists(__udivdi3 HAVE___UDIVDI3)
241   check_function_exists(__umoddi3 HAVE___UMODDI3)
243   check_function_exists(__main HAVE___MAIN)
244   check_function_exists(__cmpdi2 HAVE___CMPDI2)
245 endif()
246 if( HAVE_DLFCN_H )
247   if( HAVE_LIBDL )
248     list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
249   endif()
250   check_symbol_exists(dlopen dlfcn.h HAVE_DLOPEN)
251   check_symbol_exists(dladdr dlfcn.h HAVE_DLADDR)
252   if( HAVE_LIBDL )
253     list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
254   endif()
255 endif()
257 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec
258     "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
259 CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec
260     "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
262 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
263 if( LLVM_USING_GLIBC )
264   add_definitions( -D_GNU_SOURCE )
265   list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
266 endif()
267 # This check requires _GNU_SOURCE
268 check_symbol_exists(sched_getaffinity sched.h HAVE_SCHED_GETAFFINITY)
269 check_symbol_exists(CPU_COUNT sched.h HAVE_CPU_COUNT)
270 if (NOT PURE_WINDOWS)
271   if (LLVM_PTHREAD_LIB)
272     list(APPEND CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
273   endif()
274   check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP)
275   check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
276   if (LLVM_PTHREAD_LIB)
277     list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${LLVM_PTHREAD_LIB})
278   endif()
279 endif()
281 # available programs checks
282 function(llvm_find_program name)
283   string(TOUPPER ${name} NAME)
284   string(REGEX REPLACE "\\." "_" NAME ${NAME})
286   find_program(LLVM_PATH_${NAME} NAMES ${ARGV})
287   mark_as_advanced(LLVM_PATH_${NAME})
288   if(LLVM_PATH_${NAME})
289     set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
290     mark_as_advanced(HAVE_${NAME})
291   else(LLVM_PATH_${NAME})
292     set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
293   endif(LLVM_PATH_${NAME})
294 endfunction()
296 if (LLVM_ENABLE_DOXYGEN)
297   llvm_find_program(dot)
298 endif ()
300 if( LLVM_ENABLE_FFI )
301   find_path(FFI_INCLUDE_PATH ffi.h PATHS ${FFI_INCLUDE_DIR})
302   if( EXISTS "${FFI_INCLUDE_PATH}/ffi.h" )
303     set(FFI_HEADER ffi.h CACHE INTERNAL "")
304     set(HAVE_FFI_H 1 CACHE INTERNAL "")
305   else()
306     find_path(FFI_INCLUDE_PATH ffi/ffi.h PATHS ${FFI_INCLUDE_DIR})
307     if( EXISTS "${FFI_INCLUDE_PATH}/ffi/ffi.h" )
308       set(FFI_HEADER ffi/ffi.h CACHE INTERNAL "")
309       set(HAVE_FFI_FFI_H 1 CACHE INTERNAL "")
310     endif()
311   endif()
313   if( NOT FFI_HEADER )
314     message(FATAL_ERROR "libffi includes are not found.")
315   endif()
317   find_library(FFI_LIBRARY_PATH ffi PATHS ${FFI_LIBRARY_DIR})
318   if( NOT FFI_LIBRARY_PATH )
319     message(FATAL_ERROR "libffi is not found.")
320   endif()
322   list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
323   list(APPEND CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
324   check_symbol_exists(ffi_call ${FFI_HEADER} HAVE_FFI_CALL)
325   list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${FFI_INCLUDE_PATH})
326   list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${FFI_LIBRARY_PATH})
327 else()
328   unset(HAVE_FFI_FFI_H CACHE)
329   unset(HAVE_FFI_H CACHE)
330   unset(HAVE_FFI_CALL CACHE)
331 endif( LLVM_ENABLE_FFI )
333 # Whether we can use std::is_trivially_copyable to verify llvm::is_trivially_copyable.
334 CHECK_CXX_SOURCE_COMPILES("
335 #include <type_traits>
336 struct T { int val; };
337 static_assert(std::is_trivially_copyable<T>::value, \"ok\");
338 int main() { return 0;}
339 " HAVE_STD_IS_TRIVIALLY_COPYABLE)
342 # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported.
343 include(CheckAtomic)
345 if( LLVM_ENABLE_PIC )
346   set(ENABLE_PIC 1)
347 else()
348   set(ENABLE_PIC 0)
349   check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
350   if(SUPPORTS_NO_PIE_FLAG)
351     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
352   endif()
353 endif()
355 check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG)
356 check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments"
357                         SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
359 set(USE_NO_MAYBE_UNINITIALIZED 0)
360 set(USE_NO_UNINITIALIZED 0)
362 # Disable gcc's potentially uninitialized use analysis as it presents lots of
363 # false positives.
364 if (CMAKE_COMPILER_IS_GNUCXX)
365   check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
366   if (HAS_MAYBE_UNINITIALIZED)
367     set(USE_NO_MAYBE_UNINITIALIZED 1)
368   else()
369     # Only recent versions of gcc make the distinction between -Wuninitialized
370     # and -Wmaybe-uninitialized. If -Wmaybe-uninitialized isn't supported, just
371     # turn off all uninitialized use warnings.
372     check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
373     set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
374   endif()
375 endif()
377 # By default, we target the host, but this can be overridden at CMake
378 # invocation time.
379 include(GetHostTriple)
380 get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
382 set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING
383     "Host on which LLVM binaries will run")
385 # Determine the native architecture.
386 string(TOLOWER "${LLVM_TARGET_ARCH}" LLVM_NATIVE_ARCH)
387 if( LLVM_NATIVE_ARCH STREQUAL "host" )
388   string(REGEX MATCH "^[^-]*" LLVM_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
389 endif ()
391 if (LLVM_NATIVE_ARCH MATCHES "i[2-6]86")
392   set(LLVM_NATIVE_ARCH X86)
393 elseif (LLVM_NATIVE_ARCH STREQUAL "x86")
394   set(LLVM_NATIVE_ARCH X86)
395 elseif (LLVM_NATIVE_ARCH STREQUAL "amd64")
396   set(LLVM_NATIVE_ARCH X86)
397 elseif (LLVM_NATIVE_ARCH STREQUAL "x86_64")
398   set(LLVM_NATIVE_ARCH X86)
399 elseif (LLVM_NATIVE_ARCH MATCHES "sparc")
400   set(LLVM_NATIVE_ARCH Sparc)
401 elseif (LLVM_NATIVE_ARCH MATCHES "powerpc")
402   set(LLVM_NATIVE_ARCH PowerPC)
403 elseif (LLVM_NATIVE_ARCH MATCHES "ppc64le")
404   set(LLVM_NATIVE_ARCH PowerPC)
405 elseif (LLVM_NATIVE_ARCH MATCHES "aarch64")
406   set(LLVM_NATIVE_ARCH AArch64)
407 elseif (LLVM_NATIVE_ARCH MATCHES "arm64")
408   set(LLVM_NATIVE_ARCH AArch64)
409 elseif (LLVM_NATIVE_ARCH MATCHES "arm")
410   set(LLVM_NATIVE_ARCH ARM)
411 elseif (LLVM_NATIVE_ARCH MATCHES "avr")
412   set(LLVM_NATIVE_ARCH AVR)
413 elseif (LLVM_NATIVE_ARCH MATCHES "mips")
414   set(LLVM_NATIVE_ARCH Mips)
415 elseif (LLVM_NATIVE_ARCH MATCHES "xcore")
416   set(LLVM_NATIVE_ARCH XCore)
417 elseif (LLVM_NATIVE_ARCH MATCHES "msp430")
418   set(LLVM_NATIVE_ARCH MSP430)
419 elseif (LLVM_NATIVE_ARCH MATCHES "hexagon")
420   set(LLVM_NATIVE_ARCH Hexagon)
421 elseif (LLVM_NATIVE_ARCH MATCHES "s390x")
422   set(LLVM_NATIVE_ARCH SystemZ)
423 elseif (LLVM_NATIVE_ARCH MATCHES "wasm32")
424   set(LLVM_NATIVE_ARCH WebAssembly)
425 elseif (LLVM_NATIVE_ARCH MATCHES "wasm64")
426   set(LLVM_NATIVE_ARCH WebAssembly)
427 elseif (LLVM_NATIVE_ARCH MATCHES "riscv32")
428   set(LLVM_NATIVE_ARCH RISCV)
429 elseif (LLVM_NATIVE_ARCH MATCHES "riscv64")
430   set(LLVM_NATIVE_ARCH RISCV)
431 else ()
432   message(FATAL_ERROR "Unknown architecture ${LLVM_NATIVE_ARCH}")
433 endif ()
435 # If build targets includes "host", then replace with native architecture.
436 list(FIND LLVM_TARGETS_TO_BUILD "host" idx)
437 if( NOT idx LESS 0 )
438   list(REMOVE_AT LLVM_TARGETS_TO_BUILD ${idx})
439   list(APPEND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH})
440   list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
441 endif()
443 list(FIND LLVM_TARGETS_TO_BUILD ${LLVM_NATIVE_ARCH} NATIVE_ARCH_IDX)
444 if (NATIVE_ARCH_IDX EQUAL -1)
445   message(STATUS
446     "Native target ${LLVM_NATIVE_ARCH} is not selected; lli will not JIT code")
447 else ()
448   message(STATUS "Native target architecture is ${LLVM_NATIVE_ARCH}")
449   set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
450   set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
451   set(LLVM_NATIVE_TARGETMC LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC)
452   set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
454   # We don't have an ASM parser for all architectures yet.
455   if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/CMakeLists.txt)
456     set(LLVM_NATIVE_ASMPARSER LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser)
457   endif ()
459   # We don't have an disassembler for all architectures yet.
460   if (EXISTS ${PROJECT_SOURCE_DIR}/lib/Target/${LLVM_NATIVE_ARCH}/Disassembler/CMakeLists.txt)
461     set(LLVM_NATIVE_DISASSEMBLER LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler)
462   endif ()
463 endif ()
465 if( MSVC )
466   set(SHLIBEXT ".lib")
467   set(stricmp "_stricmp")
468   set(strdup "_strdup")
470   # See if the DIA SDK is available and usable.
471   set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
473   # Due to a bug in MSVC 2013's installation software, it is possible
474   # for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
475   # install directory.  If this happens, the installation is corrupt
476   # and there's nothing we can do.  It happens with enough frequency
477   # though that we should handle it.  We do so by simply checking that
478   # the DIA SDK folder exists.  Should this happen you will need to
479   # uninstall VS 2012 and then re-install VS 2013.
480   if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
481     set(HAVE_DIA_SDK 1)
482   else()
483     set(HAVE_DIA_SDK 0)
484   endif()
486   option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available."
487                              ${HAVE_DIA_SDK})
489   if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)
490     message(FATAL_ERROR "DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards.")
491   endif()
492 else()
493   set(LLVM_ENABLE_DIA_SDK 0)
494 endif( MSVC )
496 # FIXME: Signal handler return type, currently hardcoded to 'void'
497 set(RETSIGTYPE void)
499 if( LLVM_ENABLE_THREADS )
500   # Check if threading primitives aren't supported on this platform
501   if( NOT HAVE_PTHREAD_H AND NOT WIN32 )
502     set(LLVM_ENABLE_THREADS 0)
503   endif()
504 endif()
506 if( LLVM_ENABLE_THREADS )
507   message(STATUS "Threads enabled.")
508 else( LLVM_ENABLE_THREADS )
509   message(STATUS "Threads disabled.")
510 endif()
512 if (LLVM_ENABLE_ZLIB )
513   # Check if zlib is available in the system.
514   if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
515     set(LLVM_ENABLE_ZLIB 0)
516   endif()
517 endif()
519 if (LLVM_ENABLE_DOXYGEN)
520   message(STATUS "Doxygen enabled.")
521   find_package(Doxygen REQUIRED)
523   if (DOXYGEN_FOUND)
524     # If we find doxygen and we want to enable doxygen by default create a
525     # global aggregate doxygen target for generating llvm and any/all
526     # subprojects doxygen documentation.
527     if (LLVM_BUILD_DOCS)
528       add_custom_target(doxygen ALL)
529     endif()
531     option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
532     if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
533       set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")
534       set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
535     endif()
536   endif()
537 else()
538   message(STATUS "Doxygen disabled.")
539 endif()
541 set(LLVM_BINDINGS "")
542 find_program(GO_EXECUTABLE NAMES go DOC "go executable")
543 if(WIN32 OR NOT LLVM_ENABLE_BINDINGS)
544   message(STATUS "Go bindings disabled.")
545 else()
546   if(GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
547     message(STATUS "Go bindings disabled.")
548   else()
549     execute_process(COMMAND ${GO_EXECUTABLE} run ${PROJECT_SOURCE_DIR}/bindings/go/conftest.go
550                     RESULT_VARIABLE GO_CONFTEST)
551     if(GO_CONFTEST STREQUAL "0")
552       set(LLVM_BINDINGS "${LLVM_BINDINGS} go")
553       message(STATUS "Go bindings enabled.")
554     else()
555       message(STATUS "Go bindings disabled, need at least Go 1.2.")
556     endif()
557   endif()
558 endif()
560 find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")
561 set(LLVM_BINUTILS_INCDIR "" CACHE PATH
562         "PATH to binutils/include containing plugin-api.h for gold plugin.")
564 if(CMAKE_GENERATOR STREQUAL "Ninja")
565   execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
566     OUTPUT_VARIABLE NINJA_VERSION
567     OUTPUT_STRIP_TRAILING_WHITESPACE)
568   set(NINJA_VERSION ${NINJA_VERSION} CACHE STRING "Ninja version number" FORCE)
569   message(STATUS "Ninja version: ${NINJA_VERSION}")
570 endif()
572 if(CMAKE_GENERATOR STREQUAL "Ninja" AND
573     NOT "${NINJA_VERSION}" VERSION_LESS "1.9.0" AND
574     CMAKE_HOST_APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER "15.6.0")
575   set(LLVM_TOUCH_STATIC_LIBRARIES ON)
576 endif()
578 if(CMAKE_HOST_APPLE AND APPLE)
579   if(NOT CMAKE_XCRUN)
580     find_program(CMAKE_XCRUN NAMES xcrun)
581   endif()
582   if(CMAKE_XCRUN)
583     execute_process(COMMAND ${CMAKE_XCRUN} -find ld
584       OUTPUT_VARIABLE LD64_EXECUTABLE
585       OUTPUT_STRIP_TRAILING_WHITESPACE)
586   else()
587     find_program(LD64_EXECUTABLE NAMES ld DOC "The ld64 linker")
588   endif()
590   if(LD64_EXECUTABLE)
591     set(LD64_EXECUTABLE ${LD64_EXECUTABLE} CACHE PATH "ld64 executable")
592     message(STATUS "Found ld64 - ${LD64_EXECUTABLE}")
593   endif()
594 endif()
596 # Keep the version requirements in sync with bindings/ocaml/README.txt.
597 include(FindOCaml)
598 include(AddOCaml)
599 if(WIN32 OR NOT LLVM_ENABLE_BINDINGS)
600   message(STATUS "OCaml bindings disabled.")
601 else()
602   find_package(OCaml)
603   if( NOT OCAML_FOUND )
604     message(STATUS "OCaml bindings disabled.")
605   else()
606     if( OCAML_VERSION VERSION_LESS "4.00.0" )
607       message(STATUS "OCaml bindings disabled, need OCaml >=4.00.0.")
608     else()
609       find_ocamlfind_package(ctypes VERSION 0.4 OPTIONAL)
610       if( HAVE_OCAML_CTYPES )
611         message(STATUS "OCaml bindings enabled.")
612         find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
613         set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
615         set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
616             "Install directory for LLVM OCaml packages")
617       else()
618         message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
619       endif()
620     endif()
621   endif()
622 endif()
624 string(REPLACE " " ";" LLVM_BINDINGS_LIST "${LLVM_BINDINGS}")
626 function(find_python_module module)
627   string(REPLACE "." "_" module_name ${module})
628   string(TOUPPER ${module_name} module_upper)
629   set(FOUND_VAR PY_${module_upper}_FOUND)
630   if (DEFINED ${FOUND_VAR})
631     return()
632   endif()
634   execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}"
635     RESULT_VARIABLE status
636     ERROR_QUIET)
638   if(status)
639     set(${FOUND_VAR} OFF CACHE BOOL "Failed to find python module '${module}'")
640     message(STATUS "Could NOT find Python module ${module}")
641   else()
642   set(${FOUND_VAR} ON CACHE BOOL "Found python module '${module}'")
643     message(STATUS "Found Python module ${module}")
644   endif()
645 endfunction()
647 set (PYTHON_MODULES
648   pygments
649   # Some systems still don't have pygments.lexers.c_cpp which was introduced in
650   # version 2.0 in 2014...
651   pygments.lexers.c_cpp
652   yaml
653   )
654 foreach(module ${PYTHON_MODULES})
655   find_python_module(${module})
656 endforeach()
658 if(PY_PYGMENTS_FOUND AND PY_PYGMENTS_LEXERS_C_CPP_FOUND AND PY_YAML_FOUND)
659   set (LLVM_HAVE_OPT_VIEWER_MODULES 1)
660 else()
661   set (LLVM_HAVE_OPT_VIEWER_MODULES 0)
662 endif()