Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ cmake_policy(SET CMP0057 NEW)

project(opentelemetry-cpp)

file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h"
OPENTELEMETRY_CPP_HEADER_VERSION_H)
if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES
"OPENTELEMETRY_ABI_VERSION_NO[ \t\r\n]+\"?([0-9]+)\"?")
math(EXPR OPENTELEMETRY_ABI_VERSION_NO ${CMAKE_MATCH_1})
else()
message(
FATAL_ERROR
"OPENTELEMETRY_ABI_VERSION_NO not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h"
)
endif()
if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES
"OPENTELEMETRY_VERSION[ \t\r\n]+\"?([^\"]+)\"?")
set(OPENTELEMETRY_VERSION ${CMAKE_MATCH_1})
else()
message(
FATAL_ERROR
"OPENTELEMETRY_VERSION not found on ${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h"
)
endif()

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
Expand Down Expand Up @@ -81,6 +102,13 @@ if(MSVC)
# for recent C++ language standards. Without this option MSVC returns the
# value of __cplusplus="199711L"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")

# When using vcpkg, all targets build with the same runtime
if(VCPKG_TOOLCHAIN)
set(CMAKE_MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<STREQUAL:${VCPKG_CRT_LINKAGE},dynamic>:DLL>"
CACHE STRING "")
endif()
endif()

if(WITH_OTLP)
Expand Down Expand Up @@ -156,6 +184,9 @@ if(BUILD_TESTING)
find_package(benchmark CONFIG REQUIRED)
endif()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
Comment on lines +187 to +188
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include these 2 for non-posix?

Copy link
Copy Markdown
Member Author

@owent owent Dec 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GNUInstallDirs module only defines some directory names to install. And CMakePackageConfigHelpers is used to generate the standardized cmake config files, they are used by find_package(NAME CONFIG) of cmake. These two modules are useful on both posix and non-posix platforms.


include_directories(api/include)
add_subdirectory(api)
include_directories(sdk/include)
Expand All @@ -167,3 +198,34 @@ if(WITH_EXAMPLES)
add_subdirectory(examples)
endif()
add_subdirectory(ext)

# Export cmake config and support find_packages(opentelemetry-cpp CONFIG) Write
# config file for find_packages(opentelemetry-cpp CONFIG)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/opentelemetry-cpp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
PATH_VARS OPENTELEMETRY_ABI_VERSION_NO OPENTELEMETRY_VERSION PROJECT_NAME
CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

