113498266Sopenharmony_ci#***************************************************************************
213498266Sopenharmony_ci#                                  _   _ ____  _
313498266Sopenharmony_ci#  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci#                             / __| | | | |_) | |
513498266Sopenharmony_ci#                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci#                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci#
813498266Sopenharmony_ci# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci#
1013498266Sopenharmony_ci# This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci# you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci# are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci#
1413498266Sopenharmony_ci# You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci# copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci# furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci#
1813498266Sopenharmony_ci# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci# KIND, either express or implied.
2013498266Sopenharmony_ci#
2113498266Sopenharmony_ci# SPDX-License-Identifier: curl
2213498266Sopenharmony_ci#
2313498266Sopenharmony_ci###########################################################################
2413498266Sopenharmony_ci#File defines convenience macros for available feature testing
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci# Check if header file exists and add it to the list.
2713498266Sopenharmony_ci# This macro is intended to be called multiple times with a sequence of
2813498266Sopenharmony_ci# possibly dependent header files.  Some headers depend on others to be
2913498266Sopenharmony_ci# compiled correctly.
3013498266Sopenharmony_cimacro(check_include_file_concat FILE VARIABLE)
3113498266Sopenharmony_ci  check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
3213498266Sopenharmony_ci  if(${VARIABLE})
3313498266Sopenharmony_ci    set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
3413498266Sopenharmony_ci    set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
3513498266Sopenharmony_ci  endif()
3613498266Sopenharmony_ciendmacro()
3713498266Sopenharmony_ci
3813498266Sopenharmony_ci# For other curl specific tests, use this macro.
3913498266Sopenharmony_cimacro(curl_internal_test CURL_TEST)
4013498266Sopenharmony_ci  if(NOT DEFINED "${CURL_TEST}")
4113498266Sopenharmony_ci    set(MACRO_CHECK_FUNCTION_DEFINITIONS
4213498266Sopenharmony_ci      "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
4313498266Sopenharmony_ci    if(CMAKE_REQUIRED_LIBRARIES)
4413498266Sopenharmony_ci      set(CURL_TEST_ADD_LIBRARIES
4513498266Sopenharmony_ci        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
4613498266Sopenharmony_ci    endif()
4713498266Sopenharmony_ci
4813498266Sopenharmony_ci    message(STATUS "Performing Test ${CURL_TEST}")
4913498266Sopenharmony_ci    try_compile(${CURL_TEST}
5013498266Sopenharmony_ci      ${CMAKE_BINARY_DIR}
5113498266Sopenharmony_ci      ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
5213498266Sopenharmony_ci      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
5313498266Sopenharmony_ci      "${CURL_TEST_ADD_LIBRARIES}"
5413498266Sopenharmony_ci      OUTPUT_VARIABLE OUTPUT)
5513498266Sopenharmony_ci    if(${CURL_TEST})
5613498266Sopenharmony_ci      set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
5713498266Sopenharmony_ci      message(STATUS "Performing Test ${CURL_TEST} - Success")
5813498266Sopenharmony_ci      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
5913498266Sopenharmony_ci        "Performing Test ${CURL_TEST} passed with the following output:\n"
6013498266Sopenharmony_ci        "${OUTPUT}\n")
6113498266Sopenharmony_ci    else()
6213498266Sopenharmony_ci      message(STATUS "Performing Test ${CURL_TEST} - Failed")
6313498266Sopenharmony_ci      set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
6413498266Sopenharmony_ci      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
6513498266Sopenharmony_ci        "Performing Test ${CURL_TEST} failed with the following output:\n"
6613498266Sopenharmony_ci        "${OUTPUT}\n")
6713498266Sopenharmony_ci    endif()
6813498266Sopenharmony_ci  endif()
6913498266Sopenharmony_ciendmacro()
7013498266Sopenharmony_ci
7113498266Sopenharmony_cimacro(curl_nroff_check)
7213498266Sopenharmony_ci  find_program(NROFF NAMES gnroff nroff)
7313498266Sopenharmony_ci  if(NROFF)
7413498266Sopenharmony_ci    # Need a way to write to stdin, this will do
7513498266Sopenharmony_ci    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
7613498266Sopenharmony_ci    # Tests for a valid nroff option to generate a manpage
7713498266Sopenharmony_ci    foreach(_MANOPT "-man" "-mandoc")
7813498266Sopenharmony_ci      execute_process(COMMAND "${NROFF}" ${_MANOPT}
7913498266Sopenharmony_ci        OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
8013498266Sopenharmony_ci        INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
8113498266Sopenharmony_ci        ERROR_QUIET)
8213498266Sopenharmony_ci      # Save the option if it was valid
8313498266Sopenharmony_ci      if(NROFF_MANOPT_OUTPUT)
8413498266Sopenharmony_ci        message("Found *nroff option: -- ${_MANOPT}")
8513498266Sopenharmony_ci        set(NROFF_MANOPT ${_MANOPT})
8613498266Sopenharmony_ci        set(NROFF_USEFUL ON)
8713498266Sopenharmony_ci        break()
8813498266Sopenharmony_ci      endif()
8913498266Sopenharmony_ci    endforeach()
9013498266Sopenharmony_ci    # No need for the temporary file
9113498266Sopenharmony_ci    file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
9213498266Sopenharmony_ci    if(NOT NROFF_USEFUL)
9313498266Sopenharmony_ci      message(WARNING "Found no *nroff option to get plaintext from man pages")
9413498266Sopenharmony_ci    endif()
9513498266Sopenharmony_ci  else()
9613498266Sopenharmony_ci    message(WARNING "Found no *nroff program")
9713498266Sopenharmony_ci  endif()
9813498266Sopenharmony_ciendmacro()
9913498266Sopenharmony_ci
10013498266Sopenharmony_cimacro(optional_dependency DEPENDENCY)
10113498266Sopenharmony_ci  set(CURL_${DEPENDENCY} AUTO CACHE STRING "Build curl with ${DEPENDENCY} support (AUTO, ON or OFF)")
10213498266Sopenharmony_ci  set_property(CACHE CURL_${DEPENDENCY} PROPERTY STRINGS AUTO ON OFF)
10313498266Sopenharmony_ci
10413498266Sopenharmony_ci  if(CURL_${DEPENDENCY} STREQUAL AUTO)
10513498266Sopenharmony_ci    find_package(${DEPENDENCY})
10613498266Sopenharmony_ci  elseif(CURL_${DEPENDENCY})
10713498266Sopenharmony_ci    find_package(${DEPENDENCY} REQUIRED)
10813498266Sopenharmony_ci  endif()
10913498266Sopenharmony_ciendmacro()
110