From 294f897ccd436618be35ade634cf1c15f4bb9e48 Mon Sep 17 00:00:00 2001 From: Kang Lin Date: Thu, 23 Nov 2023 12:34:53 +0800 Subject: [PATCH] CMake: find prometheus(fix #1304) (#1315) fix #1304 --- .github/workflows/mingw.yml | 30 ++++++++++++++ cmake/FindPrometheus.cmake | 74 +++++++++++++++++++++++++++++++++++ configure | 6 +-- docs/Prometheus.md | 53 +++++++++++++++++++++++++ src/apps/relay/CMakeLists.txt | 7 +++- 5 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 cmake/FindPrometheus.cmake create mode 100644 docs/Prometheus.md diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index 487cca86..b2264b18 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -44,6 +44,7 @@ jobs: mingw-w64-x86_64-sqlite3 ^ mingw-w64-x86_64-hiredis ^ mingw-w64-x86_64-postgresql ^ + mingw-w64-x86_64-libmicrohttpd ^ git base-devel - name: make_directory @@ -60,11 +61,40 @@ jobs: ${{env.INSTALL_DIR}} key: coturn-cache-installed-mingw + - name: build prometheus + if: false + working-directory: ${{env.SOURCE_DIR}} + env: + MSYSTEM: MINGW64 + PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin + run: | + cd ${{env.SOURCE_DIR}} + git clone https://github.com/digitalocean/prometheus-client-c.git + cd prometheus-client-c/prom + mkdir build + cd build + cmake .. -G"MinGW Makefiles" ^ + -DBUILD_SHARED_LIBS=${{matrix.BUILD_SHARED_LIBS}} ^ + -DCMAKE_BUILD_TYPE=${{matrix.BUILD_TYPE}} ^ + -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_DIR}} + cmake --build . --config ${{matrix.BUILD_TYPE}} + cmake --build . --config ${{matrix.BUILD_TYPE}} --target install + cd ${{env.SOURCE_DIR}}/prometheus-client-c/promhttp + mkdir build + cd build + cmake .. -G"MinGW Makefiles" ^ + -DBUILD_SHARED_LIBS=${{matrix.BUILD_SHARED_LIBS}} ^ + -DCMAKE_BUILD_TYPE=${{matrix.BUILD_TYPE}} ^ + -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_DIR}} + cmake --build . --config ${{matrix.BUILD_TYPE}} + cmake --build . --config ${{matrix.BUILD_TYPE}} --target install + - name: build coturn working-directory: ${{github.workspace}} env: MSYSTEM: MINGW64 PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin + Prometheus_ROOT: ${{env.INSTALL_DIR}} run: | cmake -E make_directory build cd build diff --git a/cmake/FindPrometheus.cmake b/cmake/FindPrometheus.cmake new file mode 100644 index 00000000..f99abffc --- /dev/null +++ b/cmake/FindPrometheus.cmake @@ -0,0 +1,74 @@ +# Author: Kang Lin (kl222@126.com) +# +# Find Prometheus. +# +# Set this variable to any additional path you want the module to search: +# Prometheus_DIR or Prometheus_ROOT +# +# Try to find prometheus +# Once done, this will define: +# Prometheus_FOUND - Prometheus (or all requested components of prom, promhttp, microhttpd) was found. +# Prometheus_INCLUDE_DIRS - Libevent include directories +# Prometheus_LIBRARIES - libraries needed to use Prometheus +# + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig) +pkg_check_modules(PC_prom QUIET prom) +pkg_check_modules(PC_promhttp QUIET promhttp) +pkg_check_modules(PC_microhttd QUIET microhttpd) + +find_path(microhttpd_include_dir + NAMES microhttpd.h + HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_microhttd_INCLUDE_DIRS} /usr + PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT} + PATH_SUFFIXES include + ) + +find_library( + microhttpd_libs + NAMES microhttpd + HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_microhttd_LIBRARY_DIRS} + PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT} + PATH_SUFFIXES lib ${CMAKE_INSTALL_LIBDIR}) + +find_path(prom_INCLUDE_DIR + NAMES prom.h + HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_prom_INCLUDE_DIRS} /usr + PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT} + PATH_SUFFIXES include + ) + +find_library( + prom_libs + NAMES prom + HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_prom_LIBRARY_DIRS} + PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT} + PATH_SUFFIXES lib ${CMAKE_INSTALL_LIBDIR}) + +find_path(promhttp_INCLUDE_DIR + NAMES promhttp.h + HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_promhttp_INCLUDE_DIRS} /usr + PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT} + PATH_SUFFIXES include + ) + +find_library( + promhttp_libs + NAMES promhttp + HINTS ${Prometheus_DIR} ${Prometheus_ROOT} ${PC_promhttp_LIBRARY_DIRS} + PATHS $ENV{Prometheus_DIR} $ENV{Prometheus_ROOT} + PATH_SUFFIXES lib ${CMAKE_INSTALL_LIBDIR}) + +find_package_handle_standard_args(Prometheus + REQUIRED_VARS prom_libs prom_INCLUDE_DIR + promhttp_libs promhttp_INCLUDE_DIR + microhttpd_include_dir microhttpd_libs + ) + +set(Prometheus_INCLUDE_DIRS + ${prom_INCLUDE_DIR} + ${promhttp_INCLUDE_DIR} + ${microhttpd_include_dir}) +set(Prometheus_LIBRARIES ${prom_libs} ${promhttp_libs} ${microhttpd_libs}) diff --git a/configure b/configure index fc75021d..e14f9773 100755 --- a/configure +++ b/configure @@ -864,7 +864,7 @@ if [ -z "${TURN_NO_PROMETHEUS}" ] ; then ${ECHO_CMD} ${ECHO_CMD} "Warning: microhttpd development libraries are not installed properly in required location." ${ECHO_CMD} "Prometheus support will be disabled." - ${ECHO_CMD} "See the docs/Build.md file." + ${ECHO_CMD} "See the docs/Prometheus.md file." ${ECHO_CMD} OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS" fi @@ -872,7 +872,7 @@ if [ -z "${TURN_NO_PROMETHEUS}" ] ; then ${ECHO_CMD} ${ECHO_CMD} "Warning: Libpromhttp development libraries are not installed properly in required location." ${ECHO_CMD} "Prometheus support will be disabled." - ${ECHO_CMD} "See the docs/Build.md file." + ${ECHO_CMD} "See the docs/Prometheus.md file." ${ECHO_CMD} OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS" fi @@ -880,7 +880,7 @@ if [ -z "${TURN_NO_PROMETHEUS}" ] ; then ${ECHO_CMD} ${ECHO_CMD} "Warning: Libprom development libraries are not installed properly in required location." ${ECHO_CMD} "Prometheus support will be disabled." - ${ECHO_CMD} "See the docs/Build.md file." + ${ECHO_CMD} "See the docs/Prometheus.md file." ${ECHO_CMD} OSCFLAGS="${OSCFLAGS} -DTURN_NO_PROMETHEUS" fi diff --git a/docs/Prometheus.md b/docs/Prometheus.md new file mode 100644 index 00000000..94860033 --- /dev/null +++ b/docs/Prometheus.md @@ -0,0 +1,53 @@ +# Prometheus setup + +It is need the following libraries: + +- prometheus-client-c +- libmicrohttpd + +## Ubuntu + +### Install libmicrohttpd + +``` +sudo apt install libmicrohttpd-dev +``` + +## Install From source code + +- [libmicrohttpd](https://www.gnu.org/software/libmicrohttpd/) + +Download from https://git.gnunet.org/libmicrohttpd.git + +``` +git clone https://git.gnunet.org/libmicrohttpd.git +``` + +- [prometheus-client-c](https://github.com/digitalocean/prometheus-client-c) + +Download from https://github.com/digitalocean/prometheus-client-c.git + +``` +git clone https://github.com/digitalocean/prometheus-client-c.git +``` + +## Build + +- Build libmicrohttpd from source code + +``` +git clone https://git.gnunet.org/libmicrohttpd.git +cd libmicrohttpd +./autogen.sh +./configure --prefix=`pwd`/install --disable-doc --disable-examples \ + --disable-tools +make install +``` + +- Build prometheus-client-c from source code + +``` +git clone https://github.com/digitalocean/prometheus-client-c.git +cd prometheus-client-c +make +``` diff --git a/src/apps/relay/CMakeLists.txt b/src/apps/relay/CMakeLists.txt index 95b1aec4..a6a6468f 100644 --- a/src/apps/relay/CMakeLists.txt +++ b/src/apps/relay/CMakeLists.txt @@ -115,9 +115,12 @@ endif() find_package(Prometheus) if(Prometheus_FOUND) - list(APPEND SOURCE_FILES prom_server.c) - list(APPEND HEADER_FILES prom_server.h) + list(APPEND turnserver_LIBS ${Prometheus_LIBRARIES}) + list(APPEND turnserver_include_dirs ${Prometheus_INCLUDE_DIRS}) else() + message(AUTHOR_WARNING "Don't find prometheus. please install " + "prom, promhttp, microhttpd, and set Prometheus_ROOT. " + "See docs/Prometheus.md") list(APPEND turnserver_DEFINED TURN_NO_PROMETHEUS) endif()