Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OPENTELEMETRY_INSTALL to allow user to skip install targets. #2022

Merged
merged 3 commits into from
Mar 7, 2023
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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,22 @@ jobs:
sudo ./ci/setup_grpc.sh
./ci/do_ci.sh cmake.exporter.otprotocol.test

cmake_do_not_install_test:
name: CMake do not install test (with otlp-exporter)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup
run: |
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: run otlp exporter tests
run: |
sudo ./ci/setup_grpc.sh
./ci/do_ci.sh cmake.do_not_install.test

plugin_test:
name: Plugin -> CMake
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Increment the:

## [Unreleased]

* [BUILD] Add `OPENTELEMETRY_INSTALL` to allow user to skip install targets.
[#2022](https://github.com/open-telemetry/opentelemetry-cpp/pull/2022)
* [SDK] Rename the global SDK version variables to avoid naming clash
[#2011](https://github.com/open-telemetry/opentelemetry-cpp/pull/2011)
* [SDK]Add attributes for InstrumentationScope
Expand Down
80 changes: 45 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ option(WITH_GSL

option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF)

if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(OPENTELEMETRY_INSTALL_default ON)
else()
set(OPENTELEMETRY_INSTALL_default OFF)
Comment on lines +121 to +124
Copy link
Contributor

Choose a reason for hiding this comment

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

(Maybe this is too late now, but) Do you think this should default to ON in all cases for backwards compatibility?

Do you think the new feature should be listed in INSTALL.md?

Some of the available cmake build variables we can use during cmake
configuration:
- `-DCMAKE_POSITION_INDEPENDENT_CODE=ON` : Please note that with default
configuration, the code is compiled without `-fpic` option, so it is not
suitable for inclusion in shared libraries. To enable the code for
inclusion in shared libraries, this variable is used.
- `-DBUILD_SHARED_LIBS=ON` : To build shared libraries for the targets.
Please refer to note [below](#building-shared-libs-for-windows) for
Windows DLL support.
- `-DWITH_OTLP=ON` : To enable building OTLP exporter.
- `-DWITH_PROMETHEUS=ON` : To enable building prometheus exporter.

Copy link
Member

@lalitb lalitb Mar 8, 2023

Choose a reason for hiding this comment

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

(Maybe this is too late now, but) Do you think this should default to ON in all cases for backwards compatibility?

True, somehow missed this during review. Not sure if reverting back would be good idea as the release is already done now. We can mention this in release summary as breaking change for builds cc @ThomsonTan ?

endif()
option(OPENTELEMETRY_INSTALL "Whether to install opentelemetry targets"
${OPENTELEMETRY_INSTALL_default})

if(NOT DEFINED CMAKE_CXX_STANDARD)
if(WITH_STL)
# Require at least C++17. C++20 is needed to avoid gsl::span
Expand Down Expand Up @@ -579,41 +587,43 @@ if(NOT WITH_API_ONLY)
endif()
endif()

# Export cmake config and support find_packages(opentelemetry-cpp CONFIG) Write
# config file for find_packages(opentelemetry-cpp CONFIG)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/opentelemetry-cpp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
PATH_VARS OPENTELEMETRY_ABI_VERSION_NO OPENTELEMETRY_VERSION PROJECT_NAME
INCLUDE_INSTALL_DIR 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}/${PROJECT_NAME}-config-version.cmake"
VERSION ${OPENTELEMETRY_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
if(OPENTELEMETRY_INSTALL)
# Export cmake config and support find_packages(opentelemetry-cpp CONFIG)
# Write config file for find_packages(opentelemetry-cpp CONFIG)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/opentelemetry-cpp-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
PATH_VARS OPENTELEMETRY_ABI_VERSION_NO OPENTELEMETRY_VERSION PROJECT_NAME
INCLUDE_INSTALL_DIR 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}/${PROJECT_NAME}-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Export all components
export(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-target.cmake"
)
install(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

if(BUILD_PACKAGE)
include(cmake/package.cmake)
include(CPack)
VERSION ${OPENTELEMETRY_VERSION}
COMPATIBILITY ExactVersion)

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

# Export all components
export(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}/${PROJECT_NAME}-target.cmake"
)
install(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

if(BUILD_PACKAGE)
include(cmake/package.cmake)
include(CPack)
endif()
endif()
50 changes: 26 additions & 24 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,33 @@ target_include_directories(

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})

set(LOGS_EXCLUDE_PATTERN "")
if(NOT WITH_LOGS_PREVIEW)
set(LOGS_EXCLUDE_PATTERN "logs")
endif()
if(OPENTELEMETRY_INSTALL)
install(
TARGETS opentelemetry_api
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

set(LOGS_EXCLUDE_PATTERN "")
if(NOT WITH_LOGS_PREVIEW)
set(LOGS_EXCLUDE_PATTERN "logs")
endif()

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

install(
DIRECTORY include/opentelemetry
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "${LOGS_EXCLUDE_PATTERN}" EXCLUDE)
install(
DIRECTORY include/opentelemetry
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "metrics" EXCLUDE)

install(
DIRECTORY include/opentelemetry
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "${LOGS_EXCLUDE_PATTERN}" EXCLUDE)
endif()

if(BUILD_TESTING)
add_subdirectory(test)
Expand Down
15 changes: 15 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then
make -j $(nproc)
cd exporters/otlp && make test
exit 0
elif [[ "$1" == "cmake.do_not_install.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_OTLP=ON \
-DWITH_OTLP_HTTP=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DOPENTELEMETRY_INSTALL=OFF \
"${SRC_DIR}"
grpc_cpp_plugin=`which grpc_cpp_plugin`
proto_make_file="CMakeFiles/opentelemetry_proto.dir/build.make"
sed -i "s~gRPC_CPP_PLUGIN_EXECUTABLE-NOTFOUND~$grpc_cpp_plugin~" ${proto_make_file} #fixme
make -j $(nproc)
cd exporters/otlp && make test
exit 0
elif [[ "$1" == "bazel.with_abseil" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC --//api:with_abseil=true //...
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS_ASYNC --//api:with_abseil=true //...
Expand Down
85 changes: 38 additions & 47 deletions cmake/nlohmann-json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@
# SPDX-License-Identifier: Apache-2.0

#
# The dependency on nlohmann_json can be provided different ways.
# By order of decreasing priority, options are:
# The dependency on nlohmann_json can be provided different ways. By order of
# decreasing priority, options are:
#
# 1 - Search for a nlohmann_json package
#
# Packages installed on the local machine are used if found.
#
# The nlohmann_json dependency is not installed,
# as it already is.
# The nlohmann_json dependency is not installed, as it already is.
#
# 2 - Search for a nlohmann_json git submodule
#
# When git submodule is used,
# the nlohmann_json code is located in:
# When git submodule is used, the nlohmann_json code is located in:
# third_party/nlohmann-json
#
# The nlohmann_json dependency is installed,
# by building the sub directory with JSON_Install=ON
# The nlohmann_json dependency is installed, by building the sub directory with
# JSON_Install=ON
#
# 3 - Download nlohmann_json from github
#
# Code from the development branch is used,
# unless a specific release tag is provided
# in variable ${nlohmann-json}
# Code from the development branch is used, unless a specific release tag is
# provided in variable ${nlohmann-json}
#
# The nlohmann_json dependency is installed,
# by building the downloaded code with JSON_Install=ON
# The nlohmann_json dependency is installed, by building the downloaded code
# with JSON_Install=ON
#


# nlohmann_json package is required for most SDK build configurations
find_package(nlohmann_json QUIET)
set(nlohmann_json_clone FALSE)
Expand All @@ -54,47 +50,42 @@ elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
if("${nlohmann-json}" STREQUAL "")
set(nlohmann-json "develop")
set(nlohmann-json "develop")
endif()
message(STATUS "nlohmann::json dependency satisfied by: github download")
set(nlohmann_json_clone TRUE)
include(ExternalProject)
ExternalProject_Add(nlohmann_json_download
PREFIX third_party
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG
"${nlohmann-json}"
UPDATE_COMMAND ""
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DJSON_BuildTests=OFF
-DJSON_Install=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
TEST_AFTER_INSTALL
0
DOWNLOAD_NO_PROGRESS
1
LOG_CONFIGURE
1
LOG_BUILD
1
LOG_INSTALL
1
)
ExternalProject_Add(
nlohmann_json_download
PREFIX third_party
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG "${nlohmann-json}"
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DJSON_BuildTests=OFF -DJSON_Install=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
TEST_AFTER_INSTALL 0
DOWNLOAD_NO_PROGRESS 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1)

ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR)
SET(NLOHMANN_JSON_INCLUDE_DIR ${INSTALL_DIR}/src/nlohmann_json_download/single_include)
set(NLOHMANN_JSON_INCLUDE_DIR
${INSTALL_DIR}/src/nlohmann_json_download/single_include)
add_library(nlohmann_json_ INTERFACE)
target_include_directories(nlohmann_json_ INTERFACE
"$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:include>")
target_include_directories(
nlohmann_json_ INTERFACE "$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:include>")
add_dependencies(nlohmann_json_ nlohmann_json_download)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json_)

install(
TARGETS nlohmann_json_
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(OPENTELEMETRY_INSTALL)
install(
TARGETS nlohmann_json_
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()
Loading