robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
10c11c4644
master
1include ( CheckTypeSize ) 2include ( CheckSymbolExists ) 3include ( CheckFunctionExists ) 4include ( CheckIncludeFiles ) 5include ( CheckCSourceRuns ) 6include ( CheckCSourceCompiles ) 7include ( TestBigEndian ) 8 9check_c_source_compiles ( " 10#include <execinfo.h> 11int main(void) 12{ 13void *trace[1]; 14backtrace(trace, 1); 15return 0; 16} 17" HAVE_EXECINFO_BACKTRACE ) 18 19check_c_source_compiles ( " 20int main(void) 21{ 22int a = 42; 23__builtin_add_overflow(a, a, &a); 24__builtin_sub_overflow(a, a, &a); 25return 0; 26} 27" HAVE_BUILTIN_ADD_OVERFLOW ) 28 29check_type_size ( "int" SIZEOF_INT LANGUAGE C ) 30check_type_size ( "long" SIZEOF_LONG LANGUAGE C ) 31check_type_size ( "intmax_t" SIZEOF_INTMAX_T LANGUAGE C ) 32check_type_size ( "size_t" SIZEOF_SIZE_T LANGUAGE C ) 33check_type_size ( "void *" SIZEOF_VOID_PTR LANGUAGE C ) 34 35check_symbol_exists ( _NSGetEnviron crt_externs.h HAVE__NSGETENVIRON ) 36 37# Headers 38check_include_files ( langinfo.h HAVE_LANGINFO_H ) 39check_include_files ( strings.h HAVE_STRINGS_H ) 40check_include_files ( sys/utsname.h HAVE_SYS_UTSNAME_H ) 41check_include_files ( termios.h HAVE_TERMIOS_H ) 42check_include_files ( sys/uio.h HAVE_SYS_UIO_H ) 43check_include_files ( sys/sdt.h HAVE_SYS_SDT_H ) 44if ( CMAKE_SYSTEM_NAMESTREQUAL "Linux" ) 45check_include_files ( sys/xattr.h HAVE_XATTR ) 46endif () 47 48# Functions 49check_function_exists ( fseeko HAVE_FSEEKO ) 50check_function_exists ( readv HAVE_READV ) 51check_function_exists ( readlink HAVE_READLINK ) 52check_function_exists ( strnlen HAVE_STRNLEN ) 53check_function_exists ( strcasecmp HAVE_STRCASECMP ) 54check_function_exists ( strncasecmp HAVE_STRNCASECMP ) 55check_function_exists ( strptime HAVE_STRPTIME ) 56 57check_c_source_compiles ( " 58#include <sys/types.h> 59#include <dirent.h> 60#include <sys/file.h> 61int main(void) 62{ 63DIR *dir = opendir(\"dirname\"); 64dirfd(dir); 65flock(10, LOCK_SH); 66return 0; 67} 68" HAVE_DIRFD_AND_FLOCK ) 69 70 71check_c_source_compiles ( " 72#include <pwd.h> 73int main(void) 74{ 75getpwent(); 76getpwuid(0); 77getpwnam(\"root\"); 78return 0; 79} 80" HAVE_PWD_FUNCS ) 81 82check_c_source_compiles ( " 83#include <intrin.h> 84 85int main(void) 86{ 87unsigned long index; 88unsigned char mask = 0x8000; 89_BitScanForward64(&index, mask); 90return 0; 91} 92" HAVE_BITSCANFORWARD64 ) 93 94if ( CMAKE_SYSTEM_NAMESTREQUAL "SunOS" OR CMAKE_SYSTEM_NAMESTREQUAL "Haiku" ) 95check_c_source_compiles ( " 96#include <termios.h> 97int 98main(void) 99{ 100return forkpty(0, NULL, NULL, NULL); 101} 102" HAVE_FORKPTY ) 103else () 104set ( HAVE_FORKPTY 1 ) 105endif () 106 107# Symbols 108check_symbol_exists ( FD_CLOEXEC "fcntl.h" HAVE_FD_CLOEXEC ) 109if ( HAVE_LANGINFO_H) 110check_symbol_exists ( CODESET "langinfo.h" HAVE_NL_LANGINFO_CODESET ) 111endif () 112 113check_include_files ( "endian.h" HAVE_ENDIAN_H ) 114 115set ( ENDIAN_INCLUDE_FILE "endian.h" ) 116if ( NOT HAVE_ENDIAN_H) 117check_include_files ( "sys/endian.h" HAVE_SYS_ENDIAN_H ) 118if ( HAVE_SYS_ENDIAN_H) 119set ( ENDIAN_INCLUDE_FILE "sys/endian.h" ) 120endif () 121endif () 122 123set ( SI "#include <stdint.h>\n" ) 124set ( MS "int main(int argc,char**argv)\n{\n uint64_t i=0x0102030405060708ULL;" ) 125set ( ME "}" ) 126check_c_source_compiles ( " 127#define _BSD_SOURCE 1 128#define _DEFAULT_SOURCE 1 129${ SI } 130#include < ${ ENDIAN_INCLUDE_FILE } > 131#ifndef be64toh 132# error No be64toh macros 133#endif 134${ MS } 135uint64_t j = be64toh(i); 136return (j == 0); // j must not be zero 137${ ME } " 138HAVE_BE64TOH_MACROS ) 139if ( NOT " ${ HAVE_BE64TOH_MACROS } " ) 140check_function_exists ( be64toh HAVE_BE64TOH_FUNC ) 141endif () 142if ( " ${ HAVE_BE64TOH_MACROS } " OR " ${ HAVE_BE64TOH_FUNC } " ) 143set ( HAVE_BE64TOH 1 ) 144endif () 145 146test_big_endian ( ORDER_BIG_ENDIAN ) 147 148configure_file ( 149" ${ PROJECT_SOURCE_DIR } /cmake.config/config.h.in" 150" ${ PROJECT_BINARY_DIR } /cmake.config/auto/config.h" 151) 152 153set ( VERSION_STRING " ${ CMAKE_C_COMPILER } ${ CMAKE_C_FLAGS } " ) 154 155foreach ( BUILD_TYPE Debug Release RelWithDebInfo MinSizeRel) 156string ( TOUPPER ${ BUILD_TYPE } BUILD_TYPE_UPPER ) 157set ( GEN_CONFIG " $ <CONFIG: ${ BUILD_TYPE } >" ) 158 159set ( GEN_RHS " ${ CMAKE_C_FLAGS_ ${ BUILD_TYPE_UPPER }} " ) 160string ( APPEND VERSION_STRING " $ < ${ GEN_CONFIG } : ${ GEN_RHS } >" ) 161 162set ( GEN_RHS " $ < $ <BOOL: $ <TARGET_PROPERTY:nvim_bin,INTERPROCEDURAL_OPTIMIZATION_ ${ BUILD_TYPE_UPPER } >>: ${ CMAKE_C_COMPILE_OPTIONS_IPO } >" ) 163string ( APPEND VERSION_STRING " $ < ${ GEN_CONFIG } : ${ GEN_RHS } >" ) 164endforeach () 165 166string ( APPEND VERSION_STRING " " ) 167 168function ( append_target_expression ) 169cmake_parse_arguments ( ARG 170"" 171"PREFIX;PROPERTY" 172"" 173${ ARGN }) 174 175set ( TARGET_EXPRESSION " $ <TARGET_PROPERTY:nvim_bin, ${ ARG_PROPERTY } >" ) 176set ( TARGET_EXPRESSION " $ <REMOVE_DUPLICATES: ${ TARGET_EXPRESSION } >" ) 177set ( TARGET_EXPRESSION " ${ ARG_PREFIX }$ <JOIN: ${ TARGET_EXPRESSION } , ${ ARG_PREFIX } >" ) 178 179set ( VERSION_STRING " ${ VERSION_STRING } ${ TARGET_EXPRESSION } " PARENT_SCOPE ) 180endfunction () 181append_target_expression ( PROPERTY COMPILE_OPTIONS ) 182append_target_expression ( PROPERTY LINK_OPTIONS ) 183append_target_expression ( PREFIX "-D" PROPERTY COMPILE_DEFINITIONS ) 184append_target_expression ( PREFIX "-I" PROPERTY INCLUDE_DIRECTORIES ) 185string ( REPLACE ";" " " VERSION_STRING " ${ VERSION_STRING } " ) 186string ( REPLACE " " " " VERSION_STRING " ${ VERSION_STRING } " ) 187 188configure_file ( versiondef.h.in auto/versiondef.h.gen ) 189 190file ( GENERATE 191OUTPUT " ${ PROJECT_BINARY_DIR } /cmake.config/auto/versiondef- $ <CONFIG>.h" 192INPUT " ${ PROJECT_BINARY_DIR } /cmake.config/auto/versiondef.h.gen" ) 193 194configure_file ( 195" ${ PROJECT_SOURCE_DIR } /cmake.config/pathdef.h.in" 196" ${ PROJECT_BINARY_DIR } /cmake.config/auto/pathdef.h" 197ESCAPE_QUOTES )