FindCURL.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindCURL
  5. --------
  6. Find the native CURL headers and libraries.
  7. IMPORTED Targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines :prop_tgt:`IMPORTED` target ``CURL::libcurl``, if
  10. curl has been found.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module defines the following variables:
  14. ``CURL_FOUND``
  15. True if curl found.
  16. ``CURL_INCLUDE_DIRS``
  17. where to find curl/curl.h, etc.
  18. ``CURL_LIBRARIES``
  19. List of libraries when using curl.
  20. ``CURL_VERSION_STRING``
  21. The version of curl found.
  22. #]=======================================================================]
  23. # Look for the header file.
  24. find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
  25. mark_as_advanced(CURL_INCLUDE_DIR)
  26. if(NOT CURL_LIBRARY)
  27. # Look for the library (sorted from most current/relevant entry to least).
  28. find_library(CURL_LIBRARY_RELEASE NAMES
  29. curl
  30. # Windows MSVC prebuilts:
  31. curllib
  32. libcurl_imp
  33. curllib_static
  34. # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip):
  35. libcurl
  36. )
  37. mark_as_advanced(CURL_LIBRARY_RELEASE)
  38. find_library(CURL_LIBRARY_DEBUG NAMES
  39. # Windows MSVC CMake builds in debug configuration on vcpkg:
  40. libcurl-d_imp
  41. libcurl-d
  42. )
  43. mark_as_advanced(CURL_LIBRARY_DEBUG)
  44. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  45. select_library_configurations(CURL)
  46. endif()
  47. if(CURL_INCLUDE_DIR)
  48. foreach(_curl_version_header curlver.h curl.h)
  49. if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}")
  50. file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"")
  51. string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}")
  52. unset(curl_version_str)
  53. break()
  54. endif()
  55. endforeach()
  56. endif()
  57. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  58. FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL
  59. REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
  60. VERSION_VAR CURL_VERSION_STRING)
  61. if(CURL_FOUND)
  62. set(CURL_LIBRARIES ${CURL_LIBRARY})
  63. set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
  64. if(NOT TARGET CURL::libcurl)
  65. add_library(CURL::libcurl UNKNOWN IMPORTED)
  66. set_target_properties(CURL::libcurl PROPERTIES
  67. INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}")
  68. if(EXISTS "${CURL_LIBRARY}")
  69. set_target_properties(CURL::libcurl PROPERTIES
  70. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  71. IMPORTED_LOCATION "${CURL_LIBRARY}")
  72. endif()
  73. if(CURL_LIBRARY_RELEASE)
  74. set_property(TARGET CURL::libcurl APPEND PROPERTY
  75. IMPORTED_CONFIGURATIONS RELEASE)
  76. set_target_properties(CURL::libcurl PROPERTIES
  77. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  78. IMPORTED_LOCATION_RELEASE "${CURL_LIBRARY_RELEASE}")
  79. endif()
  80. if(CURL_LIBRARY_DEBUG)
  81. set_property(TARGET CURL::libcurl APPEND PROPERTY
  82. IMPORTED_CONFIGURATIONS DEBUG)
  83. set_target_properties(CURL::libcurl PROPERTIES
  84. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  85. IMPORTED_LOCATION_DEBUG "${CURL_LIBRARY_DEBUG}")
  86. endif()
  87. endif()
  88. endif()