diff --git a/CMakeLists.txt b/CMakeLists.txt index 94dc1e12..f6adff54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(prometheus-cpp) +include(GenerateExportHeader) include(GNUInstallDirs) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -47,6 +48,10 @@ if(ENABLE_WARNINGS_AS_ERRORS) ) endif() +# Hide things by default +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) + # prometheus-cpp add_subdirectory(core) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 219cc82c..9020c461 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -19,6 +19,11 @@ add_library(core add_library(${PROJECT_NAME}::core ALIAS core) +generate_export_header(core + EXPORT_FILE_NAME include/prometheus/core_export.h + PREFIX_NAME PROMETHEUS_CPP_ +) + target_link_libraries(core PRIVATE Threads::Threads @@ -28,6 +33,7 @@ target_link_libraries(core target_include_directories(core PUBLIC $ + $ ) set_target_properties(core PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-core) diff --git a/core/include/prometheus/check_names.h b/core/include/prometheus/check_names.h index 91acf239..5798dab7 100644 --- a/core/include/prometheus/check_names.h +++ b/core/include/prometheus/check_names.h @@ -2,8 +2,10 @@ #include +#include "prometheus/core_export.h" + namespace prometheus { -bool CheckMetricName(const std::string& name); -bool CheckLabelName(const std::string& name); +PROMETHEUS_CPP_CORE_EXPORT bool CheckMetricName(const std::string& name); +PROMETHEUS_CPP_CORE_EXPORT bool CheckLabelName(const std::string& name); } // namespace prometheus diff --git a/core/include/prometheus/client_metric.h b/core/include/prometheus/client_metric.h index 4f04281a..8f67c433 100644 --- a/core/include/prometheus/client_metric.h +++ b/core/include/prometheus/client_metric.h @@ -5,9 +5,11 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { -struct ClientMetric { +struct PROMETHEUS_CPP_CORE_EXPORT ClientMetric { // Label struct Label { diff --git a/core/include/prometheus/collectable.h b/core/include/prometheus/collectable.h index 97ce02ab..d463ab39 100644 --- a/core/include/prometheus/collectable.h +++ b/core/include/prometheus/collectable.h @@ -2,6 +2,8 @@ #include +#include "prometheus/core_export.h" + namespace prometheus { struct MetricFamily; } @@ -12,7 +14,7 @@ namespace prometheus { /// collect metrics. /// /// A Collectable has to be registered for collection. See Registry. -class Collectable { +class PROMETHEUS_CPP_CORE_EXPORT Collectable { public: virtual ~Collectable() = default; diff --git a/core/include/prometheus/counter.h b/core/include/prometheus/counter.h index 3faf693c..c4a55b84 100644 --- a/core/include/prometheus/counter.h +++ b/core/include/prometheus/counter.h @@ -1,6 +1,7 @@ #pragma once #include "prometheus/client_metric.h" +#include "prometheus/core_export.h" #include "prometheus/detail/counter_builder.h" #include "prometheus/gauge.h" #include "prometheus/metric_type.h" @@ -22,7 +23,7 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. -class Counter { +class PROMETHEUS_CPP_CORE_EXPORT Counter { public: static const MetricType metric_type{MetricType::Counter}; @@ -76,6 +77,6 @@ class Counter { /// /// To finish the configuration of the Counter metric, register it with /// Register(Registry&). -detail::CounterBuilder BuildCounter(); +PROMETHEUS_CPP_CORE_EXPORT detail::CounterBuilder BuildCounter(); } // namespace prometheus diff --git a/core/include/prometheus/detail/ckms_quantiles.h b/core/include/prometheus/detail/ckms_quantiles.h index 2fe6fe22..556692dc 100644 --- a/core/include/prometheus/detail/ckms_quantiles.h +++ b/core/include/prometheus/detail/ckms_quantiles.h @@ -5,10 +5,12 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { namespace detail { -class CKMSQuantiles { +class PROMETHEUS_CPP_CORE_EXPORT CKMSQuantiles { public: struct Quantile { const double quantile; diff --git a/core/include/prometheus/detail/counter_builder.h b/core/include/prometheus/detail/counter_builder.h index 5967a7c5..2aa12c16 100644 --- a/core/include/prometheus/detail/counter_builder.h +++ b/core/include/prometheus/detail/counter_builder.h @@ -3,6 +3,8 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { template @@ -12,7 +14,7 @@ class Registry; namespace detail { -class CounterBuilder { +class PROMETHEUS_CPP_CORE_EXPORT CounterBuilder { public: CounterBuilder& Labels(const std::map& labels); CounterBuilder& Name(const std::string&); diff --git a/core/include/prometheus/detail/gauge_builder.h b/core/include/prometheus/detail/gauge_builder.h index 2778ff85..aa62d4af 100644 --- a/core/include/prometheus/detail/gauge_builder.h +++ b/core/include/prometheus/detail/gauge_builder.h @@ -3,6 +3,8 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { template @@ -12,7 +14,7 @@ class Registry; namespace detail { -class GaugeBuilder { +class PROMETHEUS_CPP_CORE_EXPORT GaugeBuilder { public: GaugeBuilder& Labels(const std::map& labels); GaugeBuilder& Name(const std::string&); diff --git a/core/include/prometheus/detail/histogram_builder.h b/core/include/prometheus/detail/histogram_builder.h index c2d9a1e4..c1229dee 100644 --- a/core/include/prometheus/detail/histogram_builder.h +++ b/core/include/prometheus/detail/histogram_builder.h @@ -3,6 +3,8 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { template @@ -12,7 +14,7 @@ class Registry; namespace detail { -class HistogramBuilder { +class PROMETHEUS_CPP_CORE_EXPORT HistogramBuilder { public: HistogramBuilder& Labels(const std::map& labels); HistogramBuilder& Name(const std::string&); diff --git a/core/include/prometheus/detail/summary_builder.h b/core/include/prometheus/detail/summary_builder.h index 1b8efa32..a6f69fa5 100644 --- a/core/include/prometheus/detail/summary_builder.h +++ b/core/include/prometheus/detail/summary_builder.h @@ -3,6 +3,8 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { template @@ -12,7 +14,7 @@ class Registry; namespace detail { -class SummaryBuilder { +class PROMETHEUS_CPP_CORE_EXPORT SummaryBuilder { public: SummaryBuilder& Labels(const std::map& labels); SummaryBuilder& Name(const std::string&); diff --git a/core/include/prometheus/detail/time_window_quantiles.h b/core/include/prometheus/detail/time_window_quantiles.h index aeb42eeb..00a518d5 100644 --- a/core/include/prometheus/detail/time_window_quantiles.h +++ b/core/include/prometheus/detail/time_window_quantiles.h @@ -4,12 +4,13 @@ #include #include +#include "prometheus/core_export.h" #include "prometheus/detail/ckms_quantiles.h" namespace prometheus { namespace detail { -class TimeWindowQuantiles { +class PROMETHEUS_CPP_CORE_EXPORT TimeWindowQuantiles { using Clock = std::chrono::steady_clock; public: diff --git a/core/include/prometheus/detail/utils.h b/core/include/prometheus/detail/utils.h index 503c1b20..be21d2cd 100644 --- a/core/include/prometheus/detail/utils.h +++ b/core/include/prometheus/detail/utils.h @@ -4,6 +4,8 @@ #include #include +#include "prometheus/core_export.h" + namespace prometheus { namespace detail { @@ -13,7 +15,7 @@ namespace detail { /// \param labels The map that will be computed the hash value. /// /// \returns The hash value of the given labels. -std::size_t hash_labels(const std::map& labels); +PROMETHEUS_CPP_CORE_EXPORT std::size_t hash_labels(const std::map& labels); } // namespace detail diff --git a/core/include/prometheus/family.h b/core/include/prometheus/family.h index bb4a9500..63dd85d4 100644 --- a/core/include/prometheus/family.h +++ b/core/include/prometheus/family.h @@ -15,6 +15,7 @@ #include "prometheus/check_names.h" #include "prometheus/client_metric.h" #include "prometheus/collectable.h" +#include "prometheus/core_export.h" #include "prometheus/detail/future_std.h" #include "prometheus/detail/utils.h" #include "prometheus/metric_family.h" @@ -58,7 +59,7 @@ namespace prometheus { /// /// \tparam T One of the metric types Counter, Gauge, Histogram or Summary. template -class Family : public Collectable { +class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable { public: /// \brief Create a new metric. /// diff --git a/core/include/prometheus/gauge.h b/core/include/prometheus/gauge.h index 8184aa67..9b394c70 100644 --- a/core/include/prometheus/gauge.h +++ b/core/include/prometheus/gauge.h @@ -3,6 +3,7 @@ #include #include "prometheus/client_metric.h" +#include "prometheus/core_export.h" #include "prometheus/detail/gauge_builder.h" #include "prometheus/metric_type.h" @@ -20,7 +21,7 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. -class Gauge { +class PROMETHEUS_CPP_CORE_EXPORT Gauge { public: static const MetricType metric_type{MetricType::Gauge}; @@ -88,6 +89,6 @@ class Gauge { /// /// To finish the configuration of the Gauge metric register it with /// Register(Registry&). -detail::GaugeBuilder BuildGauge(); +PROMETHEUS_CPP_CORE_EXPORT detail::GaugeBuilder BuildGauge(); } // namespace prometheus diff --git a/core/include/prometheus/histogram.h b/core/include/prometheus/histogram.h index a7078747..4b8f9251 100644 --- a/core/include/prometheus/histogram.h +++ b/core/include/prometheus/histogram.h @@ -3,6 +3,7 @@ #include #include "prometheus/client_metric.h" +#include "prometheus/core_export.h" #include "prometheus/counter.h" #include "prometheus/detail/histogram_builder.h" #include "prometheus/metric_type.h" @@ -25,7 +26,7 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. -class Histogram { +class PROMETHEUS_CPP_CORE_EXPORT Histogram { public: using BucketBoundaries = std::vector; @@ -89,6 +90,6 @@ class Histogram { /// /// To finish the configuration of the Histogram metric register it with /// Register(Registry&). -detail::HistogramBuilder BuildHistogram(); +PROMETHEUS_CPP_CORE_EXPORT detail::HistogramBuilder BuildHistogram(); } // namespace prometheus diff --git a/core/include/prometheus/metric_family.h b/core/include/prometheus/metric_family.h index da913a45..d9d4bf40 100644 --- a/core/include/prometheus/metric_family.h +++ b/core/include/prometheus/metric_family.h @@ -4,11 +4,12 @@ #include #include "prometheus/client_metric.h" +#include "prometheus/core_export.h" #include "prometheus/metric_type.h" namespace prometheus { -struct MetricFamily { +struct PROMETHEUS_CPP_CORE_EXPORT MetricFamily { std::string name; std::string help; MetricType type = MetricType::Untyped; diff --git a/core/include/prometheus/metric_type.h b/core/include/prometheus/metric_type.h index bd5c77f0..e1a53183 100644 --- a/core/include/prometheus/metric_type.h +++ b/core/include/prometheus/metric_type.h @@ -1,8 +1,10 @@ #pragma once +#include "prometheus/core_export.h" + namespace prometheus { -enum class MetricType { +enum class PROMETHEUS_CPP_CORE_EXPORT MetricType { Counter, Gauge, Summary, diff --git a/core/include/prometheus/registry.h b/core/include/prometheus/registry.h index cc901073..ac8a6406 100644 --- a/core/include/prometheus/registry.h +++ b/core/include/prometheus/registry.h @@ -7,6 +7,7 @@ #include #include "prometheus/collectable.h" +#include "prometheus/core_export.h" #include "prometheus/counter.h" #include "prometheus/detail/counter_builder.h" #include "prometheus/detail/future_std.h" @@ -34,7 +35,7 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. -class Registry : public Collectable { +class PROMETHEUS_CPP_CORE_EXPORT Registry : public Collectable { public: /// \brief Returns a list of metrics and their samples. /// diff --git a/core/include/prometheus/serializer.h b/core/include/prometheus/serializer.h index 83bbd6e4..bba46280 100644 --- a/core/include/prometheus/serializer.h +++ b/core/include/prometheus/serializer.h @@ -4,11 +4,12 @@ #include #include +#include "prometheus/core_export.h" #include "prometheus/metric_family.h" namespace prometheus { -class Serializer { +class PROMETHEUS_CPP_CORE_EXPORT Serializer { public: virtual ~Serializer() = default; virtual std::string Serialize(const std::vector&) const; diff --git a/core/include/prometheus/summary.h b/core/include/prometheus/summary.h index 56fcd0a8..1bb53c3f 100644 --- a/core/include/prometheus/summary.h +++ b/core/include/prometheus/summary.h @@ -6,6 +6,7 @@ #include #include "prometheus/client_metric.h" +#include "prometheus/core_export.h" #include "prometheus/detail/ckms_quantiles.h" #include "prometheus/detail/summary_builder.h" #include "prometheus/detail/time_window_quantiles.h" @@ -37,7 +38,7 @@ namespace prometheus { /// /// The class is thread-safe. No concurrent call to any API of this type causes /// a data race. -class Summary { +class PROMETHEUS_CPP_CORE_EXPORT Summary { public: using Quantiles = std::vector; @@ -117,6 +118,6 @@ class Summary { /// /// To finish the configuration of the Summary metric register it with /// Register(Registry&). -detail::SummaryBuilder BuildSummary(); +PROMETHEUS_CPP_CORE_EXPORT detail::SummaryBuilder BuildSummary(); } // namespace prometheus diff --git a/core/include/prometheus/text_serializer.h b/core/include/prometheus/text_serializer.h index a12f0ec1..f25dc636 100644 --- a/core/include/prometheus/text_serializer.h +++ b/core/include/prometheus/text_serializer.h @@ -4,12 +4,13 @@ #include #include +#include "prometheus/core_export.h" #include "prometheus/metric_family.h" #include "prometheus/serializer.h" namespace prometheus { -class TextSerializer : public Serializer { +class PROMETHEUS_CPP_CORE_EXPORT TextSerializer : public Serializer { public: using Serializer::Serialize; void Serialize(std::ostream& out, diff --git a/pull/CMakeLists.txt b/pull/CMakeLists.txt index 337e21f3..7a9114f5 100644 --- a/pull/CMakeLists.txt +++ b/pull/CMakeLists.txt @@ -18,6 +18,11 @@ add_library(pull add_library(${PROJECT_NAME}::pull ALIAS pull) +generate_export_header(pull + EXPORT_FILE_NAME include/prometheus/pull_export.h + PREFIX_NAME PROMETHEUS_CPP_ +) + target_link_libraries(pull PUBLIC ${PROJECT_NAME}::core @@ -31,6 +36,7 @@ target_link_libraries(pull target_include_directories(pull PUBLIC $ + $ PRIVATE ${CIVETWEB_INCLUDE_DIRS} ) diff --git a/pull/include/prometheus/exposer.h b/pull/include/prometheus/exposer.h index c318f751..7dd29ff0 100644 --- a/pull/include/prometheus/exposer.h +++ b/pull/include/prometheus/exposer.h @@ -7,6 +7,7 @@ #include #include "prometheus/collectable.h" +#include "prometheus/pull_export.h" #include "prometheus/registry.h" class CivetServer; @@ -17,7 +18,7 @@ namespace detail { class MetricsHandler; } // namespace detail -class Exposer { +class PROMETHEUS_CPP_PULL_EXPORT Exposer { public: explicit Exposer(const std::string& bind_address, const std::string& uri = std::string("/metrics")); diff --git a/push/CMakeLists.txt b/push/CMakeLists.txt index 4e4002e2..9adfe211 100644 --- a/push/CMakeLists.txt +++ b/push/CMakeLists.txt @@ -7,6 +7,12 @@ add_library(push add_library(${PROJECT_NAME}::push ALIAS push) +generate_export_header(push + EXPORT_FILE_NAME include/prometheus/push_export.h + PREFIX_NAME PROMETHEUS_CPP_ +) + + target_link_libraries(push PUBLIC ${PROJECT_NAME}::core @@ -19,6 +25,7 @@ target_link_libraries(push target_include_directories(push PUBLIC $ + $ PRIVATE ${CURL_INCLUDE_DIRS} ) diff --git a/push/include/prometheus/gateway.h b/push/include/prometheus/gateway.h index 577bfa3d..4b05e532 100644 --- a/push/include/prometheus/gateway.h +++ b/push/include/prometheus/gateway.h @@ -7,11 +7,12 @@ #include #include +#include "prometheus/push_export.h" #include "prometheus/registry.h" namespace prometheus { -class Gateway { +class PROMETHEUS_CPP_PUSH_EXPORT Gateway { public: using Labels = std::map;