# Write version file for find_packages(opentelemetry-cpp CONFIG)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake"
VERSION ${OPENTELEMETRY_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")

# Export all components
export(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-target.cmake")
install(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
14 changes: 12 additions & 2 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
add_library(opentelemetry_api INTERFACE)
target_include_directories(
opentelemetry_api INTERFACE include
$<INSTALL_INTERFACE:include/opentelemetry>)
opentelemetry_api
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

set_target_properties(opentelemetry_api PROPERTIES EXPORT_NAME api)

install(
TARGETS opentelemetry_api
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry
Expand Down
18 changes: 18 additions & 0 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ add_library(
${METRICS_SERVICE_PB_CPP_FILE}
${METRICS_SERVICE_GRPC_PB_CPP_FILE})

set_target_properties(opentelemetry_proto PROPERTIES EXPORT_NAME proto)

install(
TARGETS opentelemetry_proto
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(TARGET protobuf::libprotobuf)
target_link_libraries(opentelemetry_proto PUBLIC protobuf::libprotobuf)
else() # cmake 3.8 or lower
target_include_directories(opentelemetry_proto
PUBLIC ${Protobuf_INCLUDE_DIRS})
target_include_directories(opentelemetry_proto
INTERFACE ${Protobuf_LIBRARIES})
endif()

if(BUILD_SHARED_LIBS)
set_property(TARGET opentelemetry_proto PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
21 changes: 20 additions & 1 deletion exporters/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@ include_directories(include)

add_library(opentelemetry_exporter_in_memory INTERFACE)

target_include_directories(opentelemetry_exporter_in_memory INTERFACE include/)
target_include_directories(
opentelemetry_exporter_in_memory
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

set_target_properties(opentelemetry_exporter_in_memory
PROPERTIES EXPORT_NAME in_memory_span_exporter)

install(
TARGETS opentelemetry_exporter_in_memory
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/exporters/memory
DESTINATION include/opentelemetry/exporters/
FILES_MATCHING
PATTERN "*.h")

if(BUILD_TESTING)
add_executable(in_memory_span_data_test test/in_memory_span_data_test.cc)
Expand Down
62 changes: 51 additions & 11 deletions exporters/ostream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
include_directories(include)

add_library(opentelemetry_exporter_ostream_logs src/log_exporter.cc)
add_library(opentelemetry_exporter_ostream_metrics src/metrics_exporter.cc)
add_library(opentelemetry_exporter_ostream_span src/span_exporter.cc)

set_target_properties(opentelemetry_exporter_ostream_logs
PROPERTIES EXPORT_NAME ostream_log_exporter)

set_target_properties(opentelemetry_exporter_ostream_metrics
PROPERTIES EXPORT_NAME ostream_metrics_exporter)

set_target_properties(opentelemetry_exporter_ostream_span
PROPERTIES EXPORT_NAME ostream_span_exporter)

target_include_directories(
opentelemetry_exporter_ostream_logs
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>")

target_include_directories(
opentelemetry_exporter_ostream_metrics
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>")

target_include_directories(
opentelemetry_exporter_ostream_span
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>")

target_link_libraries(opentelemetry_exporter_ostream_logs
PUBLIC opentelemetry_logs)

target_link_libraries(opentelemetry_exporter_ostream_metrics
PUBLIC opentelemetry_metrics)

target_link_libraries(opentelemetry_exporter_ostream_span
PUBLIC opentelemetry_trace)

install(
TARGETS opentelemetry_exporter_ostream_logs
opentelemetry_exporter_ostream_metrics
opentelemetry_exporter_ostream_span
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/exporters/ostream
DESTINATION include/opentelemetry/exporters/
FILES_MATCHING
PATTERN "*.h")

if(BUILD_TESTING)
add_executable(ostream_metrics_test test/ostream_metrics_test.cc)
add_executable(ostream_span_test test/ostream_span_test.cc)
add_executable(ostream_log_test test/ostream_log_test.cc)

target_link_libraries(
ostream_span_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
${CORE_RUNTIME_LIBS} opentelemetry_exporter_ostream_span)
target_link_libraries(ostream_span_test ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_ostream_span)

target_link_libraries(
ostream_metrics_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
${CORE_RUNTIME_LIBS} opentelemetry_exporter_ostream_metrics)
target_link_libraries(ostream_metrics_test ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_ostream_metrics)

target_link_libraries(
ostream_log_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_exporter_ostream_logs opentelemetry_logs)
target_link_libraries(ostream_log_test ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_ostream_logs)

gtest_add_tests(
TARGET ostream_log_test
Expand Down
26 changes: 23 additions & 3 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
include_directories(include)

add_library(opentelemetry_exporter_otprotocol src/recordable.cc
src/otlp_exporter.cc)
target_link_libraries(opentelemetry_exporter_otprotocol opentelemetry_proto)

set_target_properties(opentelemetry_exporter_otprotocol
PROPERTIES EXPORT_NAME otlp_exporter)

target_link_libraries(opentelemetry_exporter_otprotocol
PUBLIC opentelemetry_trace opentelemetry_proto)

install(
TARGETS opentelemetry_exporter_otprotocol
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/exporters/otlp
DESTINATION include/opentelemetry/exporters/
FILES_MATCHING
PATTERN "*.h")

target_include_directories(
opentelemetry_exporter_otprotocol
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>")

if(BUILD_TESTING)
add_executable(recordable_test test/recordable_test.cc)
Expand Down
23 changes: 21 additions & 2 deletions exporters/prometheus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.

include_directories(include)

find_package(prometheus-cpp CONFIG REQUIRED)

add_library(prometheus_exporter src/prometheus_collector.cc
src/prometheus_exporter_utils.cc)

target_include_directories(
prometheus_exporter
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

target_link_libraries(prometheus_exporter PUBLIC opentelemetry_metrics
prometheus-cpp::core)

install(
TARGETS prometheus_exporter
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/exporters/prometheus
DESTINATION include/opentelemetry/exporters/
FILES_MATCHING
PATTERN "*.h")

if(BUILD_TESTING)
add_subdirectory(test)
endif()
21 changes: 21 additions & 0 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
add_library(opentelemetry_ext INTERFACE)
target_include_directories(
opentelemetry_ext
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

set_target_properties(opentelemetry_ext PROPERTIES EXPORT_NAME "ext")

install(
TARGETS opentelemetry_ext
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/ext
DESTINATION include/opentelemetry/
FILES_MATCHING
PATTERN "*.h")

add_subdirectory(src)
include_directories(include)

Expand Down
14 changes: 11 additions & 3 deletions ext/src/zpages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ add_library(
../../include/opentelemetry/ext/zpages/tracez_data_aggregator.h
../../include/opentelemetry/ext/zpages/tracez_http_server.h)

target_include_directories(opentelemetry_zpages PUBLIC ../../include)
set_target_properties(opentelemetry_zpages PROPERTIES EXPORT_NAME zpages)

target_link_libraries(opentelemetry_zpages opentelemetry_api
opentelemetry_trace)
target_link_libraries(
opentelemetry_zpages PUBLIC opentelemetry_ext opentelemetry_api
opentelemetry_trace)

install(
TARGETS opentelemetry_zpages
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
10 changes: 8 additions & 2 deletions ext/test/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ if(CURL_FOUND)
set(CURL_LIBRARY "-lcurl")
set(FILENAME curl_http_test)
add_executable(${FILENAME} ${FILENAME}.cc)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(${FILENAME} ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${CURL_LIBRARIES})
${CMAKE_THREAD_LIBS_INIT})

if(TARGET CURL::libcurl)
target_link_libraries(${FILENAME} CURL::libcurl)
else()
include_directories(${CURL_INCLUDE_DIRS})
target_link_libraries(${FILENAME} ${CURL_LIBRARIES})
endif()
gtest_add_tests(
TARGET ${FILENAME}
TEST_PREFIX ext.http.curl.
Expand Down
Loading