FindCURL.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. # First, prefer config scripts
  32. set(_q "")
  33. if(CURL_FIND_QUIETLY)
  34. set(_q QUIET)
  35. endif()
  36. find_package(CURL ${CURL_FIND_VERSION} CONFIG ${_q})
  37. if(NOT CURL_FIND_QUIETLY)
  38. if (NOT CURL_FOUND)
  39. message(STATUS "Falling back to MODULE search for CURL...")
  40. else()
  41. message(STATUS "CURL found in ${CURL_DIR}")
  42. endif()
  43. endif()
  44. if (NOT CURL_FOUND)
  45. # Look for the header file.
  46. find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
  47. mark_as_advanced(CURL_INCLUDE_DIR)
  48. if(NOT CURL_LIBRARY)
  49. # Look for the library (sorted from most current/relevant entry to least).
  50. find_library(CURL_LIBRARY_RELEASE NAMES
  51. curl
  52. # Windows MSVC prebuilts:
  53. curllib
  54. libcurl_imp
  55. curllib_static
  56. # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip):
  57. libcurl
  58. # Static library on Windows
  59. libcurl_a
  60. )
  61. mark_as_advanced(CURL_LIBRARY_RELEASE)
  62. find_library(CURL_LIBRARY_DEBUG NAMES
  63. # Windows MSVC CMake builds in debug configuration on vcpkg:
  64. libcurl-d_imp
  65. libcurl-d
  66. # Static library on Windows, compiled in debug mode
  67. libcurl_a_debug
  68. )
  69. mark_as_advanced(CURL_LIBRARY_DEBUG)
  70. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations_SLIC3R.cmake)
  71. select_library_configurations_SLIC3R(CURL)
  72. endif()
  73. if(CURL_INCLUDE_DIR)
  74. foreach(_curl_version_header curlver.h curl.h)
  75. if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}")
  76. file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"")
  77. string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}")
  78. unset(curl_version_str)
  79. break()
  80. endif()
  81. endforeach()
  82. endif()
  83. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs_SLIC3R.cmake)
  84. FIND_PACKAGE_HANDLE_STANDARD_ARGS_SLIC3R(CURL
  85. REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
  86. VERSION_VAR CURL_VERSION_STRING)
  87. if(CURL_FOUND)
  88. set(CURL_LIBRARIES ${CURL_LIBRARY})
  89. set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
  90. if(NOT TARGET CURL::libcurl)
  91. add_library(CURL::libcurl UNKNOWN IMPORTED)
  92. set_target_properties(CURL::libcurl PROPERTIES
  93. INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}")
  94. if(EXISTS "${CURL_LIBRARY}")
  95. set_target_properties(CURL::libcurl PROPERTIES
  96. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  97. IMPORTED_LOCATION "${CURL_LIBRARY}")
  98. endif()
  99. if(CURL_LIBRARY_RELEASE)
  100. set_property(TARGET CURL::libcurl APPEND PROPERTY
  101. IMPORTED_CONFIGURATIONS RELEASE)
  102. set_target_properties(CURL::libcurl PROPERTIES
  103. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  104. IMPORTED_LOCATION_RELEASE "${CURL_LIBRARY_RELEASE}")
  105. endif()
  106. if(CURL_LIBRARY_DEBUG)
  107. set_property(TARGET CURL::libcurl APPEND PROPERTY
  108. IMPORTED_CONFIGURATIONS DEBUG)
  109. set_target_properties(CURL::libcurl PROPERTIES
  110. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  111. IMPORTED_LOCATION_DEBUG "${CURL_LIBRARY_DEBUG}")
  112. endif()
  113. endif()
  114. endif()
  115. endif (NOT CURL_FOUND)