• 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# This macro checks if the symbol exists in the library and if it
27# does, it prepends library to the list.  It is intended to be called
28# multiple times with a sequence of possibly dependent libraries in
29# order of least-to-most-dependent.  Some libraries depend on others
30# to link correctly.
31macro(check_library_exists_concat LIBRARY SYMBOL VARIABLE)
32  check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
33    ${VARIABLE})
34  if(${VARIABLE})
35    set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
36  endif()
37endmacro()
38
39# Check if header file exists and add it to the list.
40# This macro is intended to be called multiple times with a sequence of
41# possibly dependent header files.  Some headers depend on others to be
42# compiled correctly.
43macro(check_include_file_concat FILE VARIABLE)
44  check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
45  if(${VARIABLE})
46    set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
47    set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
48  endif()
49endmacro()
50
51# For other curl specific tests, use this macro.
52macro(curl_internal_test CURL_TEST)
53  if(NOT DEFINED "${CURL_TEST}")
54    set(MACRO_CHECK_FUNCTION_DEFINITIONS
55      "-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
56    if(CMAKE_REQUIRED_LIBRARIES)
57      set(CURL_TEST_ADD_LIBRARIES
58        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
59    endif()
60
61    message(STATUS "Performing Curl Test ${CURL_TEST}")
62    try_compile(${CURL_TEST}
63      ${CMAKE_BINARY_DIR}
64      ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
65      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
66      "${CURL_TEST_ADD_LIBRARIES}"
67      OUTPUT_VARIABLE OUTPUT)
68    if(${CURL_TEST})
69      set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
70      message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
71      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
72        "Performing Curl Test ${CURL_TEST} passed with the following output:\n"
73        "${OUTPUT}\n")
74    else()
75      message(STATUS "Performing Curl Test ${CURL_TEST} - Failed")
76      set(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}")
77      file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
78        "Performing Curl Test ${CURL_TEST} failed with the following output:\n"
79        "${OUTPUT}\n")
80    endif()
81  endif()
82endmacro()
83
84macro(curl_nroff_check)
85  find_program(NROFF NAMES gnroff nroff)
86  if(NROFF)
87    # Need a way to write to stdin, this will do
88    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
89    # Tests for a valid nroff option to generate a manpage
90    foreach(_MANOPT "-man" "-mandoc")
91      execute_process(COMMAND "${NROFF}" ${_MANOPT}
92        OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
93        INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
94        ERROR_QUIET)
95      # Save the option if it was valid
96      if(NROFF_MANOPT_OUTPUT)
97        message("Found *nroff option: -- ${_MANOPT}")
98        set(NROFF_MANOPT ${_MANOPT})
99        set(NROFF_USEFUL ON)
100        break()
101      endif()
102    endforeach()
103    # No need for the temporary file
104    file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
105    if(NOT NROFF_USEFUL)
106      message(WARNING "Found no *nroff option to get plaintext from man pages")
107    endif()
108  else()
109    message(WARNING "Found no *nroff program")
110  endif()
111endmacro()
112
113macro(optional_dependency DEPENDENCY)
114  set(CURL_${DEPENDENCY} AUTO CACHE STRING "Build curl with ${DEPENDENCY} support (AUTO, ON or OFF)")
115  set_property(CACHE CURL_${DEPENDENCY} PROPERTY STRINGS AUTO ON OFF)
116
117  if(CURL_${DEPENDENCY} STREQUAL AUTO)
118    find_package(${DEPENDENCY})
119  elseif(CURL_${DEPENDENCY})
120    find_package(${DEPENDENCY} REQUIRED)
121  endif()
122endmacro()
123