FindCURL.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #
  7. # Find the native CURL headers and libraries.
  8. #
  9. # IMPORTED Targets
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module defines :prop_tgt:`IMPORTED` target ``CURL::libcurl``, if
  13. # curl has been found.
  14. #
  15. # Result Variables
  16. # ^^^^^^^^^^^^^^^^
  17. #
  18. # This module defines the following variables:
  19. #
  20. # ``CURL_FOUND``
  21. # True if curl found.
  22. #
  23. # ``CURL_INCLUDE_DIRS``
  24. # where to find curl/curl.h, etc.
  25. #
  26. # ``CURL_LIBRARIES``
  27. # List of libraries when using curl.
  28. #
  29. # ``CURL_VERSION_STRING``
  30. # The version of curl found.
  31. # Look for the header file.
  32. find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
  33. mark_as_advanced(CURL_INCLUDE_DIR)
  34. if(NOT CURL_LIBRARY)
  35. # Look for the library (sorted from most current/relevant entry to least).
  36. find_library(CURL_LIBRARY_RELEASE NAMES
  37. curl
  38. # Windows MSVC prebuilts:
  39. curllib
  40. libcurl_imp
  41. curllib_static
  42. # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip):
  43. libcurl
  44. # Static library on Windows
  45. libcurl_a
  46. )
  47. mark_as_advanced(CURL_LIBRARY_RELEASE)
  48. find_library(CURL_LIBRARY_DEBUG NAMES
  49. # Windows MSVC CMake builds in debug configuration on vcpkg:
  50. libcurl-d_imp
  51. libcurl-d
  52. # Static library on Windows, compiled in debug mode
  53. libcurl_a_debug
  54. )
  55. mark_as_advanced(CURL_LIBRARY_DEBUG)
  56. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations_SLIC3R.cmake)
  57. select_library_configurations_SLIC3R(CURL)
  58. endif()
  59. if(CURL_INCLUDE_DIR)
  60. foreach(_curl_version_header curlver.h curl.h)
  61. if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}")
  62. file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"")
  63. string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}")
  64. unset(curl_version_str)
  65. break()
  66. endif()
  67. endforeach()
  68. endif()
  69. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs_SLIC3R.cmake)
  70. FIND_PACKAGE_HANDLE_STANDARD_ARGS_SLIC3R(CURL
  71. REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
  72. VERSION_VAR CURL_VERSION_STRING)
  73. if(CURL_FOUND)
  74. set(CURL_LIBRARIES ${CURL_LIBRARY})
  75. set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
  76. if(NOT TARGET CURL::libcurl)
  77. add_library(CURL::libcurl UNKNOWN IMPORTED)
  78. set_target_properties(CURL::libcurl PROPERTIES
  79. INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}")
  80. if(EXISTS "${CURL_LIBRARY}")
  81. set_target_properties(CURL::libcurl PROPERTIES
  82. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  83. IMPORTED_LOCATION "${CURL_LIBRARY}")
  84. endif()
  85. if(CURL_LIBRARY_RELEASE)
  86. set_property(TARGET CURL::libcurl APPEND PROPERTY
  87. IMPORTED_CONFIGURATIONS RELEASE)
  88. set_target_properties(CURL::libcurl PROPERTIES
  89. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  90. IMPORTED_LOCATION_RELEASE "${CURL_LIBRARY_RELEASE}")
  91. endif()
  92. if(CURL_LIBRARY_DEBUG)
  93. set_property(TARGET CURL::libcurl APPEND PROPERTY
  94. IMPORTED_CONFIGURATIONS DEBUG)
  95. set_target_properties(CURL::libcurl PROPERTIES
  96. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  97. IMPORTED_LOCATION_DEBUG "${CURL_LIBRARY_DEBUG}")
  98. endif()
  99. endif()
  100. endif()