• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(curl_nroff_check)
72  find_program(NROFF NAMES gnroff nroff)
73  if(NROFF)
74    # Need a way to write to stdin, this will do
75    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
76    # Tests for a valid nroff option to generate a manpage
77    foreach(_MANOPT "-man" "-mandoc")
78      execute_process(COMMAND "${NROFF}" ${_MANOPT}
79        OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
80        INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
81        ERROR_QUIET)
82      # Save the option if it was valid
83      if(NROFF_MANOPT_OUTPUT)
84        message("Found *nroff option: -- ${_MANOPT}")
85        set(NROFF_MANOPT ${_MANOPT})
86        set(NROFF_USEFUL ON)
87        break()
88      endif()
89    endforeach()
90    # No need for the temporary file
91    file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
92    if(NOT NROFF_USEFUL)
93      message(WARNING "Found no *nroff option to get plaintext from man pages")
94    endif()
95  else()
96    message(WARNING "Found no *nroff program")
97  endif()
98endmacro()
99
100macro(optional_dependency DEPENDENCY)
101  set(CURL_${DEPENDENCY} AUTO CACHE STRING "Build curl with ${DEPENDENCY} support (AUTO, ON or OFF)")
102  set_property(CACHE CURL_${DEPENDENCY} PROPERTY STRINGS AUTO ON OFF)
103
104  if(CURL_${DEPENDENCY} STREQUAL AUTO)
105    find_package(${DEPENDENCY})
106  elseif(CURL_${DEPENDENCY})
107    find_package(${DEPENDENCY} REQUIRED)
108  endif()
109endmacro()
110