Home Explore Blog CI



neovim

1st chunk of `cmake.config/CMakeLists.txt`
9b617ae3359b0444600b239438bbb234c07eaf52fea49d6e0000000100000a36
include(CheckTypeSize)
include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckCSourceRuns)
include(CheckCSourceCompiles)
include(TestBigEndian)

check_c_source_compiles("
#include <execinfo.h>
int main(void)
{
  void *trace[1];
  backtrace(trace, 1);
  return 0;
}
" HAVE_EXECINFO_BACKTRACE)

check_c_source_compiles("
int main(void)
{
  int a = 42;
  __builtin_add_overflow(a, a, &a);
  __builtin_sub_overflow(a, a, &a);
  return 0;
}
" HAVE_BUILTIN_ADD_OVERFLOW)

check_type_size("int" SIZEOF_INT LANGUAGE C)
check_type_size("long" SIZEOF_LONG LANGUAGE C)
check_type_size("intmax_t" SIZEOF_INTMAX_T LANGUAGE C)
check_type_size("size_t" SIZEOF_SIZE_T LANGUAGE C)
check_type_size("void *" SIZEOF_VOID_PTR LANGUAGE C)

check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)

# Headers
check_include_files(langinfo.h HAVE_LANGINFO_H)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H)
check_include_files(termios.h HAVE_TERMIOS_H)
check_include_files(sys/uio.h HAVE_SYS_UIO_H)
check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  check_include_files(sys/xattr.h HAVE_XATTR)
endif()

# Functions
check_function_exists(fseeko HAVE_FSEEKO)
check_function_exists(readv HAVE_READV)
check_function_exists(readlink HAVE_READLINK)
check_function_exists(strnlen HAVE_STRNLEN)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(strncasecmp HAVE_STRNCASECMP)
check_function_exists(strptime HAVE_STRPTIME)

check_c_source_compiles("
#include <sys/types.h>
#include <dirent.h>
#include <sys/file.h>
int main(void)
{
  DIR *dir = opendir(\"dirname\");
  dirfd(dir);
  flock(10, LOCK_SH);
  return 0;
}
" HAVE_DIRFD_AND_FLOCK)


check_c_source_compiles("
#include <pwd.h>
int main(void)
{
  getpwent();
  getpwuid(0);
  getpwnam(\"root\");
  return 0;
}
" HAVE_PWD_FUNCS)

check_c_source_compiles("
#include <intrin.h>

int main(void)
{
  unsigned long index;
  unsigned char mask = 0x8000;
  _BitScanForward64(&index, mask);
  return 0;
}
" HAVE_BITSCANFORWARD64)

if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  check_c_source_compiles("
#include <termios.h>
int
main(void)
{
  return forkpty(0, NULL, NULL, NULL);
}
" HAVE_FORKPTY)
else()
  set(HAVE_FORKPTY 1)
endif()

# Symbols
check_symbol_exists(FD_CLOEXEC "fcntl.h" HAVE_FD_CLOEXEC)
if(HAVE_LANGINFO_H)
  check_symbol_exists(CODESET "langinfo.h" HAVE_NL_LANGINFO_CODESET)
endif()

check_include_files("endian.h" HAVE_ENDIAN_H)

set(ENDIAN_INCLUDE_FILE "endian.h")
if(NOT HAVE_ENDIAN_H)
  check_include_files("sys/endian.h"

Title: CMake Configuration: Feature Detection and System Checks
Summary
This section uses CMake modules (CheckTypeSize, CheckSymbolExists, etc.) to detect various features, header files, functions, and symbols available on the target system. It checks for things like the existence of `backtrace`, `fseeko`, `langinfo.h`, `FD_CLOEXEC`, and determines the sizes of data types. It also includes platform-specific checks like for `forkpty` on SunOS and `sys/xattr.h` on Linux. The results of these checks are stored in CMake variables (e.g., `HAVE_EXECINFO_BACKTRACE`, `HAVE_FSEEKO`).