Macros.cmake 4.2 KB

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