+check_symbol_exists(strerror string.h HAVE_STRERROR)
+check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
+check_symbol_exists(strerror_s string.h HAVE_STRERROR_S)
+check_symbol_exists(setenv stdlib.h HAVE_SETENV)
+if ( LLVM_ON_WIN32 )
+ check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
+endif()
+
+check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
+if( LLVM_USING_GLIBC )
+ add_llvm_definitions( -D_GNU_SOURCE )
+endif()
+
+# Type checks
+check_type_exists(std::bidirectional_iterator<int,int> "iterator;iostream" HAVE_BI_ITERATOR)
+check_type_exists(std::iterator<int,int,int> iterator HAVE_STD_ITERATOR)
+check_type_exists(std::forward_iterator<int,int> iterator HAVE_FWD_ITERATOR)
+
+set(headers "")
+if (HAVE_SYS_TYPES_H)
+ set(headers ${headers} "sys/types.h")
+endif()
+
+if (HAVE_INTTYPES_H)
+ set(headers ${headers} "inttypes.h")
+endif()
+
+if (HAVE_STDINT_H)
+ set(headers ${headers} "stdint.h")
+endif()
+
+check_type_exists(uint64_t "${headers}" HAVE_UINT64_T)
+check_type_exists(u_int64_t "${headers}" HAVE_U_INT64_T)
+
+# available programs checks
+function(llvm_find_program name)
+ string(TOUPPER ${name} NAME)
+ find_program(LLVM_PATH_${NAME} ${name})
+ mark_as_advanced(LLVM_PATH_${NAME})
+ if(LLVM_PATH_${NAME})
+ set(HAVE_${NAME} 1 CACHE INTERNAL "Is ${name} available ?")
+ mark_as_advanced(HAVE_${NAME})
+ else(LLVM_PATH_${NAME})
+ set(HAVE_${NAME} "" CACHE INTERNAL "Is ${name} available ?")
+ endif(LLVM_PATH_${NAME})
+endfunction()
+
+llvm_find_program(gv)
+llvm_find_program(circo)
+llvm_find_program(twopi)
+llvm_find_program(neato)
+llvm_find_program(fdp)
+llvm_find_program(dot)
+llvm_find_program(dotty)
+
+# Define LLVM_MULTITHREADED if gcc atomic builtins exists.
+include(CheckAtomic)
+
+include(CheckCXXCompilerFlag)
+# On windows all code is position-independent and mingw warns if -fPIC
+# is in the command-line.
+if( NOT WIN32 )
+ check_cxx_compiler_flag("-fPIC" SUPPORTS_FPIC_FLAG)
+endif()
+
+check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)