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. 39macro(curl_internal_test CURL_TEST) 40 if(NOT DEFINED "${CURL_TEST}") 41 set(MACRO_CHECK_FUNCTION_DEFINITIONS 42 "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}") 43 if(CMAKE_REQUIRED_LIBRARIES) 44 set(CURL_TEST_ADD_LIBRARIES 45 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") 46 endif() 47 48 message(STATUS "Performing Test ${CURL_TEST}") 49 try_compile(${CURL_TEST} 50 ${CMAKE_BINARY_DIR} 51 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c 52 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} 53 "${CURL_TEST_ADD_LIBRARIES}" 54 OUTPUT_VARIABLE OUTPUT) 55 if(${CURL_TEST}) 56 set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}") 57 message(STATUS "Performing Test ${CURL_TEST} - Success") 58 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 59 "Performing Test ${CURL_TEST} passed with the following output:\n" 60 "${OUTPUT}\n") 61 else() 62 message(STATUS "Performing Test ${CURL_TEST} - Failed") 63 set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}") 64 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 65 "Performing Test ${CURL_TEST} failed with the following output:\n" 66 "${OUTPUT}\n") 67 endif() 68 endif() 69endmacro() 70 71macro(optional_dependency DEPENDENCY) 72 set(CURL_${DEPENDENCY} AUTO CACHE STRING "Build curl with ${DEPENDENCY} support (AUTO, ON or OFF)") 73 set_property(CACHE CURL_${DEPENDENCY} PROPERTY STRINGS AUTO ON OFF) 74 75 if(CURL_${DEPENDENCY} STREQUAL AUTO) 76 find_package(${DEPENDENCY}) 77 elseif(CURL_${DEPENDENCY}) 78 find_package(${DEPENDENCY} REQUIRED) 79 endif() 80endmacro() 81