Macros.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_curl _file _variable)
  30. check_include_files("${CURL_INCLUDES};${_file}" ${_variable})
  31. if(${_variable})
  32. list(APPEND CURL_INCLUDES ${_file})
  33. endif()
  34. endmacro()
  35. # For other curl specific tests, use this macro.
  36. # Return result in variable: CURL_TEST_OUTPUT
  37. macro(curl_internal_test _curl_test)
  38. if(NOT DEFINED "${_curl_test}")
  39. string(REPLACE ";" " " _cmake_required_definitions "${CMAKE_REQUIRED_DEFINITIONS}")
  40. if(CMAKE_REQUIRED_LIBRARIES)
  41. set(_curl_test_add_libraries
  42. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  43. endif()
  44. message(STATUS "Performing Test ${_curl_test}")
  45. try_compile(${_curl_test}
  46. ${PROJECT_BINARY_DIR}
  47. "${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c"
  48. CMAKE_FLAGS
  49. "-DCOMPILE_DEFINITIONS:STRING=-D${_curl_test} ${CURL_TEST_DEFINES} ${_cmake_required_definitions}"
  50. "${_curl_test_add_libraries}"
  51. OUTPUT_VARIABLE CURL_TEST_OUTPUT)
  52. if(${_curl_test})
  53. set(${_curl_test} 1 CACHE INTERNAL "Curl test")
  54. message(STATUS "Performing Test ${_curl_test} - Success")
  55. else()
  56. set(${_curl_test} "" CACHE INTERNAL "Curl test")
  57. message(STATUS "Performing Test ${_curl_test} - Failed")
  58. endif()
  59. endif()
  60. endmacro()
  61. macro(curl_dependency_option _option_name _find_name _desc_name)
  62. set(${_option_name} "AUTO" CACHE STRING "Build curl with ${_desc_name} support (AUTO, ON or OFF)")
  63. set_property(CACHE ${_option_name} PROPERTY STRINGS "AUTO" "ON" "OFF")
  64. if(${_option_name} STREQUAL "AUTO")
  65. find_package(${_find_name})
  66. elseif(${_option_name})
  67. find_package(${_find_name} REQUIRED)
  68. endif()
  69. endmacro()
  70. # Convert the passed paths to libpath linker options and add them to CMAKE_REQUIRED_*.
  71. macro(curl_required_libpaths _libpaths_arg)
  72. if(CMAKE_VERSION VERSION_LESS 3.31)
  73. set(_libpaths "${_libpaths_arg}")
  74. foreach(_libpath IN LISTS _libpaths)
  75. list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_LIBRARY_PATH_FLAG}${_libpath}")
  76. endforeach()
  77. else()
  78. list(APPEND CMAKE_REQUIRED_LINK_DIRECTORIES "${_libpaths_arg}")
  79. endif()
  80. endmacro()