1
0
Эх сурвалжийг харах

CMake: find prometheus(fix #1304) (#1315)

fix #1304
Kang Lin 1 жил өмнө
parent
commit
294f897ccd

+ 30 - 0
.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

+ 74 - 0
cmake/FindPrometheus.cmake

@@ -0,0 +1,74 @@
+# Author: Kang Lin ([email protected])
+#
+# 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})

+ 3 - 3
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

+ 53 - 0
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
+```

+ 5 - 2
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()