1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9# 10# This software is licensed as described in the file COPYING, which 11# you should have received as part of this distribution. The terms 12# are also available at https://curl.se/docs/copyright.html. 13# 14# You may opt to use, copy, modify, merge, publish, distribute and/or sell 15# copies of the Software, and permit persons to whom the Software is 16# furnished to do so, under the terms of the COPYING file. 17# 18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19# KIND, either express or implied. 20# 21# SPDX-License-Identifier: curl 22# 23########################################################################### 24# File defines convenience macros for available feature testing 25 26# Check if header file exists and add it to the list. 27# This macro is intended to be called multiple times with a sequence of 28# possibly dependent header files. Some headers depend on others to be 29# compiled correctly. 30macro(check_include_file_concat _file _variable) 31 check_include_files("${CURL_INCLUDES};${_file}" ${_variable}) 32 if(${_variable}) 33 set(CURL_INCLUDES ${CURL_INCLUDES} ${_file}) 34 set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${_variable}") 35 endif() 36endmacro() 37 38# For other curl specific tests, use this macro. 39# Return result in variable: CURL_TEST_OUTPUT 40macro(curl_internal_test _curl_test) 41 if(NOT DEFINED "${_curl_test}") 42 set(_macro_check_function_definitions 43 "-D${_curl_test} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}") 44 if(CMAKE_REQUIRED_LIBRARIES) 45 set(_curl_test_add_libraries 46 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") 47 endif() 48 49 message(STATUS "Performing Test ${_curl_test}") 50 try_compile(${_curl_test} 51 ${CMAKE_BINARY_DIR} 52 "${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c" 53 CMAKE_FLAGS 54 "-DCOMPILE_DEFINITIONS:STRING=${_macro_check_function_definitions}" 55 "${_curl_test_add_libraries}" 56 OUTPUT_VARIABLE CURL_TEST_OUTPUT) 57 if(${_curl_test}) 58 set(${_curl_test} 1 CACHE INTERNAL "Curl test") 59 message(STATUS "Performing Test ${_curl_test} - Success") 60 else() 61 set(${_curl_test} "" CACHE INTERNAL "Curl test") 62 message(STATUS "Performing Test ${_curl_test} - Failed") 63 endif() 64 endif() 65endmacro() 66 67macro(curl_dependency_option _dependency) 68 set(CURL_${_dependency} "AUTO" CACHE STRING "Build curl with ${_dependency} support (AUTO, ON or OFF)") 69 set_property(CACHE CURL_${_dependency} PROPERTY STRINGS "AUTO" "ON" "OFF") 70 71 if(CURL_${_dependency} STREQUAL "AUTO") 72 find_package(${_dependency}) 73 elseif(CURL_${_dependency}) 74 find_package(${_dependency} REQUIRED) 75 endif() 76endmacro() 77