From 5a75869d9ecd50f31adfaf1afba4ee37306fae10 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 18 Oct 2023 16:26:55 -0700 Subject: [PATCH 1/4] Add FindPrometheusCpp.cmake --- FindPrometheusCpp.cmake | 106 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 FindPrometheusCpp.cmake diff --git a/FindPrometheusCpp.cmake b/FindPrometheusCpp.cmake new file mode 100644 index 0000000..daadde7 --- /dev/null +++ b/FindPrometheusCpp.cmake @@ -0,0 +1,106 @@ +set(prometheuscpp_build "${CMAKE_CURRENT_BINARY_DIR}/prometheus-cpp-build") +set(prometheuscpp_install "${CMAKE_CURRENT_BINARY_DIR}/prometheus-cpp-build") +set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") + +set(prometheuscpp_core_lib "${prometheuscpp_build}/lib/libprometheus-cpp-core${CMAKE_STATIC_LIBRARY_SUFFIX}") +set(prometheuscpp_pull_lib "${prometheuscpp_build}/lib/libprometheus-cpp-pull${CMAKE_STATIC_LIBRARY_SUFFIX}") + +set(prometheuscpp_includes + "${prometheuscpp_src}/pull/include" + "${prometheuscpp_src}/core/include" + "${prometheuscpp_build}/pull/include" + "${prometheuscpp_build}/core/include" +) + +include(ExternalProject) + +ExternalProject_Add(project_prometheuscpp + PREFIX "${prometheuscpp_ep}" + BINARY_DIR "${prometheuscpp_build}" + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS ${prometheuscpp_core_lib} ${prometheuscpp_pull_lib} +) + +ExternalProject_Add_Step(project_prometheuscpp project_prometheuscpp_build_step + COMMAND ${CMAKE_MAKE_PROGRAM} + COMMENT "Building libprometheuscpp" + WORKING_DIRECTORY ${prometheuscpp_build} + ALWAYS 1 + USES_TERMINAL 1 +) + +if ( MSVC ) + set(OTHER_CONFIG -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}) +endif() + +if ( CMAKE_TOOLCHAIN_FILE ) + set(toolchain_arg -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) +else () + set(toolchain_arg) +endif () + +if ( CMAKE_C_COMPILER_LAUNCHER ) + set(cmake_c_compiler_launcher_arg + -DCMAKE_C_COMPILER_LAUNCHER:path=${CMAKE_C_COMPILER_LAUNCHER}) +else () + set(cmake_c_compiler_launcher_arg) +endif () + +if ( CMAKE_CXX_COMPILER_LAUNCHER ) + set(cmake_cxx_compiler_launcher_arg + -DCMAKE_CXX_COMPILER_LAUNCHER:path=${CMAKE_CXX_COMPILER_LAUNCHER}) +else () + set(cmake_cxx_compiler_launcher_arg) +endif () + +execute_process( + COMMAND + ${CMAKE_COMMAND} + -G${CMAKE_GENERATOR} + ${toolchain_arg} + ${cmake_c_compiler_launcher_arg} + ${cmake_cxx_compiler_launcher_arg} + -DCMAKE_BUILD_TYPE:string=${CMAKE_BUILD_TYPE} + -DENABLE_PUSH=OFF + -DENABLE_TESTING=OFF + -DGENERATE_PKGCONFIG=OFF + ${OTHER_CONFIG} + ${prometheuscpp_src} + WORKING_DIRECTORY ${prometheuscpp_build} + RESULT_VARIABLE prometheuscpp_cmake_result + ERROR_VARIABLE PROMETHEUSCPP_CMAKE_OUTPUT + OUTPUT_VARIABLE PROMETHEUSCPP_CMAKE_OUTPUT + ERROR_STRIP_TRAILING_WHITESPACE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +message("\n********** Begin prometheus-cpp External Project CMake Output ************") +message("\n${PROMETHEUSCPP_CMAKE_OUTPUT}") +message("\n*********** End promtheus-cpp External Project CMake Output *************") +message("\n") + +if (prometheuscpp_cmake_result) + message(FATAL_ERROR "prometheus-cpp CMake configuration failed") +endif () + +add_library(prometheuscpp_core_a STATIC IMPORTED) +set_property(TARGET prometheuscpp_core_a PROPERTY IMPORTED_LOCATION ${prometheuscpp_core_lib}) +add_dependencies(prometheuscpp_core_a project_prometheuscpp) + +add_library(prometheuscpp_pull_a STATIC IMPORTED) +set_property(TARGET prometheuscpp_pull_a PROPERTY IMPORTED_LOCATION ${prometheuscpp_pull_lib}) +add_dependencies(prometheuscpp_pull_a project_prometheuscpp) + +set(HAVE_PROMETHEUSCPP true) + +set(PROMETHEUSCPP_LIBRARIES + prometheuscpp_core_a + prometheuscpp_pull_a + CACHE STRING "prometheuscpp libs" FORCE) +set(zeekdeps ${zeekdeps} ${PROMETHEUSCPP_LIBRARIES}) + +set(PROMETHEUSCPP_INCLUDE_DIRS ${prometheuscpp_includes} CACHE INTERNAL "prometheuscpp includes" FORCE) +include_directories(BEFORE ${PROMETHEUSCPP_INCLUDE_DIRS}) From fc939385d4ccb34cd309848bc373177577fc5115 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 6 Mar 2024 09:54:23 -0700 Subject: [PATCH 2/4] Use add_subdirectory and defined targets instead of manually building --- FindPrometheusCpp.cmake | 115 +++++----------------------------------- 1 file changed, 13 insertions(+), 102 deletions(-) diff --git a/FindPrometheusCpp.cmake b/FindPrometheusCpp.cmake index daadde7..6879e9c 100644 --- a/FindPrometheusCpp.cmake +++ b/FindPrometheusCpp.cmake @@ -1,106 +1,17 @@ -set(prometheuscpp_build "${CMAKE_CURRENT_BINARY_DIR}/prometheus-cpp-build") -set(prometheuscpp_install "${CMAKE_CURRENT_BINARY_DIR}/prometheus-cpp-build") -set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") +set(prometheuscpp_build "${CMAKE_CURRENT_BINARY_DIR}/auxil/prometheus-cpp") +set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") -set(prometheuscpp_core_lib "${prometheuscpp_build}/lib/libprometheus-cpp-core${CMAKE_STATIC_LIBRARY_SUFFIX}") -set(prometheuscpp_pull_lib "${prometheuscpp_build}/lib/libprometheus-cpp-pull${CMAKE_STATIC_LIBRARY_SUFFIX}") +set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS OFF) +option(ENABLE_PUSH "" OFF) +option(ENABLE_TESTING "" OFF) +option(GENERATE_PKGCONFIG "" OFF) -set(prometheuscpp_includes - "${prometheuscpp_src}/pull/include" - "${prometheuscpp_src}/core/include" - "${prometheuscpp_build}/pull/include" - "${prometheuscpp_build}/core/include" -) +add_subdirectory(auxil/prometheus-cpp EXCLUDE_FROM_ALL) -include(ExternalProject) +set(zeekdeps ${zeekdeps} prometheus-cpp::core prometheus-cpp::pull) +include_directories(BEFORE ${prometheuscpp_src}/pull/include ${prometheuscpp_src}/core/include) +#include_directories(BEFORE ${prometheuscpp_src}/3rdparty/civetweb/include) +include_directories(BEFORE ${prometheuscpp_build}/pull/include ${prometheuscpp_build}/core/include) -ExternalProject_Add(project_prometheuscpp - PREFIX "${prometheuscpp_ep}" - BINARY_DIR "${prometheuscpp_build}" - DOWNLOAD_COMMAND "" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - BUILD_BYPRODUCTS ${prometheuscpp_core_lib} ${prometheuscpp_pull_lib} -) - -ExternalProject_Add_Step(project_prometheuscpp project_prometheuscpp_build_step - COMMAND ${CMAKE_MAKE_PROGRAM} - COMMENT "Building libprometheuscpp" - WORKING_DIRECTORY ${prometheuscpp_build} - ALWAYS 1 - USES_TERMINAL 1 -) - -if ( MSVC ) - set(OTHER_CONFIG -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}) -endif() - -if ( CMAKE_TOOLCHAIN_FILE ) - set(toolchain_arg -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) -else () - set(toolchain_arg) -endif () - -if ( CMAKE_C_COMPILER_LAUNCHER ) - set(cmake_c_compiler_launcher_arg - -DCMAKE_C_COMPILER_LAUNCHER:path=${CMAKE_C_COMPILER_LAUNCHER}) -else () - set(cmake_c_compiler_launcher_arg) -endif () - -if ( CMAKE_CXX_COMPILER_LAUNCHER ) - set(cmake_cxx_compiler_launcher_arg - -DCMAKE_CXX_COMPILER_LAUNCHER:path=${CMAKE_CXX_COMPILER_LAUNCHER}) -else () - set(cmake_cxx_compiler_launcher_arg) -endif () - -execute_process( - COMMAND - ${CMAKE_COMMAND} - -G${CMAKE_GENERATOR} - ${toolchain_arg} - ${cmake_c_compiler_launcher_arg} - ${cmake_cxx_compiler_launcher_arg} - -DCMAKE_BUILD_TYPE:string=${CMAKE_BUILD_TYPE} - -DENABLE_PUSH=OFF - -DENABLE_TESTING=OFF - -DGENERATE_PKGCONFIG=OFF - ${OTHER_CONFIG} - ${prometheuscpp_src} - WORKING_DIRECTORY ${prometheuscpp_build} - RESULT_VARIABLE prometheuscpp_cmake_result - ERROR_VARIABLE PROMETHEUSCPP_CMAKE_OUTPUT - OUTPUT_VARIABLE PROMETHEUSCPP_CMAKE_OUTPUT - ERROR_STRIP_TRAILING_WHITESPACE - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -message("\n********** Begin prometheus-cpp External Project CMake Output ************") -message("\n${PROMETHEUSCPP_CMAKE_OUTPUT}") -message("\n*********** End promtheus-cpp External Project CMake Output *************") -message("\n") - -if (prometheuscpp_cmake_result) - message(FATAL_ERROR "prometheus-cpp CMake configuration failed") -endif () - -add_library(prometheuscpp_core_a STATIC IMPORTED) -set_property(TARGET prometheuscpp_core_a PROPERTY IMPORTED_LOCATION ${prometheuscpp_core_lib}) -add_dependencies(prometheuscpp_core_a project_prometheuscpp) - -add_library(prometheuscpp_pull_a STATIC IMPORTED) -set_property(TARGET prometheuscpp_pull_a PROPERTY IMPORTED_LOCATION ${prometheuscpp_pull_lib}) -add_dependencies(prometheuscpp_pull_a project_prometheuscpp) - -set(HAVE_PROMETHEUSCPP true) - -set(PROMETHEUSCPP_LIBRARIES - prometheuscpp_core_a - prometheuscpp_pull_a - CACHE STRING "prometheuscpp libs" FORCE) -set(zeekdeps ${zeekdeps} ${PROMETHEUSCPP_LIBRARIES}) - -set(PROMETHEUSCPP_INCLUDE_DIRS ${prometheuscpp_includes} CACHE INTERNAL "prometheuscpp includes" FORCE) -include_directories(BEFORE ${PROMETHEUSCPP_INCLUDE_DIRS}) +set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS}) From 38ca8a49a5faf12554329da0e0da0e59fa0bd39d Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 14 Mar 2024 15:58:22 -0700 Subject: [PATCH 3/4] Prevent prometheus-cpp from passing -DDEBUG down to the civetweb build --- FindPrometheusCpp.cmake | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/FindPrometheusCpp.cmake b/FindPrometheusCpp.cmake index 6879e9c..c499f72 100644 --- a/FindPrometheusCpp.cmake +++ b/FindPrometheusCpp.cmake @@ -1,17 +1,33 @@ set(prometheuscpp_build "${CMAKE_CURRENT_BINARY_DIR}/auxil/prometheus-cpp") set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") -set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +# Reset this to prevent Prometheus from using the internal zeek value and thus building +# shared libraries instead of static ones. +set(_sharedlibs ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS OFF) + +# These need to be reset before setting up Prometheus because otherwise it picks up +# the -DDEBUG from SetDefaultCompileFlags and causes civetweb to output a bunch of +# debugging information. Let the library figure out its own flags. +set(_cxxflags ${CMAKE_CXX_FLAGS}) +set(CMAKE_CXX_FLAGS "") +set(_cflags ${CMAKE_C_FLAGS}) +set(CMAKE_C_FLAGS "") + option(ENABLE_PUSH "" OFF) option(ENABLE_TESTING "" OFF) option(GENERATE_PKGCONFIG "" OFF) +option(CIVETWEB_ENABLE_DEBUG_TOOLS "" OFF) +message("\n==================| prometheus-cpp Config Summary |====================\n") add_subdirectory(auxil/prometheus-cpp EXCLUDE_FROM_ALL) +message("=========================================================================\n ") set(zeekdeps ${zeekdeps} prometheus-cpp::core prometheus-cpp::pull) include_directories(BEFORE ${prometheuscpp_src}/pull/include ${prometheuscpp_src}/core/include) #include_directories(BEFORE ${prometheuscpp_src}/3rdparty/civetweb/include) include_directories(BEFORE ${prometheuscpp_build}/pull/include ${prometheuscpp_build}/core/include) -set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS ${_sharedlibs}) +set(CMAKE_CXX_FLAGS ${_cxxflags}) +set(CMAKE_C_FLAGS ${_cflags}) From 34cf738d60a95d5ecf001de2c6e259578be4fc56 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 25 Apr 2024 13:19:48 -0700 Subject: [PATCH 4/4] FindPrometheusCpp: fix cmake-format --- FindPrometheusCpp.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FindPrometheusCpp.cmake b/FindPrometheusCpp.cmake index c499f72..0072ed1 100644 --- a/FindPrometheusCpp.cmake +++ b/FindPrometheusCpp.cmake @@ -1,5 +1,5 @@ set(prometheuscpp_build "${CMAKE_CURRENT_BINARY_DIR}/auxil/prometheus-cpp") -set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") +set(prometheuscpp_src "${CMAKE_CURRENT_SOURCE_DIR}/auxil/prometheus-cpp") # Reset this to prevent Prometheus from using the internal zeek value and thus building # shared libraries instead of static ones.