Macros.cmake 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(optional_dependency DEPENDENCY)
  68. set(CURL_${DEPENDENCY} AUTO CACHE STRING "Build curl with ${DEPENDENCY} support (AUTO, ON or OFF)")
  69. set_property(CACHE CURL_${DEPENDENCY} PROPERTY STRINGS AUTO ON OFF)
  70. if(CURL_${DEPENDENCY} STREQUAL AUTO)
  71. find_package(${DEPENDENCY})
  72. elseif(CURL_${DEPENDENCY})
  73. find_package(${DEPENDENCY} REQUIRED)
  74. endif()
  75. endmacro()