2014-01-31 06:39:15 -07:00
|
|
|
include(CheckTypeSize)
|
2014-04-03 01:27:36 -07:00
|
|
|
include(CheckSymbolExists)
|
2014-06-05 02:41:27 -07:00
|
|
|
include(CheckFunctionExists)
|
|
|
|
include(CheckIncludeFiles)
|
2015-08-15 06:16:29 -07:00
|
|
|
include(CheckCSourceRuns)
|
2015-08-15 07:41:28 -07:00
|
|
|
include(CheckCSourceCompiles)
|
2023-10-26 13:30:00 -07:00
|
|
|
include(TestBigEndian)
|
2014-01-31 11:10:18 -07:00
|
|
|
|
2023-01-10 10:49:57 -07:00
|
|
|
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)
|
|
|
|
|
2022-04-26 19:41:11 -07:00
|
|
|
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)
|
2014-01-31 06:39:15 -07:00
|
|
|
|
2014-04-03 01:27:36 -07:00
|
|
|
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
|
2014-02-28 03:33:31 -07:00
|
|
|
|
2014-06-05 02:41:27 -07:00
|
|
|
# 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)
|
2016-12-11 22:50:39 -07:00
|
|
|
check_include_files(termios.h HAVE_TERMIOS_H)
|
2016-06-04 12:48:29 -07:00
|
|
|
check_include_files(sys/uio.h HAVE_SYS_UIO_H)
|
2020-03-15 11:01:36 -07:00
|
|
|
check_include_files(sys/sdt.h HAVE_SYS_SDT_H)
|
2023-09-30 06:19:12 -07:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
check_include_files(sys/xattr.h HAVE_XATTR)
|
|
|
|
endif()
|
2014-06-05 02:41:27 -07:00
|
|
|
|
|
|
|
# Functions
|
|
|
|
check_function_exists(fseeko HAVE_FSEEKO)
|
2016-06-04 12:48:29 -07:00
|
|
|
check_function_exists(readv HAVE_READV)
|
2014-06-05 02:41:27 -07:00
|
|
|
check_function_exists(readlink HAVE_READLINK)
|
2021-12-05 23:49:15 -07:00
|
|
|
check_function_exists(strnlen HAVE_STRNLEN)
|
2014-06-05 02:41:27 -07:00
|
|
|
check_function_exists(strcasecmp HAVE_STRCASECMP)
|
|
|
|
check_function_exists(strncasecmp HAVE_STRNCASECMP)
|
2020-12-05 23:15:43 -07:00
|
|
|
check_function_exists(strptime HAVE_STRPTIME)
|
2014-06-05 02:41:27 -07:00
|
|
|
|
2023-01-02 05:37:13 -07:00
|
|
|
check_c_source_compiles("
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
2023-02-27 08:30:32 -07:00
|
|
|
#include <sys/file.h>
|
2023-01-02 05:37:13 -07:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
DIR *dir = opendir(\"dirname\");
|
|
|
|
dirfd(dir);
|
2023-02-27 08:30:32 -07:00
|
|
|
flock(10, LOCK_SH);
|
2023-01-02 05:37:13 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2023-02-27 08:30:32 -07:00
|
|
|
" HAVE_DIRFD_AND_FLOCK)
|
|
|
|
|
2023-01-02 05:37:13 -07:00
|
|
|
|
|
|
|
check_c_source_compiles("
|
2023-02-27 08:30:32 -07:00
|
|
|
#include <pwd.h>
|
2023-01-02 05:37:13 -07:00
|
|
|
int main(void)
|
|
|
|
{
|
2023-02-27 08:30:32 -07:00
|
|
|
getpwent();
|
|
|
|
getpwuid(0);
|
|
|
|
getpwnam(\"root\");
|
2023-01-02 05:37:13 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2023-02-27 08:30:32 -07:00
|
|
|
" HAVE_PWD_FUNCS)
|
|
|
|
|
2023-01-02 05:37:13 -07:00
|
|
|
|
2021-12-09 12:01:19 -07:00
|
|
|
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()
|
|
|
|
|
2014-06-05 02:41:27 -07:00
|
|
|
# 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()
|
|
|
|
|
2016-05-14 05:44:37 -07:00
|
|
|
check_include_files("endian.h" HAVE_ENDIAN_H)
|
|
|
|
|
|
|
|
set(ENDIAN_INCLUDE_FILE "endian.h")
|
2023-02-27 08:30:32 -07:00
|
|
|
if(NOT HAVE_ENDIAN_H)
|
|
|
|
check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H)
|
|
|
|
if (HAVE_SYS_ENDIAN_H)
|
|
|
|
set(ENDIAN_INCLUDE_FILE "sys/endian.h")
|
|
|
|
endif()
|
2016-05-14 05:44:37 -07:00
|
|
|
endif()
|
|
|
|
|
2015-08-15 06:16:29 -07:00
|
|
|
set(SI "#include <stdint.h>\n")
|
|
|
|
set(MS "int main(int argc,char**argv)\n{\n uint64_t i=0x0102030405060708ULL;")
|
|
|
|
set(ME "}")
|
2015-08-15 07:41:28 -07:00
|
|
|
check_c_source_compiles("
|
2015-08-15 06:16:29 -07:00
|
|
|
#define _BSD_SOURCE 1
|
|
|
|
#define _DEFAULT_SOURCE 1
|
|
|
|
${SI}
|
2016-05-14 05:44:37 -07:00
|
|
|
#include <${ENDIAN_INCLUDE_FILE}>
|
2015-08-15 07:41:28 -07:00
|
|
|
#ifndef be64toh
|
|
|
|
# error No be64toh macros
|
|
|
|
#endif
|
2015-08-15 06:16:29 -07:00
|
|
|
${MS}
|
|
|
|
uint64_t j = be64toh(i);
|
2015-08-15 07:41:28 -07:00
|
|
|
return (j == 0); // j must not be zero
|
2015-08-15 06:16:29 -07:00
|
|
|
${ME}"
|
2015-08-15 07:41:28 -07:00
|
|
|
HAVE_BE64TOH_MACROS)
|
|
|
|
if(NOT "${HAVE_BE64TOH_MACROS}")
|
|
|
|
check_function_exists(be64toh HAVE_BE64TOH_FUNC)
|
|
|
|
endif()
|
|
|
|
if("${HAVE_BE64TOH_MACROS}" OR "${HAVE_BE64TOH_FUNC}")
|
|
|
|
set(HAVE_BE64TOH 1)
|
|
|
|
endif()
|
2023-10-26 13:30:00 -07:00
|
|
|
|
|
|
|
test_big_endian(ORDER_BIG_ENDIAN)
|
2015-08-15 06:16:29 -07:00
|
|
|
|
2014-01-31 06:39:15 -07:00
|
|
|
configure_file (
|
2022-06-27 03:08:59 -07:00
|
|
|
"${PROJECT_SOURCE_DIR}/cmake.config/config.h.in"
|
|
|
|
"${PROJECT_BINARY_DIR}/cmake.config/auto/config.h"
|
2014-01-31 06:39:15 -07:00
|
|
|
)
|
2014-06-05 02:41:27 -07:00
|
|
|
|
2023-12-14 09:52:00 -07:00
|
|
|
set(VERSION_STRING "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ")
|
2023-10-23 13:32:32 -07:00
|
|
|
|
2023-12-14 09:52:00 -07:00
|
|
|
foreach(BUILD_TYPE Debug Release RelWithDebInfo MinSizeRel)
|
|
|
|
string(TOUPPER ${BUILD_TYPE} BUILD_TYPE_UPPER)
|
|
|
|
set(GEN_CONFIG "$<CONFIG:${BUILD_TYPE}>")
|
|
|
|
|
|
|
|
set(GEN_RHS "${CMAKE_C_FLAGS_${BUILD_TYPE_UPPER}} ")
|
|
|
|
string(APPEND VERSION_STRING "$<${GEN_CONFIG}:${GEN_RHS}>")
|
|
|
|
|
2024-01-19 05:21:25 -07:00
|
|
|
set(GEN_RHS "$<$<BOOL:$<TARGET_PROPERTY:nvim_bin,INTERPROCEDURAL_OPTIMIZATION_${BUILD_TYPE_UPPER}>>:${CMAKE_C_COMPILE_OPTIONS_IPO}>")
|
2023-12-14 09:52:00 -07:00
|
|
|
string(APPEND VERSION_STRING "$<${GEN_CONFIG}:${GEN_RHS}>")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
string(APPEND VERSION_STRING " ")
|
|
|
|
|
|
|
|
function(append_target_expression)
|
|
|
|
cmake_parse_arguments(ARG
|
|
|
|
""
|
|
|
|
"PREFIX;PROPERTY"
|
|
|
|
""
|
|
|
|
${ARGN})
|
|
|
|
|
2024-01-19 05:21:25 -07:00
|
|
|
set(TARGET_EXPRESSION "$<TARGET_PROPERTY:nvim_bin,${ARG_PROPERTY}>")
|
2023-12-14 09:52:00 -07:00
|
|
|
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.15)
|
|
|
|
set(TARGET_EXPRESSION "$<REMOVE_DUPLICATES:${TARGET_EXPRESSION}>")
|
|
|
|
endif()
|
|
|
|
set(TARGET_EXPRESSION "${ARG_PREFIX}$<JOIN:${TARGET_EXPRESSION}, ${ARG_PREFIX}>")
|
|
|
|
|
|
|
|
set(VERSION_STRING "${VERSION_STRING} ${TARGET_EXPRESSION} " PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
append_target_expression(PROPERTY COMPILE_OPTIONS)
|
2023-11-24 05:28:15 -07:00
|
|
|
append_target_expression(PROPERTY LINK_OPTIONS)
|
2023-12-14 09:52:00 -07:00
|
|
|
append_target_expression(PREFIX "-D" PROPERTY COMPILE_DEFINITIONS)
|
|
|
|
append_target_expression(PREFIX "-I" PROPERTY INCLUDE_DIRECTORIES)
|
2023-12-17 07:40:09 -07:00
|
|
|
string(REPLACE ";" " " VERSION_STRING "${VERSION_STRING}")
|
|
|
|
string(REPLACE " " " " VERSION_STRING "${VERSION_STRING}")
|
2023-12-14 09:52:00 -07:00
|
|
|
|
|
|
|
configure_file(versiondef.h.in auto/versiondef.h.gen)
|
2023-05-18 07:27:05 -07:00
|
|
|
|
2023-02-02 16:00:15 -07:00
|
|
|
file(GENERATE
|
2023-02-16 13:52:41 -07:00
|
|
|
OUTPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef-$<CONFIG>.h"
|
2023-02-02 16:00:15 -07:00
|
|
|
INPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen")
|
2015-03-01 08:36:10 -07:00
|
|
|
|
2014-01-31 06:39:15 -07:00
|
|
|
configure_file (
|
2022-06-27 03:08:59 -07:00
|
|
|
"${PROJECT_SOURCE_DIR}/cmake.config/pathdef.c.in"
|
|
|
|
"${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.c"
|
2014-01-31 06:39:15 -07:00
|
|
|
ESCAPE_QUOTES)
|