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