httplibConfig.cmake.in 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Generates a macro to auto-configure everything
  2. @PACKAGE_INIT@
  3. # Setting these here so they're accessible after install.
  4. # Might be useful for some users to check which settings were used.
  5. set(HTTPLIB_IS_USING_OPENSSL @HTTPLIB_IS_USING_OPENSSL@)
  6. set(HTTPLIB_IS_USING_ZLIB @HTTPLIB_IS_USING_ZLIB@)
  7. set(HTTPLIB_IS_COMPILED @HTTPLIB_COMPILE@)
  8. set(HTTPLIB_IS_USING_BROTLI @HTTPLIB_IS_USING_BROTLI@)
  9. set(HTTPLIB_IS_USING_NON_BLOCKING_GETADDRINFO @HTTPLIB_IS_USING_NON_BLOCKING_GETADDRINFO@)
  10. set(HTTPLIB_VERSION @PROJECT_VERSION@)
  11. include(CMakeFindDependencyMacro)
  12. # We add find_dependency calls here to not make the end-user have to call them.
  13. find_dependency(Threads)
  14. if(@HTTPLIB_IS_USING_OPENSSL@)
  15. # OpenSSL COMPONENTS were added in Cmake v3.11
  16. if(CMAKE_VERSION VERSION_LESS "3.11")
  17. find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@)
  18. else()
  19. # Once the COMPONENTS were added, they were made optional when not specified.
  20. # Since we use both, we need to search for both.
  21. find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ COMPONENTS Crypto SSL)
  22. endif()
  23. set(httplib_OpenSSL_FOUND ${OpenSSL_FOUND})
  24. endif()
  25. if(@HTTPLIB_IS_USING_ZLIB@)
  26. find_dependency(ZLIB)
  27. set(httplib_ZLIB_FOUND ${ZLIB_FOUND})
  28. endif()
  29. if(@HTTPLIB_IS_USING_BROTLI@)
  30. # Needed so we can use our own FindBrotli.cmake in this file.
  31. # Note that the FindBrotli.cmake file is installed in the same dir as this file.
  32. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
  33. set(BROTLI_USE_STATIC_LIBS @BROTLI_USE_STATIC_LIBS@)
  34. find_dependency(Brotli COMPONENTS common encoder decoder)
  35. set(httplib_Brotli_FOUND ${Brotli_FOUND})
  36. endif()
  37. if(@HTTPLIB_IS_USING_ZSTD@)
  38. set(httplib_fd_zstd_quiet_arg)
  39. if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
  40. set(httplib_fd_zstd_quiet_arg QUIET)
  41. endif()
  42. set(httplib_fd_zstd_required_arg)
  43. if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
  44. set(httplib_fd_zstd_required_arg REQUIRED)
  45. endif()
  46. find_package(zstd QUIET)
  47. if(NOT zstd_FOUND)
  48. find_package(PkgConfig ${httplib_fd_zstd_quiet_arg} ${httplib_fd_zstd_required_arg})
  49. if(PKG_CONFIG_FOUND)
  50. pkg_check_modules(zstd ${httplib_fd_zstd_quiet_arg} ${httplib_fd_zstd_required_arg} IMPORTED_TARGET libzstd)
  51. if(TARGET PkgConfig::zstd)
  52. add_library(zstd::libzstd ALIAS PkgConfig::zstd)
  53. endif()
  54. endif()
  55. endif()
  56. set(httplib_zstd_FOUND ${zstd_FOUND})
  57. endif()
  58. # Mildly useful for end-users
  59. # Not really recommended to be used though
  60. set_and_check(HTTPLIB_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
  61. # Lets the end-user find the header path with the header appended
  62. # This is helpful if you're using Cmake's pre-compiled header feature
  63. set_and_check(HTTPLIB_HEADER_PATH "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/httplib.h")
  64. check_required_components(httplib)
  65. # Brings in the target library, but only if all required components are found
  66. if(NOT DEFINED httplib_FOUND OR httplib_FOUND)
  67. include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
  68. endif()
  69. # Outputs a "found httplib /usr/include/httplib.h" message when using find_package(httplib)
  70. include(FindPackageMessage)
  71. if(TARGET httplib::httplib)
  72. set(HTTPLIB_FOUND TRUE)
  73. # Since the compiled version has a lib, show that in the message
  74. if(@HTTPLIB_COMPILE@)
  75. # The list of configurations is most likely just 1 unless they installed a debug & release
  76. get_target_property(_httplib_configs httplib::httplib "IMPORTED_CONFIGURATIONS")
  77. # Need to loop since the "IMPORTED_LOCATION" property isn't want we want.
  78. # Instead, we need to find the IMPORTED_LOCATION_RELEASE or IMPORTED_LOCATION_DEBUG which has the lib path.
  79. foreach(_httplib_conf "${_httplib_configs}")
  80. # Grab the path to the lib and sets it to HTTPLIB_LIBRARY
  81. get_target_property(HTTPLIB_LIBRARY httplib::httplib "IMPORTED_LOCATION_${_httplib_conf}")
  82. # Check if we found it
  83. if(HTTPLIB_LIBRARY)
  84. break()
  85. endif()
  86. endforeach()
  87. unset(_httplib_configs)
  88. unset(_httplib_conf)
  89. find_package_message(httplib "Found httplib: ${HTTPLIB_LIBRARY} (found version \"${HTTPLIB_VERSION}\")" "[${HTTPLIB_LIBRARY}][${HTTPLIB_HEADER_PATH}]")
  90. else()
  91. find_package_message(httplib "Found httplib: ${HTTPLIB_HEADER_PATH} (found version \"${HTTPLIB_VERSION}\")" "[${HTTPLIB_HEADER_PATH}]")
  92. endif()
  93. endif()