Skip to content

Commit

Permalink
Merge pull request #308 from jupp0r/cmake-visibilities
Browse files Browse the repository at this point in the history
Fix symbol visibilities for CMake (and Bazel)
  • Loading branch information
gjasny committed Oct 19, 2019
2 parents 1d844b6 + ae5f98d commit 51c7110
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 53 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(prometheus-cpp VERSION 0.8.0)

include(GenerateExportHeader)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down
5 changes: 4 additions & 1 deletion bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
exports_files(
glob(["*.BUILD"]),
glob([
"*.BUILD",
"*.tpl",
]),
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions bazel/dummy_export.h.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#define {BASE_NAME}_EXPORT
#define {BASE_NAME}_NO_EXPORT
21 changes: 21 additions & 0 deletions bazel/export_header.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def _generate_dummy_export_header_impl(ctx):
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.header_file,
substitutions = {
"{BASE_NAME}": ctx.attr.basename,
},
)

generate_dummy_export_header = rule(
attrs = {
"basename": attr.string(mandatory = True),
"header": attr.string(mandatory = True),
"_template": attr.label(
allow_single_file = True,
default = Label("@com_github_jupp0r_prometheus_cpp//bazel:dummy_export.h.tpl"),
),
},
implementation = _generate_dummy_export_header_impl,
outputs = {"header_file": "%{header}"},
)
13 changes: 9 additions & 4 deletions core/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
load("//bazel:export_header.bzl", "generate_dummy_export_header")

generate_dummy_export_header(
name = "export_header",
basename = "PROMETHEUS_CPP_CORE",
header = "include/prometheus/detail/core_export.h",
)

cc_library(
name = "core",
srcs = glob([
Expand All @@ -6,10 +14,7 @@ cc_library(
]),
hdrs = glob(
["include/**/*.h"],
),
local_defines = [
"PROMETHEUS_CPP_COMPILE_CORE",
],
) + [":export_header"],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)
10 changes: 8 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ 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
DEFINE_SYMBOL PROMETHEUS_CPP_COMPILE_CORE
DEFINE_SYMBOL PROMETHEUS_CPP_CORE_EXPORTS
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

generate_export_header(core
BASE_NAME ${PROJECT_NAME}-core
EXPORT_FILE_NAME include/prometheus/detail/core_export.h
)

install(
TARGETS core
EXPORT ${PROJECT_NAME}-targets
Expand All @@ -46,7 +52,7 @@ install(
)

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

Expand Down
11 changes: 0 additions & 11 deletions core/include/prometheus/detail/core_export.h

This file was deleted.

11 changes: 9 additions & 2 deletions pull/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
load("//bazel:export_header.bzl", "generate_dummy_export_header")

generate_dummy_export_header(
name = "export_header",
basename = "PROMETHEUS_CPP_PULL",
header = "include/prometheus/detail/pull_export.h",
)

cc_library(
name = "pull",
srcs = glob([
Expand All @@ -6,10 +14,9 @@ cc_library(
]),
hdrs = glob(
["include/**/*.h"],
),
) + [":export_header"],
local_defines = [
"HAVE_ZLIB",
"PROMETHEUS_CPP_COMPILE_PULL",
],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
Expand Down
10 changes: 8 additions & 2 deletions pull/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ target_link_libraries(pull
target_include_directories(pull
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE
${CIVETWEB_INCLUDE_DIRS}
)
Expand All @@ -43,11 +44,16 @@ target_compile_definitions(pull
set_target_properties(pull
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}-pull
DEFINE_SYMBOL PROMETHEUS_CPP_COMPILE_PULL
DEFINE_SYMBOL PROMETHEUS_CPP_PULL_EXPORTS
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

generate_export_header(pull
BASE_NAME ${PROJECT_NAME}-pull
EXPORT_FILE_NAME include/prometheus/detail/pull_export.h
)

install(
TARGETS pull
EXPORT ${PROJECT_NAME}-targets
Expand All @@ -58,7 +64,7 @@ install(
)

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

Expand Down
11 changes: 0 additions & 11 deletions pull/include/prometheus/detail/pull_export.h

This file was deleted.

13 changes: 9 additions & 4 deletions push/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
load("//bazel:export_header.bzl", "generate_dummy_export_header")

generate_dummy_export_header(
name = "export_header",
basename = "PROMETHEUS_CPP_PUSH",
header = "include/prometheus/detail/push_export.h",
)

cc_library(
name = "push",
srcs = glob([
Expand All @@ -6,15 +14,12 @@ cc_library(
]),
hdrs = glob(
["include/**/*.h"],
),
) + [":export_header"],
linkopts = select({
"//:windows": [],
"//:windows_msvc": [],
"//conditions:default": ["-lpthread"],
}),
local_defines = [
"PROMETHEUS_CPP_COMPILE_PUSH",
],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = [
Expand Down
10 changes: 8 additions & 2 deletions push/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ target_link_libraries(push
target_include_directories(push
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE
${CURL_INCLUDE_DIRS}
)

set_target_properties(push
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}-push
DEFINE_SYMBOL PROMETHEUS_CPP_COMPILE_PUSH
DEFINE_SYMBOL PROMETHEUS_CPP_PUSH_EXPORTS
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)

generate_export_header(push
BASE_NAME ${PROJECT_NAME}-push
EXPORT_FILE_NAME include/prometheus/detail/push_export.h
)

install(
TARGETS push
EXPORT ${PROJECT_NAME}-targets
Expand All @@ -41,7 +47,7 @@ install(
)

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

Expand Down
11 changes: 0 additions & 11 deletions push/include/prometheus/detail/push_export.h

This file was deleted.

6 changes: 3 additions & 3 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def load_civetweb():
http_archive(
name = "civetweb",
strip_prefix = "civetweb-1.11",
sha256 = "de7d5e7a2d9551d325898c71e41d437d5f7b51e754b242af897f7be96e713a42",
strip_prefix = "civetweb-2c1caa6e690bfe3b435a10c372ab2dcd14b872e8",
sha256 = "d576b2257fe116523e5644232868670dcdd6c89b8e42b69d51e26b146575ab6a",
urls = [
"https://github.com/civetweb/civetweb/archive/v1.11.tar.gz",
"https://github.com/civetweb/civetweb/archive/2c1caa6e690bfe3b435a10c372ab2dcd14b872e8.tar.gz",
],
build_file = "@com_github_jupp0r_prometheus_cpp//bazel:civetweb.BUILD",
)
Expand Down

0 comments on commit 51c7110

Please sign in to comment.