Macros.cmake 4.7 KB

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