FindCURL.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #.rst:
  2. # FindCURL
  3. # --------
  4. #
  5. # Find curl
  6. #
  7. # Find the native CURL headers and libraries.
  8. #
  9. # ::
  10. #
  11. # CURL_INCLUDE_DIRS - where to find curl/curl.h, etc.
  12. # CURL_LIBRARIES - List of libraries when using curl.
  13. # CURL_FOUND - True if curl found.
  14. # CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8)
  15. #=============================================================================
  16. # Copyright 2006-2009 Kitware, Inc.
  17. # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
  18. #
  19. # Distributed under the OSI-approved BSD License (the "License");
  20. # see accompanying file Copyright.txt for details.
  21. #
  22. # This software is distributed WITHOUT ANY WARRANTY; without even the
  23. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. # See the License for more information.
  25. #=============================================================================
  26. # (To distribute this file outside of CMake, substitute the full
  27. # License text for the above reference.)
  28. set(CURL_LIBRARY_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. find_package(PkgConfig)
  38. if(PKG_CONFIG_FOUND)
  39. pkg_search_module(CURL QUIET libcurl)
  40. endif()
  41. if(NOT CURL_FOUND)
  42. # Look for the header file.
  43. find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
  44. mark_as_advanced(CURL_INCLUDE_DIR)
  45. # Look for the library (sorted from most current/relevant entry to least).
  46. find_library(CURL_LIBRARY NAMES
  47. curl
  48. # Windows MSVC prebuilts:
  49. curllib
  50. libcurl_imp
  51. curllib_static
  52. # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip):
  53. libcurl
  54. )
  55. mark_as_advanced(CURL_LIBRARY)
  56. if(CURL_INCLUDE_DIR)
  57. foreach(_curl_version_header curlver.h curl.h)
  58. if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}")
  59. file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"")
  60. string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}")
  61. unset(curl_version_str)
  62. break()
  63. endif()
  64. endforeach()
  65. endif()
  66. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  67. FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL
  68. REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
  69. VERSION_VAR CURL_VERSION_STRING)
  70. if(CURL_FOUND)
  71. set(CURL_LIBRARIES ${CURL_LIBRARY})
  72. set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
  73. endif()
  74. endif()