aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzard <fuzzard@kodi.tv>2024-04-29 11:40:04 +1000
committerfuzzard <fuzzard@kodi.tv>2024-05-09 09:09:47 +1000
commit0b1c6b4b8e416502b85a23b7751cd97818dc5eec (patch)
tree5aa87871b570bc4d3f499cc0a4092db29e41dfb0
parente7ee85daf989c1dec524c49d16ac10254ee2820a (diff)
downloadxbmc-0b1c6b4b8e416502b85a23b7751cd97818dc5eec.tar.xz
[cmake][modules] FindNGHttp2 module
Cmake doesnt have "default" find package for nghttp2, so create one.
-rw-r--r--cmake/modules/FindNGHttp2.cmake52
1 files changed, 52 insertions, 0 deletions
diff --git a/cmake/modules/FindNGHttp2.cmake b/cmake/modules/FindNGHttp2.cmake
new file mode 100644
index 0000000000..7dba36e0ed
--- /dev/null
+++ b/cmake/modules/FindNGHttp2.cmake
@@ -0,0 +1,52 @@
+#.rst:
+# FindNGHttp2
+# ----------
+# Finds the NGHttp2 library
+#
+# This will define the following target:
+#
+# NGHttp2::NGHttp2 - The NGHttp2 library
+
+if(NOT TARGET NGHttp2::NGHttp2)
+ find_package(PkgConfig)
+ if(PKG_CONFIG_FOUND AND NOT (WIN32 OR WINDOWSSTORE))
+ pkg_check_modules(NGHTTP2 libnghttp2 QUIET)
+
+ # First item is the full path of the library file found
+ # pkg_check_modules does not populate a variable of the found library explicitly
+ list(GET NGHTTP2_LINK_LIBRARIES 0 NGHTTP2_LIBRARY)
+
+ set(NGHTTP2_INCLUDE_DIR ${NGHTTP2_INCLUDEDIR})
+ else()
+
+ find_path(NGHTTP2_INCLUDE_DIR NAMES nghttp2/nghttp2.h
+ HINTS ${DEPENDS_PATH}/include
+ ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
+ find_library(NGHTTP2_LIBRARY NAMES nghttp2 nghttp2_static
+ HINTS ${DEPENDS_PATH}/lib
+ ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
+ endif()
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(NGHttp2
+ REQUIRED_VARS NGHTTP2_LIBRARY NGHTTP2_INCLUDE_DIR
+ VERSION_VAR NGHTTP2_VERSION)
+
+ if(NGHTTP2_FOUND)
+ add_library(NGHttp2::NGHttp2 UNKNOWN IMPORTED)
+
+ set_target_properties(NGHttp2::NGHttp2 PROPERTIES
+ IMPORTED_LOCATION "${NGHTTP2_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${NGHTTP2_INCLUDE_DIR}")
+
+ # Todo: for windows, do a find_package config call to retrieve this from the cmake config
+ # For now just explicitly say its a static build
+ if(WIN32 OR WINDOWS_STORE)
+ set_property(TARGET NGHttp2::NGHttp2 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "NGHTTP2_STATICLIB")
+ endif()
+ else()
+ if(NGHttp2_FIND_REQUIRED)
+ message(FATAL_ERROR "NGHttp2 libraries were not found.")
+ endif()
+ endif()
+endif()