3rdparty/libzip: Hardcode most checks

We are only targetting a limited number of platforms.

Significantly speeds up generation time with Xcode.
This commit is contained in:
Stenzek 2023-12-30 17:22:01 +10:00 committed by Connor McLaughlin
parent 8e5fc236ca
commit 96fb49e35c
1 changed files with 67 additions and 156 deletions

View File

@ -28,103 +28,83 @@ include(TestBigEndian)
# Request ISO C secure library functions (memcpy_s &c) # Request ISO C secure library functions (memcpy_s &c)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__STDC_WANT_LIB_EXT1__=1) list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__STDC_WANT_LIB_EXT1__=1)
check_function_exists(_close HAVE__CLOSE) # Replaced these dynamic checks with static, otherwise XCode is slow to configure.
check_function_exists(_dup HAVE__DUP) set(HAVE__CLOSE ${MSVC})
check_function_exists(_fdopen HAVE__FDOPEN) set(HAVE__DUP ${MSVC})
check_function_exists(_fileno HAVE__FILENO) set(HAVE__FDOPEN ${MSVC})
check_function_exists(_setmode HAVE__SETMODE) set(HAVE__FILENO ${MSVC})
check_symbol_exists(_snprintf stdio.h HAVE__SNPRINTF) set(HAVE__SETMODE ${MSVC})
check_symbol_exists(_snprintf_s stdio.h HAVE__SNPRINTF_S) set(HAVE__SNPRINTF ${MSVC})
check_symbol_exists(_snwprintf_s stdio.h HAVE__SNWPRINTF_S) set(HAVE__SNPRINTF_S ${MSVC})
check_function_exists(_strdup HAVE__STRDUP) set(HAVE__SNWPRINTF_S ${MSVC})
check_symbol_exists(_stricmp string.h HAVE__STRICMP) set(HAVE__STRDUP ${MSVC})
check_function_exists(_strtoi64 HAVE__STRTOI64) set(HAVE__STRICMP ${MSVC})
check_function_exists(_strtoui64 HAVE__STRTOUI64) set(HAVE__STRTOI64 ${MSVC})
check_function_exists(_unlink HAVE__UNLINK) set(HAVE__STRTOUI64 ${MSVC})
check_function_exists(arc4random HAVE_ARC4RANDOM) set(HAVE__UNLINK ${MSVC})
check_function_exists(clonefile HAVE_CLONEFILE) set(HAVE_ARC4RANDOM ${APPLE})
check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) set(HAVE_CLONEFILE ${APPLE})
check_function_exists(explicit_memset HAVE_EXPLICIT_MEMSET) set(HAVE_EXPLICIT_BZERO ${LINUX})
check_function_exists(fchmod HAVE_FCHMOD) set(HAVE_EXPLICIT_MEMSET ${LINUX})
check_function_exists(fileno HAVE_FILENO) set(HAVE_FCHMOD ${UNIX})
check_function_exists(fseeko HAVE_FSEEKO) set(HAVE_FILENO TRUE)
check_function_exists(ftello HAVE_FTELLO) set(HAVE_FSEEKO ${UNIX})
check_function_exists(getprogname HAVE_GETPROGNAME) set(HAVE_FTELLO ${UNIX})
check_symbol_exists(localtime_r time.h HAVE_LOCALTIME_R) set(HAVE_GETPROGNAME ${APPLE})
check_symbol_exists(localtime_s time.h HAVE_LOCALTIME_S) set(HAVE_LOCALTIME_R ${UNIX})
check_function_exists(memcpy_s HAVE_MEMCPY_S) set(HAVE_LOCALTIME_S ${MSVC})
check_function_exists(random HAVE_RANDOM) set(HAVE_MEMCPY_S ${MSVC})
check_function_exists(setmode HAVE_SETMODE) set(HAVE_RANDOM ${UNIX})
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF) set(HAVE_SETMODE ${APPLE})
check_symbol_exists(snprintf_s stdio.h HAVE_SNPRINTF_S) set(HAVE_SNPRINTF TRUE)
check_symbol_exists(strcasecmp strings.h HAVE_STRCASECMP) set(HAVE_SNPRINTF_S FALSE)
check_function_exists(strdup HAVE_STRDUP) set(HAVE_STRCASECMP ${UNIX})
check_function_exists(strerror_s HAVE_STRERROR_S) set(HAVE_STRDUP TRUE)
check_function_exists(strerrorlen_s HAVE_STRERRORLEN_S) set(HAVE_STRERROR_S ${MSVC})
check_function_exists(stricmp HAVE_STRICMP) set(HAVE_STRERRORLEN_S FALSE)
check_function_exists(strncpy_s HAVE_STRNCPY_S) set(HAVE_STRICMP ${MSVC})
check_function_exists(strtoll HAVE_STRTOLL) set(HAVE_STRNCPY_S ${MSVC})
check_function_exists(strtoull HAVE_STRTOULL) set(HAVE_STRTOLL TRUE)
set(HAVE_STRTOULL TRUE)
check_include_files("sys/types.h;sys/stat.h;fts.h" HAVE_FTS_H) if(UNIX)
# fts functions may be in external library set(HAVE_FTS_H TRUE)
if(HAVE_FTS_H)
check_function_exists(fts_open HAVE_FTS_OPEN) check_function_exists(fts_open HAVE_FTS_OPEN)
if(NOT HAVE_FTS_OPEN) if(NOT HAVE_FTS_OPEN)
check_library_exists(fts fts_open "" HAVE_LIB_FTS) check_library_exists(fts fts_open "" HAVE_LIB_FTS)
else(NOT HAVE_FTS_OPEN) else(NOT HAVE_FTS_OPEN)
set(HAVE_LIB_FTS "" CACHE INTERNAL "") set(HAVE_LIB_FTS "")
endif(NOT HAVE_FTS_OPEN) endif(NOT HAVE_FTS_OPEN)
else(HAVE_FTS_H)
set(HAVE_LIB_FTS "" CACHE INTERNAL "")
endif(HAVE_FTS_H)
if(HAVE_LIB_FTS)
set(FTS_LIB fts CACHE INTERNAL "")
else() else()
set(FTS_LIB "" CACHE INTERNAL "") set(HAVE_LIB_FTS "")
endif() endif()
check_include_files(stdbool.h HAVE_STDBOOL_H) if(HAVE_LIB_FTS)
check_include_files(strings.h HAVE_STRINGS_H) set(FTS_LIB fts)
check_include_files(unistd.h HAVE_UNISTD_H) else()
set(FTS_LIB "")
endif()
check_include_files(inttypes.h HAVE_INTTYPES_H_LIBZIP) set(HAVE_STDBOOL_H TRUE)
check_include_files(stdint.h HAVE_STDINT_H_LIBZIP) set(HAVE_STRINGS_H ${UNIX})
check_include_files(sys/types.h HAVE_SYS_TYPES_H_LIBZIP) set(HAVE_UNISTD_H ${UNIX})
# TODO: fix test
# this test does not find __progname even when it exists
#check_symbol_exists(__progname stdlib.h HAVE___PROGNAME)
check_type_size(__int8 __INT8_LIBZIP)
check_type_size(int8_t INT8_T_LIBZIP)
check_type_size(uint8_t UINT8_T_LIBZIP)
check_type_size(__int16 __INT16_LIBZIP)
check_type_size(int16_t INT16_T_LIBZIP)
check_type_size(uint16_t UINT16_T_LIBZIP)
check_type_size(__int32 __INT32_LIBZIP)
check_type_size(int32_t INT32_T_LIBZIP)
check_type_size(uint32_t UINT32_T_LIBZIP)
check_type_size(__int64 __INT64_LIBZIP)
check_type_size(int64_t INT64_T_LIBZIP)
check_type_size(uint64_t UINT64_T_LIBZIP)
check_type_size("short" SHORT_LIBZIP)
check_type_size("int" INT_LIBZIP)
check_type_size("long" LONG_LIBZIP)
check_type_size("long long" LONG_LONG_LIBZIP)
check_type_size("off_t" SIZEOF_OFF_T) check_type_size("off_t" SIZEOF_OFF_T)
check_type_size("size_t" SIZEOF_SIZE_T) check_type_size("size_t" SIZEOF_SIZE_T)
check_c_source_compiles("#include <sys/ioctl.h> if(LINUX)
#include <linux/fs.h> check_c_source_compiles("#include <sys/ioctl.h>
int main(int argc, char *argv[]) { unsigned long x = FICLONERANGE; }" HAVE_FICLONERANGE) #include <linux/fs.h>
int main(int argc, char *argv[]) { unsigned long x = FICLONERANGE; }" HAVE_FICLONERANGE)
else()
set(HAVE_FICLONERANGE FALSE)
endif()
check_c_source_compiles(" check_c_source_compiles("
int foo(char * _Nullable bar); int foo(char * _Nullable bar);
int main(int argc, char *argv[]) { }" HAVE_NULLABLE) int main(int argc, char *argv[]) { }" HAVE_NULLABLE)
test_big_endian(WORDS_BIGENDIAN) set(WORDS_BIGENDIAN FALSE)
if(MSVC) if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
@ -133,88 +113,19 @@ endif(MSVC)
# fixed size integral types # fixed size integral types
if(HAVE_INTTYPES_H_LIBZIP) set(LIBZIP_TYPES_INCLUDE "#if !defined(__STDC_FORMAT_MACROS)
set(LIBZIP_TYPES_INCLUDE "#if !defined(__STDC_FORMAT_MACROS)
#define __STDC_FORMAT_MACROS 1 #define __STDC_FORMAT_MACROS 1
#endif #endif
#include <inttypes.h>") #include <inttypes.h>")
elseif(HAVE_STDINT_H_LIBZIP)
set(LIBZIP_TYPES_INCLUDE "#include <stdint.h>")
elseif(HAVE_SYS_TYPES_H_LIBZIP)
set(LIBZIP_TYPES_INCLUDE "#include <sys/types.h>")
endif()
if(HAVE_INT8_T_LIBZIP) set(ZIP_INT8_T int8_t)
set(ZIP_INT8_T int8_t) set(ZIP_UINT8_T uint8_t)
elseif(HAVE___INT8_LIBZIP) set(ZIP_INT16_T int16_t)
set(ZIP_INT8_T __int8) set(ZIP_UINT16_T uint16_t)
else() set(ZIP_INT32_T int32_t)
set(ZIP_INT8_T "signed char") set(ZIP_UINT32_T uint32_t)
endif() set(ZIP_INT64_T int64_t)
set(ZIP_UINT64_T uint64_t)
if(HAVE_UINT8_T_LIBZIP)
set(ZIP_UINT8_T uint8_t)
elseif(HAVE___INT8_LIBZIP)
set(ZIP_UINT8_T "unsigned __int8")
else()
set(ZIP_UINT8_T "unsigned char")
endif()
if(HAVE_INT16_T_LIBZIP)
set(ZIP_INT16_T int16_t)
elseif(HAVE___INT16_LIBZIP)
set(INT16_T_LIBZIP __int16)
elseif(SHORT_LIBZIP EQUAL 2)
set(INT16_T_LIBZIP short)
endif()
if(HAVE_UINT16_T_LIBZIP)
set(ZIP_UINT16_T uint16_t)
elseif(HAVE___INT16_LIBZIP)
set(UINT16_T_LIBZIP "unsigned __int16")
elseif(SHORT_LIBZIP EQUAL 2)
set(UINT16_T_LIBZIP "unsigned short")
endif()
if(HAVE_INT32_T_LIBZIP)
set(ZIP_INT32_T int32_t)
elseif(HAVE___INT32_LIBZIP)
set(ZIP_INT32_T __int32)
elseif(INT_LIBZIP EQUAL 4)
set(ZIP_INT32_T int)
elseif(LONG_LIBZIP EQUAL 4)
set(ZIP_INT32_T long)
endif()
if(HAVE_UINT32_T_LIBZIP)
set(ZIP_UINT32_T uint32_t)
elseif(HAVE___INT32_LIBZIP)
set(ZIP_UINT32_T "unsigned __int32")
elseif(INT_LIBZIP EQUAL 4)
set(ZIP_UINT32_T "unsigned int")
elseif(LONG_LIBZIP EQUAL 4)
set(ZIP_UINT32_T "unsigned long")
endif()
if(HAVE_INT64_T_LIBZIP)
set(ZIP_INT64_T int64_t)
elseif(HAVE___INT64_LIBZIP)
set(ZIP_INT64_T __int64)
elseif(LONG_LIBZIP EQUAL 8)
set(ZIP_INT64_T long)
elseif(LONG_LONG_LIBZIP EQUAL 8)
set(ZIP_INT64_T "long long")
endif()
if(HAVE_UINT64_T_LIBZIP)
set(ZIP_UINT64_T uint64_t)
elseif(HAVE___INT64_LIBZIP)
set(ZIP_UINT64_T "unsigned __int64")
elseif(LONG_LIBZIP EQUAL 8)
set(ZIP_UINT64_T "unsigned long")
elseif(LONG_LONG_LIBZIP EQUAL 8)
set(ZIP_UINT64_T "unsigned long long")
endif()
if(HAVE_NULLABLE) if(HAVE_NULLABLE)
set(ZIP_NULLABLE_DEFINES) set(ZIP_NULLABLE_DEFINES)