diff --git a/CMake/OtherTests.cmake b/CMake/OtherTests.cmake index 2e5b62f6e3..62eef12d71 100644 --- a/CMake/OtherTests.cmake +++ b/CMake/OtherTests.cmake @@ -32,7 +32,8 @@ macro(add_header_include _check _header) endif() endmacro() -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +set(_cmake_try_compile_target_type_save ${CMAKE_TRY_COMPILE_TARGET_TYPE}) +set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") if(NOT DEFINED HAVE_STRUCT_SOCKADDR_STORAGE) cmake_push_check_state() @@ -74,7 +75,8 @@ check_c_source_compiles("${_source_epilogue} return 0; }" HAVE_STRUCT_TIMEVAL) -unset(CMAKE_TRY_COMPILE_TARGET_TYPE) +set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_cmake_try_compile_target_type_save}) +unset(_cmake_try_compile_target_type_save) # Detect HAVE_GETADDRINFO_THREADSAFE @@ -150,3 +152,5 @@ if(NOT WIN32 AND NOT DEFINED HAVE_CLOCK_GETTIME_MONOTONIC_RAW) return 0; }" HAVE_CLOCK_GETTIME_MONOTONIC_RAW) endif() + +unset(_source_epilogue) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8b80dc7c6..9b74da979b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,17 @@ if(NOT DEFINED CMAKE_UNITY_BUILD_BATCH_SIZE) set(CMAKE_UNITY_BUILD_BATCH_SIZE 0) endif() +# Having CMAKE_TRY_COMPILE_TARGET_TYPE set to STATIC_LIBRARY breaks certain +# 'check_function_exists()' detections (possibly more), by detecting +# non-existing features. This happens by default when using 'ios.toolchain.cmake'. +# Work it around by setting this value to `EXECUTABLE`. +if(CMAKE_TRY_COMPILE_TARGET_TYPE STREQUAL "STATIC_LIBRARY") + message(STATUS "CMAKE_TRY_COMPILE_TARGET_TYPE was found set to STATIC_LIBRARY. " + "Overriding with EXECUTABLE for feature detections to work.") + set(_cmake_try_compile_target_type_save ${CMAKE_TRY_COMPILE_TARGET_TYPE}) + set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE") +endif() + option(CURL_WERROR "Turn compiler warnings into errors" OFF) option(PICKY_COMPILER "Enable picky compiler options" ON) option(BUILD_CURL_EXE "Build curl executable" ON) @@ -456,6 +467,11 @@ include(CheckCSourceCompiles) # Preload settings on Windows if(WIN32) include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake") +elseif(APPLE) + # Fast-track predicable feature detections + set(HAVE_EVENTFD 0) + set(HAVE_GETPASS_R 0) + set(HAVE_SENDMMSG 0) endif() if(ENABLE_THREADED_RESOLVER) @@ -470,7 +486,7 @@ if(ENABLE_THREADED_RESOLVER) endif() # Check for all needed libraries -if(NOT WIN32) +if(NOT WIN32 AND NOT APPLE) check_library_exists("socket" "connect" "" HAVE_LIBSOCKET) if(HAVE_LIBSOCKET) set(CURL_LIBS "socket;${CURL_LIBS}") @@ -1751,6 +1767,11 @@ if(CMAKE_COMPILER_IS_GNUCC AND APPLE) endif() endif() +if(_cmake_try_compile_target_type_save) + set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_cmake_try_compile_target_type_save}) + unset(_cmake_try_compile_target_type_save) +endif() + include(CMake/OtherTests.cmake) add_definitions("-DHAVE_CONFIG_H")