Skip to content

Commit

Permalink
Add (shared) library versioning
Browse files Browse the repository at this point in the history
Closes: #223
  • Loading branch information
gjasny committed Aug 31, 2019
1 parent 1bf46d4 commit fca8824
Show file tree
Hide file tree
Showing 29 changed files with 226 additions and 38 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
@@ -1,8 +1,9 @@

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(prometheus-cpp)
project(prometheus-cpp VERSION 0.8.0)

include(GenerateExportHeader)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand All @@ -20,6 +21,13 @@ if(OVERRIDE_CXX_STANDARD_FLAGS)
set(CMAKE_CXX_EXTENSIONS Off)
endif()

# Hide things by default for shared libraries
if(BUILD_SHARED_LIBS)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads)

Expand Down
15 changes: 13 additions & 2 deletions core/CMakeLists.txt
Expand Up @@ -18,6 +18,11 @@ add_library(core

add_library(${PROJECT_NAME}::core ALIAS core)

generate_export_header(core
EXPORT_FILE_NAME include/prometheus/detail/core_export.h
PREFIX_NAME PROMETHEUS_CPP_
)

target_link_libraries(core
PRIVATE
Threads::Threads
Expand All @@ -27,9 +32,15 @@ target_link_libraries(core
target_include_directories(core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
)

set_target_properties(core PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-core)
set_target_properties(core
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}-core
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

install(
TARGETS core
Expand All @@ -41,7 +52,7 @@ install(
)

install(
DIRECTORY include/
DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

Expand Down
6 changes: 4 additions & 2 deletions core/include/prometheus/check_names.h
Expand Up @@ -2,8 +2,10 @@

#include <string>

#include "prometheus/detail/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
4 changes: 3 additions & 1 deletion core/include/prometheus/client_metric.h
Expand Up @@ -5,9 +5,11 @@
#include <tuple>
#include <vector>

#include "prometheus/detail/core_export.h"

namespace prometheus {

struct ClientMetric {
struct PROMETHEUS_CPP_CORE_EXPORT ClientMetric {
// Label

struct Label {
Expand Down
4 changes: 3 additions & 1 deletion core/include/prometheus/collectable.h
Expand Up @@ -2,6 +2,8 @@

#include <vector>

#include "prometheus/detail/core_export.h"

namespace prometheus {
struct MetricFamily;
}
Expand All @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions core/include/prometheus/counter.h
Expand Up @@ -2,6 +2,7 @@

#include "prometheus/client_metric.h"
#include "prometheus/detail/builder.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/gauge.h"
#include "prometheus/metric_type.h"

Expand All @@ -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};

Expand Down Expand Up @@ -76,6 +77,6 @@ class Counter {
///
/// To finish the configuration of the Counter metric, register it with
/// Register(Registry&).
detail::Builder<Counter> BuildCounter();
PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Counter> BuildCounter();

} // namespace prometheus
6 changes: 4 additions & 2 deletions core/include/prometheus/detail/ckms_quantiles.h
Expand Up @@ -5,12 +5,14 @@
#include <functional>
#include <vector>

#include "prometheus/detail/core_export.h"

namespace prometheus {
namespace detail {

class CKMSQuantiles {
class PROMETHEUS_CPP_CORE_EXPORT CKMSQuantiles {
public:
struct Quantile {
struct PROMETHEUS_CPP_CORE_EXPORT Quantile {
const double quantile;
const double error;
const double u;
Expand Down
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/counter_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Counter;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT CounterBuilder {
public:
CounterBuilder& Labels(const std::map<std::string, std::string>& labels);
CounterBuilder& Name(const std::string&);
CounterBuilder& Help(const std::string&);
Family<Counter>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/gauge_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Gauge;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT GaugeBuilder {
public:
GaugeBuilder& Labels(const std::map<std::string, std::string>& labels);
GaugeBuilder& Name(const std::string&);
GaugeBuilder& Help(const std::string&);
Family<Gauge>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/histogram_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Histogram;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT HistogramBuilder {
public:
HistogramBuilder& Labels(const std::map<std::string, std::string>& labels);
HistogramBuilder& Name(const std::string&);
HistogramBuilder& Help(const std::string&);
Family<Histogram>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
31 changes: 31 additions & 0 deletions core/include/prometheus/detail/summary_builder.h
@@ -0,0 +1,31 @@
#pragma once

#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

template <typename T>
class Family;
class Summary;
class Registry;

namespace detail {

class PROMETHEUS_CPP_CORE_EXPORT SummaryBuilder {
public:
SummaryBuilder& Labels(const std::map<std::string, std::string>& labels);
SummaryBuilder& Name(const std::string&);
SummaryBuilder& Help(const std::string&);
Family<Summary>& Register(Registry&);

private:
std::map<std::string, std::string> labels_;
std::string name_;
std::string help_;
};

} // namespace detail
} // namespace prometheus
3 changes: 2 additions & 1 deletion core/include/prometheus/detail/time_window_quantiles.h
Expand Up @@ -5,11 +5,12 @@
#include <vector>

#include "prometheus/detail/ckms_quantiles.h"
#include "prometheus/detail/core_export.h"

namespace prometheus {
namespace detail {

class TimeWindowQuantiles {
class PROMETHEUS_CPP_CORE_EXPORT TimeWindowQuantiles {
using Clock = std::chrono::steady_clock;

public:
Expand Down
5 changes: 4 additions & 1 deletion core/include/prometheus/detail/utils.h
Expand Up @@ -4,6 +4,8 @@
#include <map>
#include <string>

#include "prometheus/detail/core_export.h"

namespace prometheus {

namespace detail {
Expand All @@ -13,7 +15,8 @@ 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<std::string, std::string>& labels);
PROMETHEUS_CPP_CORE_EXPORT std::size_t hash_labels(
const std::map<std::string, std::string>& labels);

} // namespace detail

Expand Down
3 changes: 2 additions & 1 deletion core/include/prometheus/family.h
Expand Up @@ -15,6 +15,7 @@
#include "prometheus/check_names.h"
#include "prometheus/client_metric.h"
#include "prometheus/collectable.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/detail/utils.h"
#include "prometheus/metric_family.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ namespace prometheus {
///
/// \tparam T One of the metric types Counter, Gauge, Histogram or Summary.
template <typename T>
class Family : public Collectable {
class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
public:
/// \brief Create a new metric.
///
Expand Down
5 changes: 3 additions & 2 deletions core/include/prometheus/gauge.h
Expand Up @@ -4,6 +4,7 @@

#include "prometheus/client_metric.h"
#include "prometheus/detail/builder.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/metric_type.h"

namespace prometheus {
Expand All @@ -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};

Expand Down Expand Up @@ -88,6 +89,6 @@ class Gauge {
///
/// To finish the configuration of the Gauge metric register it with
/// Register(Registry&).
detail::Builder<Gauge> BuildGauge();
PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Gauge> BuildGauge();

} // namespace prometheus
5 changes: 3 additions & 2 deletions core/include/prometheus/histogram.h
Expand Up @@ -5,6 +5,7 @@
#include "prometheus/client_metric.h"
#include "prometheus/counter.h"
#include "prometheus/detail/builder.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/metric_type.h"

namespace prometheus {
Expand All @@ -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<double>;

Expand Down Expand Up @@ -97,6 +98,6 @@ class Histogram {
///
/// To finish the configuration of the Histogram metric register it with
/// Register(Registry&).
detail::Builder<Histogram> BuildHistogram();
PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Histogram> BuildHistogram();

} // namespace prometheus
3 changes: 2 additions & 1 deletion core/include/prometheus/metric_family.h
Expand Up @@ -4,11 +4,12 @@
#include <vector>

#include "prometheus/client_metric.h"
#include "prometheus/detail/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;
Expand Down

0 comments on commit fca8824

Please sign in to comment.