diff --git a/.github/workflows/cmake-ci.yml b/.github/workflows/cmake-ci.yml index f30e4c5b..7a63338a 100644 --- a/.github/workflows/cmake-ci.yml +++ b/.github/workflows/cmake-ci.yml @@ -9,32 +9,27 @@ on: jobs: build: - name: CMake on ${{ matrix.os }} with ${{ matrix.dependencies }} + name: CMake on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [macos-14, ubuntu-22.04, windows-2022] - dependencies: [submodule, vcpkg] steps: - name: Checkout source uses: actions/checkout@v7 - with: - submodules: ${{ matrix.dependencies == 'submodule' }} - name: Mount vcpkg cache - if: matrix.dependencies == 'vcpkg' uses: actions/cache@v5 with: path: "~/.cache/vcpkg/archives" key: vcpkg-${{ matrix.os }} - name: Default to x64-windows vcpkg triplet - if: matrix.dependencies == 'vcpkg' && runner.os == 'Windows' + if: runner.os == 'Windows' run: echo "VCPKG_DEFAULT_TRIPLET=x64-windows" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append - name: Install vcpkg dependencies - if: matrix.dependencies == 'vcpkg' run: vcpkg install benchmark civetweb curl[core] gtest zlib - name: Generate German locale on Ubuntu @@ -54,20 +49,12 @@ jobs: if: runner.os == 'macOS' run: brew install ninja - - name: "Configure for Unix with internal dependencies" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' - run: cmake -DUSE_THIRDPARTY_LIBRARIES=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }} -B ${{ github.workspace }}/_build -DBUILD_SHARED_LIBS=ON - - - name: "Configure for Windows with internal dependencies" - if: matrix.dependencies == 'submodule' && runner.os == 'Windows' - run: cmake -DUSE_THIRDPARTY_LIBRARIES=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -S ${{ github.workspace }} -B ${{ github.workspace }}/_build -DBUILD_SHARED_LIBS=ON - - name: "Configure for Unix with vcpkg dependencies" - if: matrix.dependencies == 'vcpkg' && runner.os != 'Windows' + if: runner.os != 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_DEBUG_POSTFIX=_d -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: "Configure for Windows with vcpkg dependencies" - if: matrix.dependencies == 'vcpkg' && runner.os == 'Windows' + if: runner.os == 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install "-DCMAKE_TOOLCHAIN_FILE=${Env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" -DCMAKE_DEBUG_POSTFIX=_d -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: "Build Debug" @@ -94,20 +81,12 @@ jobs: - name: "Install Release" run: cmake --install ${{ github.workspace }}/_build --config Release - - name: "Configure CMake import for Unix with internal dependencies" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' - run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - - - name: "Configure CMake import for Windows with internal dependencies" - if: matrix.dependencies == 'submodule' && runner.os == 'Windows' - run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - - name: "Configure CMake import for Unix with vcpkg dependencies" - if: matrix.dependencies == 'vcpkg' && runner.os != 'Windows' + if: runner.os != 'Windows' run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - name: "Configure CMake import for Windows with vcpkg dependencies" - if: matrix.dependencies == 'vcpkg' && runner.os == 'Windows' + if: runner.os == 'Windows' run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp "-DCMAKE_TOOLCHAIN_FILE=${Env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - name: "Build CMake import Debug" @@ -117,21 +96,21 @@ jobs: run: cmake --build ${{ github.workspace }}/_import_cmake --config Release - name: "Configure for Unix Shared Libs with internal dependencies" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' - run: cmake -DUSE_THIRDPARTY_LIBRARIES=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install_shared -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -GNinja -S ${{ github.workspace }} -B ${{ github.workspace }}/_build_shared + if: runner.os != 'Windows' + run: cmake "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install_shared -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -GNinja -S ${{ github.workspace }} -B ${{ github.workspace }}/_build_shared - name: "Build for Unix Shared Libs" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' + if: runner.os != 'Windows' run: cmake --build ${{ github.workspace }}/_build_shared - name: "Install for Unix Shared Libs" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' + if: runner.os != 'Windows' run: cmake --install ${{ github.workspace }}/_build_shared - name: "Configure pkg-config import for Unix" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' - run: cmake -DCMAKE_PREFIX_PATH=${{ github.workspace }}/_install_shared -GNinja -S ${{ github.workspace }}/cmake/project-import-pkgconfig -B ${{ github.workspace }}/_import_pkgconfig + if: runner.os != 'Windows' + run: cmake "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_PREFIX_PATH=${{ github.workspace }}/_install_shared -GNinja -S ${{ github.workspace }}/cmake/project-import-pkgconfig -B ${{ github.workspace }}/_import_pkgconfig - name: "Build pkg-config import for Unix" - if: matrix.dependencies == 'submodule' && runner.os != 'Windows' + if: runner.os != 'Windows' run: cmake --build ${{ github.workspace }}/_import_pkgconfig diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 9e4329cb..e57acc60 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -17,12 +17,10 @@ jobs: - name: Install dependencies run: | apt-get update - apt-get install -y --no-install-recommends ca-certificates clang-19 cmake git iwyu libbenchmark-dev libcurl4-openssl-dev ninja-build zlib1g-dev + apt-get install -y --no-install-recommends ca-certificates clang-19 cmake git iwyu libbenchmark-dev libcivetweb-dev libcurl4-openssl-dev ninja-build zlib1g-dev - name: Checkout source uses: actions/checkout@v7 - with: - submodules: true - name: "CMake Configure" run: cmake -GNinja -DRUN_IWYU=ON -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -S ${GITHUB_WORKSPACE} -B ${GITHUB_WORKSPACE}/_build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 351428a1..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,27 +0,0 @@ -on: - release: - types: [created] - -name: Handle Release - -jobs: - build: - name: Upload Release Asset - runs-on: ubuntu-slim - steps: - - name: Checkout code - uses: actions/checkout@v7 - with: - persist-credentials: false - submodules: true - - - name: Create tarball including submodules - shell: bash - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PREFIX: prometheus-cpp-with-submodules - run: | - git archive --prefix "${PREFIX}/" -o "${PREFIX}.tar" HEAD - git submodule foreach --recursive "git archive --prefix=${PREFIX}/\$path/ --output=\$sha1.tar HEAD && tar --concatenate --file=$(pwd)/${PREFIX}.tar \$sha1.tar && rm \$sha1.tar" - gzip "${PREFIX}.tar" - gh release upload ${{ github.event.release.tag_name }} "${PREFIX}.tar.gz" diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ccfd018a..00000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "googletest"] - path = 3rdparty/googletest - url = https://github.com/google/googletest.git -[submodule "civetweb"] - path = 3rdparty/civetweb - url = https://github.com/civetweb/civetweb.git diff --git a/3rdparty/civetweb b/3rdparty/civetweb deleted file mode 160000 index d7ba35bb..00000000 --- a/3rdparty/civetweb +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d7ba35bbb649209c66e582d5a0244ba988a15159 diff --git a/3rdparty/googletest b/3rdparty/googletest deleted file mode 160000 index 063de7e9..00000000 --- a/3rdparty/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 063de7e9578f82b369302001269680b4b1553359 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5700b7d3..d676e21c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,6 @@ option(ENABLE_PULL "Build prometheus-cpp pull library" ON) option(ENABLE_PUSH "Build prometheus-cpp push library" ON) option(ENABLE_COMPRESSION "Enable gzip compression" ON) option(ENABLE_TESTING "Build tests" ON) -option(USE_THIRDPARTY_LIBRARIES "Use 3rdParty submodules" ON) -option(THIRDPARTY_CIVETWEB_WITH_SSL "Enable SSL support for embedded civetweb source code") option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++17 even if the CXXFLAGS are configured differently" ON) option(GENERATE_PKGCONFIG "Generate and install pkg-config files" ${UNIX}) option(RUN_IWYU "Run include-what-you-use" OFF) @@ -82,11 +80,7 @@ endif() include(CheckAtomic) if(ENABLE_TESTING) - if(USE_THIRDPARTY_LIBRARIES) - find_package(googlemock-3rdparty CONFIG REQUIRED) - else() - find_package(GTest 1.8.1 CONFIG REQUIRED) - endif() + find_package(GTest 1.8.1 CONFIG REQUIRED) find_package(benchmark CONFIG) enable_testing() endif() diff --git a/README.md b/README.md index 04c03e23..740220cd 100644 --- a/README.md +++ b/README.md @@ -105,17 +105,21 @@ the [GitHub Workflows](.github/workflows) might help. ### With CMake -For CMake builds don't forget to fetch the submodules first. Please note that -[zlib](https://zlib.net/) and [libcurl](https://curl.se/) are not provided by -the included submodules. In the example below their usage is disabled. +`prometheus-cpp` does not vendor its dependencies. It expects the following +libraries to already be installed and discoverable via `find_package()`: -Then build as usual. +- [civetweb](https://github.com/civetweb/civetweb) +- [googletest](https://github.com/google/googletest) (optional, needed for `ENABLE_TESTING`) +- [benchmark](https://github.com/google/benchmark) (optional, needed for benchmarks) +- [zlib](https://zlib.net/) (optional, needed for `ENABLE_COMPRESSION`) +- [libcurl](https://curl.se/) (optional, needed for `ENABLE_PUSH`) -``` shell -# fetch third-party dependencies -git submodule init -git submodule update +Use whichever package manager you prefer to provide them, e.g. +[vcpkg](#vcpkg), [Conan](#conan), your system's package manager, or a +manually installed copy. In the example below push support and compression +are disabled to keep the dependency list minimal. +``` shell mkdir _build cd _build @@ -155,9 +159,6 @@ configuration options. To generate a Debian package you could follow these steps: ``` shell -# fetch third-party dependencies -git submodule update --init - # run cmake cmake -B_build -DCPACK_GENERATOR=DEB -DBUILD_SHARED_LIBS=ON # or OFF for static libraries diff --git a/cmake/civetweb-3rdparty-config.cmake b/cmake/civetweb-3rdparty-config.cmake deleted file mode 100644 index 8cc73cf9..00000000 --- a/cmake/civetweb-3rdparty-config.cmake +++ /dev/null @@ -1,73 +0,0 @@ -get_filename_component(_IMPORT_PREFIX "${PROJECT_SOURCE_DIR}/3rdparty/civetweb/" ABSOLUTE) - -macro(set_and_check _var _file) - set(${_var} "${_file}") - if(NOT EXISTS "${_file}") - message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") - endif() -endmacro() - -set_and_check(CIVETWEB_INCLUDE_DIR ${_IMPORT_PREFIX}/include) -set(CIVETWEB_INCLUDE_DIRS "${CIVETWEB_INCLUDE_DIR}") - -add_library(civetweb OBJECT - ${_IMPORT_PREFIX}/include/CivetServer.h - ${_IMPORT_PREFIX}/include/civetweb.h - ${_IMPORT_PREFIX}/src/CivetServer.cpp - ${_IMPORT_PREFIX}/src/civetweb.c - ${_IMPORT_PREFIX}/src/handle_form.inl - ${_IMPORT_PREFIX}/src/md5.inl -) - -set_property(TARGET civetweb PROPERTY PUBLIC_HEADER - ${_IMPORT_PREFIX}/include/CivetServer.h - ${_IMPORT_PREFIX}/include/civetweb.h -) - -target_compile_definitions(civetweb - PRIVATE - CIVETWEB_API= - USE_IPV6 - NDEBUG - NO_CGI - NO_CACHING - NO_FILES - SOCKET_TIMEOUT_QUANTUM=200 -) - -target_compile_options(civetweb - PRIVATE - $<$:-w> - $<$:-w> -) - -target_include_directories(civetweb - PRIVATE - ${CIVETWEB_INCLUDE_DIRS} -) - -if(THIRDPARTY_CIVETWEB_WITH_SSL) - include(CMakeFindDependencyMacro) - find_dependency(OpenSSL) - if(OPENSSL_VERSION VERSION_GREATER_EQUAL 1.1) - target_compile_definitions(civetweb PRIVATE OPENSSL_API_1_1) - endif() - target_compile_definitions(civetweb PRIVATE NO_SSL_DL) - target_link_libraries(civetweb PUBLIC OpenSSL::SSL) -else() - target_compile_definitions(civetweb PRIVATE NO_SSL) -endif() - -if(BUILD_SHARED_LIBS) - set_target_properties(civetweb PROPERTIES - POSITION_INDEPENDENT_CODE ON - C_VISIBILITY_PRESET hidden - CXX_VISIBILITY_PRESET hidden - VISIBILITY_INLINES_HIDDEN ON - ) -endif() - -set_target_properties(civetweb PROPERTIES - C_INCLUDE_WHAT_YOU_USE "" - CXX_INCLUDE_WHAT_YOU_USE "" -) diff --git a/cmake/googlemock-3rdparty-config.cmake b/cmake/googlemock-3rdparty-config.cmake deleted file mode 100644 index 66defd2f..00000000 --- a/cmake/googlemock-3rdparty-config.cmake +++ /dev/null @@ -1,29 +0,0 @@ -get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../3rdparty/googletest/" ABSOLUTE) - -find_package(Threads QUIET) - -add_library(gmock_main STATIC EXCLUDE_FROM_ALL - ${_IMPORT_PREFIX}/googletest/src/gtest-all.cc - ${_IMPORT_PREFIX}/googlemock/src/gmock-all.cc - ${_IMPORT_PREFIX}/googlemock/src/gmock_main.cc -) - -target_include_directories(gmock_main SYSTEM - PUBLIC - ${_IMPORT_PREFIX}/googletest/include - ${_IMPORT_PREFIX}/googlemock/include - PRIVATE - ${_IMPORT_PREFIX}/googletest - ${_IMPORT_PREFIX}/googlemock -) - -target_link_libraries(gmock_main - PRIVATE - Threads::Threads -) -add_library(GTest::gmock_main ALIAS gmock_main) - -set_target_properties(gmock_main PROPERTIES - C_INCLUDE_WHAT_YOU_USE "" - CXX_INCLUDE_WHAT_YOU_USE "" -) diff --git a/cmake/prometheus-cpp-config.cmake.in b/cmake/prometheus-cpp-config.cmake.in index fe9606e0..b82a3184 100644 --- a/cmake/prometheus-cpp-config.cmake.in +++ b/cmake/prometheus-cpp-config.cmake.in @@ -6,21 +6,13 @@ set_and_check(prometheus-cpp_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") set(PROMETHEUS_CPP_ENABLE_PULL @ENABLE_PULL@) set(PROMETHEUS_CPP_ENABLE_PUSH @ENABLE_PUSH@) set(PROMETHEUS_CPP_USE_COMPRESSION @ENABLE_COMPRESSION@) -set(PROMETHEUS_CPP_USE_THIRDPARTY_LIBRARIES @USE_THIRDPARTY_LIBRARIES@) -set(PROMETHEUS_CPP_THIRDPARTY_CIVETWEB_WITH_SSL @THIRDPARTY_CIVETWEB_WITH_SSL@) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_dependency(Threads) unset(CMAKE_THREAD_PREFER_PTHREAD) if(PROMETHEUS_CPP_ENABLE_PULL) - if(PROMETHEUS_CPP_USE_THIRDPARTY_LIBRARIES) - if(PROMETHEUS_CPP_THIRDPARTY_CIVETWEB_WITH_SSL) - find_dependency(OpenSSL) - endif() - else() - find_dependency(civetweb) - endif() + find_dependency(civetweb) endif() if(PROMETHEUS_CPP_ENABLE_PULL AND PROMETHEUS_CPP_USE_COMPRESSION) diff --git a/pull/CMakeLists.txt b/pull/CMakeLists.txt index a35446d0..f13cf799 100644 --- a/pull/CMakeLists.txt +++ b/pull/CMakeLists.txt @@ -1,20 +1,9 @@ -if(USE_THIRDPARTY_LIBRARIES) - find_package(civetweb-3rdparty CONFIG REQUIRED) - add_library(${PROJECT_NAME}::civetweb ALIAS civetweb) - install( - TARGETS civetweb - EXPORT ${PROJECT_NAME}-targets - # keep embedded civetweb headers scoped to prometheus(-cpp) - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/prometheus - ) -else() - find_package(civetweb CONFIG REQUIRED) +find_package(civetweb CONFIG REQUIRED) - # work-around https://github.com/civetweb/civetweb/pull/918 - if(WIN32 AND NOT TARGET WINSOCK::WINSOCK) - add_library(WINSOCK::WINSOCK INTERFACE IMPORTED) - target_link_libraries(WINSOCK::WINSOCK INTERFACE ws2_32) - endif() +# work-around https://github.com/civetweb/civetweb/pull/918 +if(WIN32 AND NOT TARGET WINSOCK::WINSOCK) + add_library(WINSOCK::WINSOCK INTERFACE IMPORTED) + target_link_libraries(WINSOCK::WINSOCK INTERFACE ws2_32) endif() if(ENABLE_COMPRESSION) @@ -46,7 +35,7 @@ target_link_libraries(pull PRIVATE ${PROJECT_NAME}::util Threads::Threads - $,${PROJECT_NAME}::civetweb,civetweb::civetweb-cpp> + civetweb::civetweb-cpp $<$,$>>:rt> $<$:ZLIB::ZLIB> ) @@ -95,9 +84,7 @@ if(GENERATE_PKGCONFIG) set(PKGCONFIG_LIBS) set(PKGCONFIG_REQUIRES) - if(NOT USE_THIRDPARTY_LIBRARIES) - string(APPEND PKGCONFIG_LIBS " -lcivetweb-cpp -lcivetweb") - endif() + string(APPEND PKGCONFIG_LIBS " -lcivetweb-cpp -lcivetweb") if(ENABLE_COMPRESSION) string(APPEND PKGCONFIG_REQUIRES " zlib")