From d89c8005136f70a113db75aae9fb0e72885f8e6a Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 21 Jul 2026 14:25:10 -0400 Subject: [PATCH 1/6] add support for cmake component deprecation and policy --- cmake/find-package-support-functions.cmake | 30 +++++++++- cmake/otel-install-functions.cmake | 58 +++++++++++++++++-- .../templates/component-definitions.cmake.in | 11 ++++ .../opentelemetry-cpp-config.cmake.in | 13 +++++ 4 files changed, 103 insertions(+), 9 deletions(-) diff --git a/cmake/find-package-support-functions.cmake b/cmake/find-package-support-functions.cmake index f74d029d27..e6582224ac 100644 --- a/cmake/find-package-support-functions.cmake +++ b/cmake/find-package-support-functions.cmake @@ -4,6 +4,29 @@ include("${CMAKE_CURRENT_LIST_DIR}/component-definitions.cmake") include("${CMAKE_CURRENT_LIST_DIR}/thirdparty-dependency-definitions.cmake") +#------------------------------------------------------------------------- +# Function to resolve deprecated component names to their aliases. +# Components without an alias are removed from the list +#------------------------------------------------------------------------- +function(resolve_deprecated_components requested_components_inout) + set(_result ${${requested_components_inout}}) + foreach(_COMPONENT IN LISTS ${requested_components_inout}) + if(${_COMPONENT} IN_LIST OTEL_DEPRECATED_COMPONENTS_LIST) + set(_replacement_var "COMPONENT_${_COMPONENT}_REPLACEMENT") + if(DEFINED ${_replacement_var}) + message(DEPRECATION "opentelemetry-cpp: component `${_COMPONENT}` is deprecated, use `${${_replacement_var}}` instead.") + list(REMOVE_ITEM _result ${_COMPONENT}) + list(APPEND _result ${${_replacement_var}}) + else() + message(DEPRECATION "opentelemetry-cpp: component `${_COMPONENT}` is deprecated with no replacement.") + list(REMOVE_ITEM _result ${_COMPONENT}) + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES _result) + set(${requested_components_inout} "${_result}" PARENT_SCOPE) +endfunction() + #------------------------------------------------------------------------- # Function to get installed components. #------------------------------------------------------------------------- @@ -33,7 +56,6 @@ function(get_dependent_components component_in dependent_components_out) set(${dependent_components_out} ${result} PARENT_SCOPE) endfunction() - #------------------------------------------------------------------------- # Function to get requested components. #------------------------------------------------------------------------- @@ -44,8 +66,10 @@ function(get_requested_components installed_components_in requested_components_o message(DEBUG "get_requested_components: No components explicitly requested. Importing all installed components including: ${result}") set(${requested_components_out} ${result} PARENT_SCOPE) else() - message(DEBUG "get_requested_components: Components requested: ${opentelemetry-cpp_FIND_COMPONENTS}") - foreach(_COMPONENT IN LISTS opentelemetry-cpp_FIND_COMPONENTS) + set(REQUESTED_COMPONENTS ${opentelemetry-cpp_FIND_COMPONENTS}) + message(DEBUG "get_requested_components: Components requested: ${REQUESTED_COMPONENTS}") + resolve_deprecated_components(REQUESTED_COMPONENTS) + foreach(_COMPONENT IN LISTS REQUESTED_COMPONENTS) if(NOT ${_COMPONENT} IN_LIST OTEL_BUILT_COMPONENTS_LIST) message(ERROR " get_requested_components: Component `${_COMPONENT}` is not a built component of the opentelemetry-cpp package. Built components include: ${OTEL_BUILT_COMPONENTS_LIST}") return() diff --git a/cmake/otel-install-functions.cmake b/cmake/otel-install-functions.cmake index 109a0ed548..4da3685486 100644 --- a/cmake/otel-install-functions.cmake +++ b/cmake/otel-install-functions.cmake @@ -317,28 +317,44 @@ endfunction() #----------------------------------------------------------------------- # otel_add_component: -# Adds a component to the list of components to be installed. A component name and list of targest are required. +# Adds a component to the list of components to be installed. A component name and list of targets are required. # Optional files can be added to the component by specifying a directory, destination and matching pattern. # Each target is assigned to the component and its dependencies are identified based on the LINK_LIBRARIES property. # An alias target is also created for each target in the form of PROJECT_NAME::TARGET_EXPORT_NAME. +# DEPRECATED_NAMES lists old component names that are redirected to this component with a deprecation warning. +# DEPRECATED marks a component that has been fully removed with no replacement (no TARGETS required). # Usage: # otel_add_component( # COMPONENT +# [DEPRECATED_NAMES ...] # TARGETS ... -# FILES_DIRECTORY -# FILES_DESTINATION -# FILES_MATCHING ) +# [FILES_DIRECTORY +# FILES_DESTINATION +# FILES_MATCHING ]) +# otel_add_component( +# COMPONENT +# DEPRECATED) #----------------------------------------------------------------------- function(otel_add_component) - set(optionArgs ) + set(optionArgs DEPRECATED) set(oneValueArgs COMPONENT FILES_DIRECTORY FILES_DESTINATION) - set(multiValueArgs TARGETS FILES_MATCHING) + set(multiValueArgs TARGETS FILES_MATCHING DEPRECATED_NAMES) cmake_parse_arguments(_OTEL_ADD_COMP "${optionArgs}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") if(NOT _OTEL_ADD_COMP_COMPONENT) message(FATAL_ERROR "otel_add_component: COMPONENT is required") endif() + if(_OTEL_ADD_COMP_DEPRECATED) + # TODO: Support deprecated components that still install their targets, and + # mark those targets deprecated during the deprecation window. + get_property(_deprecated_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + list(APPEND _deprecated_components "${_OTEL_ADD_COMP_COMPONENT}") + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST "${_deprecated_components}") + message(DEBUG " DEPRECATED: ${_OTEL_ADD_COMP_COMPONENT} (no replacement)") + return() + endif() + if(NOT _OTEL_ADD_COMP_TARGETS) message(FATAL_ERROR "otel_add_component: TARGETS is required") endif() @@ -378,6 +394,16 @@ function(otel_add_component) FILES_MATCHING ${_OTEL_ADD_COMP_FILES_MATCHING} COMPONENT_DEPENDS ${_COMPONENT_DEPENDS} THIRDPARTY_DEPENDS ${_THIRDPARTY_DEPENDS}) + + foreach(_DEP_NAME IN LISTS _OTEL_ADD_COMP_DEPRECATED_NAMES) + get_property(_deprecated_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + list(APPEND _deprecated_components "${_DEP_NAME}") + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST "${_deprecated_components}") + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} + PROPERTY OTEL_COMPONENT_REPLACEMENT_${_DEP_NAME} + "${_OTEL_ADD_COMP_COMPONENT}") + message(DEBUG " DEPRECATED_NAME: ${_DEP_NAME} -> ${_OTEL_ADD_COMP_COMPONENT}") + endforeach() endfunction() #----------------------------------------------------------------------- @@ -420,6 +446,26 @@ function(otel_install_components) _otel_populate_component_thirdparty_depends_block(${_COMPONENT} OTEL_COMPONENTS_THIRDPARTY_DEPENDENCIES_BLOCK) endforeach() + get_property(OTEL_DEPRECATED_COMPONENTS_LIST DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + + if(OTEL_DEPRECATED_COMPONENTS_LIST) + message(STATUS "Install DEPRECATED COMPONENT definitions:") + endif() + + set(OTEL_COMPONENTS_REPLACEMENTS_BLOCK "") + foreach(_DEPRECATED_COMPONENT IN LISTS OTEL_DEPRECATED_COMPONENTS_LIST) + get_property(_REPLACEMENT_COMPONENT DIRECTORY ${PROJECT_SOURCE_DIR} + PROPERTY OTEL_COMPONENT_REPLACEMENT_${_DEPRECATED_COMPONENT}) + message(STATUS " Deprecated COMPONENT ${_DEPRECATED_COMPONENT}") + if(_REPLACEMENT_COMPONENT) + message(STATUS " Replacement: ${_REPLACEMENT_COMPONENT}") + string(APPEND OTEL_COMPONENTS_REPLACEMENTS_BLOCK + "set(COMPONENT_${_DEPRECATED_COMPONENT}_REPLACEMENT ${_REPLACEMENT_COMPONENT})\n") + else() + message(STATUS " No replacement installed.") + endif() + endforeach() + configure_file( "${PROJECT_SOURCE_DIR}/cmake/templates/component-definitions.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake/component-definitions.cmake" diff --git a/cmake/templates/component-definitions.cmake.in b/cmake/templates/component-definitions.cmake.in index 8430cc90fe..46263053ea 100644 --- a/cmake/templates/component-definitions.cmake.in +++ b/cmake/templates/component-definitions.cmake.in @@ -3,6 +3,17 @@ # Configured from opentelemetry-cpp/cmake/component-definitions.cmake.in +# ---------------------------------------------------------------------- +# Deprecated components +# ---------------------------------------------------------------------- +set(OTEL_DEPRECATED_COMPONENTS_LIST @OTEL_DEPRECATED_COMPONENTS_LIST@) + +# ---------------------------------------------------------------------- +# Deprecated component replacements (deprecated_name -> replacement_name) +# ---------------------------------------------------------------------- + +@OTEL_COMPONENTS_REPLACEMENTS_BLOCK@ + # ---------------------------------------------------------------------- # opentelmetry-cpp Built COMPONENT list # ---------------------------------------------------------------------- diff --git a/cmake/templates/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in index 69f77feac9..4a62d36947 100644 --- a/cmake/templates/opentelemetry-cpp-config.cmake.in +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -72,6 +72,7 @@ # COMPONENTS # api # sdk +# configuration # ext_common # ext_http_curl # ext_dll @@ -88,6 +89,14 @@ # resource_detectors # shims_opentracing # +# DEPRECATED COMPONENTS +# exporters_otlp_builder_utils - targets moved to COMPONENT exporters_otlp_common +# exporters_otlp_file_builder - targets moved to COMPONENT exporters_otlp_file +# exporters_otlp_http_builder - targets moved to COMPONENT exporters_otlp_http +# exporters_otlp_grpc_builder - targets moved to COMPONENT exporters_otlp_grpc +# exporters_ostream_builder - targets moved to COMPONENT exporters_ostream +# exporters_prometheus_builder - targets moved to COMPONENT exporters_prometheus +# -------------------- # :: # # TARGETS @@ -99,6 +108,8 @@ # opentelemetry-cpp::trace - Imported target of COMPONENT sdk # opentelemetry-cpp::metrics - Imported target of COMPONENT sdk # opentelemetry-cpp::logs - Imported target of COMPONENT sdk +# opentelemetry-cpp::configuration_core - Imported target of COMPONENT sdk +# opentelemetry-cpp::configuration - Imported target of COMPONENT configuration # opentelemetry-cpp::ext - Imported target of COMPONENT ext_common # opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext_http_curl # opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext_dll @@ -143,6 +154,7 @@ # - **Protobuf** # - **gRPC** # - **prometheus-cpp** +# - **ryml** # - **OpenTracing** # # **Found using the CMake MODULE search mode:** @@ -214,6 +226,7 @@ endforeach() # TRUE if all variables listed contain valid results, e.g. valid file paths. include("FindPackageHandleStandardArgs") +set(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${_REQUESTED_COMPONENTS}) set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE}) find_package_handle_standard_args( From a30f9fb95004d3cf9f47a7cba1943945c5ac6473 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Tue, 21 Jul 2026 14:34:42 -0400 Subject: [PATCH 2/6] update deprecation policy --- docs/deprecation-process.md | 131 ++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/docs/deprecation-process.md b/docs/deprecation-process.md index 81d3e845ce..ce8105671e 100644 --- a/docs/deprecation-process.md +++ b/docs/deprecation-process.md @@ -298,6 +298,137 @@ and will not be impacted by the removal to come. When implementing such logic, document it in the mitigation section, in file `DEPRECATED`. +### CMake package component deprecation + +The installed opentelemetry-cpp CMake package supports the `COMPONENTS` +argument to `find_package(opentelemetry-cpp CONFIG ...)`. +CMake components may need to be deprecated over time. + +There are three cases to distinguish: + +* a component name is changed, +* a component is merged (with all its targets) into another component, +* a component and its targets are deprecated and set for future removal from the + package. + +#### Component name change + +For a component name change, keep the CMake target set unchanged and add the +deprecated name under the `DEPRECATED_NAMES` list. + +Example: + +```cmake +otel_add_component( + COMPONENT component_old_name + TARGETS opentelemetry_some_target) +``` + +The new component receives the new name but must retain the targets unchanged. + +```cmake +otel_add_component( + COMPONENT component_new_name + DEPRECATED_NAMES component_old_name + TARGETS opentelemetry_some_target) +``` + +When a user requests `component_old_name`, the installed package config emits a CMake +deprecation warning and resolves the request to `component_new_name`. + +```cmake +# the following will now resolve `component_old_name` to `component_new_name` +find_package(opentelemetry-cpp CONFIG COMPONENTS component_old_name) +``` + +#### Component merge + +For a component merge, add `component_B` to `component_A`'s +`DEPRECATED_NAMES` list and add `component_B`'s targets to `component_A`'s +`TARGETS` list: + +Example: + +Before the merge, two components are defined. + +```cmake +otel_add_component( + COMPONENT component_A + TARGETS component_A_target) + +otel_add_component( + COMPONENT component_B + TARGETS component_B_target) +``` + +After the merge, `component_B`'s definition is removed. +Its name and targets are added to the deprecated names and targets +for `component_A` respectively. + +```cmake +otel_add_component( + COMPONENT component_A + DEPRECATED_NAMES component_B + TARGETS + component_A_target + component_B_target) +``` + +When a user requests `component_B`, the installed package config emits a CMake +deprecation warning and resolves the request to `component_A` importing +the merged set of targets. + +```cmake +# the following will now resolve deprecated `component_B` to `component_A` +# all targets from the merged component are imported and remain unchanged +find_package(opentelemetry-cpp CONFIG COMPONENTS component_B) + +target_link_libraries(my_library PRIVATE + opentelemetry-cpp::component_A_target + opentelemetry-cpp::component_B_target) +``` + +Note: The set of targets provided by the independent components before merge +and from the merged component must not change. Changing target names risks +breaking the user's CMake configuration. Deprecating and renaming targets +remains a TODO and is currently not supported. + +#### Deprecating a component for removal + +[TODO] This use case is not fully implemented in `otel_add_component` + +When a component and its targets are set for removal from the package, the +component must be marked deprecated with the `DEPRECATED` tag and remain in the +package for a deprecation period. During this time the component and its targets +must be installed with the package and be imported by `find_package`. + +Example: + +```cmake +otel_add_component( + COMPONENT component_to_remove + DEPRECATED + TARGETS component_target + ) +``` + +```cmake +# the following will import the deprecated component's targets and emit a +# CMake deprecation warning +find_package(opentelemetry-cpp CONFIG COMPONENTS component_to_remove) +``` + +#### Validate the deprecated component + +Add the deprecated component name to the `./ci/do_ci.sh` script's +`cmake.install.test` target's `DEPRECATED_COMPONENTS` variable. + +The install test +`./install/test/cmake/usage_tests/deprecated_components` verifies that +requesting deprecated +component names with `find_package` configures successfully and that +CMake emits a deprecation warning. + ### C++ deprecation #### C++ header deprecation From e585b0d9ad31835e02761d7c3a3786ac608827cc Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Thu, 23 Jul 2026 17:25:40 -0400 Subject: [PATCH 3/6] move cmake install function tests to their own sub folder and main cmake file. Add test for component deprecation. Update ci scripts to support running the tests. Add the tests to the cmake.install CI workflow. Address review feedback - set old_component_FOUND when the new name is resolved --- .github/workflows/cmake_install.yml | 20 +++++ ci/do_ci.ps1 | 52 ++++++++++++ ci/do_ci.sh | 36 +++++++++ cmake/find-package-support-functions.cmake | 17 ++++ cmake/otel-install-functions.cmake | 27 +++---- .../opentelemetry-cpp-config.cmake.in | 5 +- install/test/cmake/CMakeLists.txt | 42 ---------- .../install_functions_test/CMakeLists.txt | 79 +++++++++++++++++++ .../components/CMakeLists.txt | 19 +++++ .../components/component_depends.cmake | 27 +++++++ .../components/deprecated_name.cmake | 18 +++++ .../deprecated_name/CMakeLists.txt | 42 ++++++++++ .../missing_components/CMakeLists.txt | 46 +++++++++++ .../no_components/CMakeLists.txt | 8 +- .../unsorted_components/CMakeLists.txt | 46 +++++++++++ .../unsupported_components/CMakeLists.txt | 32 ++++++++ .../missing_components/CMakeLists.txt | 45 ----------- .../unsorted_components/CMakeLists.txt | 46 ----------- .../unsupported_components/CMakeLists.txt | 23 ------ 19 files changed, 458 insertions(+), 172 deletions(-) create mode 100644 install/test/cmake/install_functions_test/CMakeLists.txt create mode 100644 install/test/cmake/install_functions_test/components/CMakeLists.txt create mode 100644 install/test/cmake/install_functions_test/components/component_depends.cmake create mode 100644 install/test/cmake/install_functions_test/components/deprecated_name.cmake create mode 100644 install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt create mode 100644 install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt rename install/test/cmake/{usage_tests => install_functions_test/post_install_tests}/no_components/CMakeLists.txt (78%) create mode 100644 install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt create mode 100644 install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt delete mode 100644 install/test/cmake/usage_tests/missing_components/CMakeLists.txt delete mode 100644 install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt delete mode 100644 install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt diff --git a/.github/workflows/cmake_install.yml b/.github/workflows/cmake_install.yml index 7bc345707f..f770d0dd8c 100644 --- a/.github/workflows/cmake_install.yml +++ b/.github/workflows/cmake_install.yml @@ -29,6 +29,8 @@ jobs: - name: Build dependencies with vcpkg submodule run: | ./ci/setup_windows_ci_environment.ps1 + - name: Run Install Functions Tests + run: ./ci/do_ci.ps1 cmake.install_functions.test - name: Run Tests run: ./ci/do_ci.ps1 cmake.install.test - name: Run DLL Tests @@ -51,6 +53,8 @@ jobs: - name: Build dependencies with vcpkg submodule run: | ./ci/setup_windows_ci_environment.ps1 + - name: Run Install Functions Tests + run: ./ci/do_ci.ps1 cmake.install_functions.test - name: Run Tests run: ./ci/do_ci.ps1 cmake.install.test @@ -78,6 +82,8 @@ jobs: sudo -E apt-get update sudo -E apt-get install -y libabsl-dev libcurl4-openssl-dev zlib1g-dev nlohmann-json3-dev libprotobuf-dev libgrpc++-dev protobuf-compiler protobuf-compiler-grpc sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file third_party_release --packages "googletest;benchmark" + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -108,6 +114,8 @@ jobs: - name: Install Dependencies run: | sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_latest + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -138,6 +146,8 @@ jobs: - name: Install Dependencies run: | sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_stable + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -172,6 +182,8 @@ jobs: - name: Install Dependencies run: | sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_minimum + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -209,6 +221,8 @@ jobs: run: | conan install install/conan/conanfile_stable.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD} conan cache clean --source --build + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -248,6 +262,8 @@ jobs: run: | conan install install/conan/conanfile_latest.txt --build=missing -of /home/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD} conan cache clean --source --build + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -288,6 +304,8 @@ jobs: run: | conan install install/conan/conanfile_stable.txt --build=missing -of /Users/runner/conan -s build_type=${BUILD_TYPE} -s compiler.cppstd=${CXX_STANDARD} conan cache clean --source --build + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' @@ -320,6 +338,8 @@ jobs: brew install grpc brew install nlohmann-json brew install prometheus-cpp + - name: Run Install Functions Tests + run: ./ci/do_ci.sh cmake.install_functions.test - name: Run Tests (static libs) env: BUILD_SHARED_LIBS: 'OFF' diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index eb71804511..7b604ab615 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -472,6 +472,58 @@ switch ($action) { exit 0 } + "cmake.install_functions.test" { + # Test the otel install functions and installed cmake package config + # with mock components injected via OPENTELEMETRY_EXTERNAL_COMPONENT_PATH. + # The package is installed, it then runs cmake configure time tests from + # install/test/cmake/install_functions_test. + Remove-Item -Recurse -Force "$BUILD_DIR\*" + Remove-Item -Recurse -Force "$INSTALL_TEST_DIR\*" + cd "$BUILD_DIR" + + cmake $SRC_DIR ` + -DVCPKG_TARGET_TRIPLET=x64-windows ` + "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" ` + "-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" ` + -DOPENTELEMETRY_INSTALL=ON ` + -DWITH_EXAMPLES=OFF ` + -DBUILD_TESTING=OFF ` + "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=$SRC_DIR\install\test\cmake\install_functions_test\components" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + cmake --build . -j $nproc + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + cmake --build . --target install + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + mkdir "$BUILD_DIR\install_functions_test" + cd "$BUILD_DIR\install_functions_test" + + cmake "-DCMAKE_PREFIX_PATH=$INSTALL_TEST_DIR" ` + -S "$SRC_DIR\install\test\cmake\install_functions_test" + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + ctest -C Debug --output-on-failure + $exit = $LASTEXITCODE + if ($exit -ne 0) { + exit $exit + } + + exit 0 + } "cmake.dll.install.test" { cd "$BUILD_DIR" Remove-Item -Recurse -Force "$BUILD_DIR\*" diff --git a/ci/do_ci.sh b/ci/do_ci.sh index cc825c37f1..3b259dc69b 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -457,6 +457,42 @@ elif [[ "$1" == "cmake.do_not_install.test" ]]; then cmake --build . "${CMAKE_BUILD_ARGS[@]}" ctest --output-on-failure exit 0 +elif [[ "$1" == "cmake.install_functions.test" ]]; then + # Test the otel install functions and installed cmake package config + # with mock components injected via + # OPENTELEMETRY_EXTERNAL_COMPONENT_PATH. The package is installed, it then runs + # cmake configure time tests from install/test/cmake/install_functions_test. + if [[ -n "${BUILD_SHARED_LIBS}" && "${BUILD_SHARED_LIBS}" == "ON" ]]; then + CMAKE_OPTIONS+=("-DBUILD_SHARED_LIBS=ON") + echo "BUILD_SHARED_LIBS is set to: ON" + else + CMAKE_OPTIONS+=("-DBUILD_SHARED_LIBS=OFF") + echo "BUILD_SHARED_LIBS is set to: OFF" + fi + CMAKE_OPTIONS+=("-DCMAKE_POSITION_INDEPENDENT_CODE=ON") + + cd "${BUILD_DIR}" + rm -rf * + rm -rf ${INSTALL_TEST_DIR}/* + + cmake "${CMAKE_OPTIONS[@]}" \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ + -DOPENTELEMETRY_INSTALL=ON \ + -DWITH_EXAMPLES=OFF \ + -DBUILD_TESTING=OFF \ + -DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${SRC_DIR}/install/test/cmake/install_functions_test/components \ + "${SRC_DIR}" + + cmake --build . "${CMAKE_BUILD_ARGS[@]}" + cmake --build . "${CMAKE_BUILD_ARGS[@]}" --target install + export LD_LIBRARY_PATH="${INSTALL_TEST_DIR}/lib:$LD_LIBRARY_PATH" + + mkdir -p "${BUILD_DIR}/install_functions_test" + cd "${BUILD_DIR}/install_functions_test" + cmake "-DCMAKE_PREFIX_PATH=${INSTALL_TEST_DIR}" \ + -S "${SRC_DIR}/install/test/cmake/install_functions_test" + ctest --output-on-failure + exit 0 elif [[ "$1" == "cmake.install.test" ]]; then if [[ -n "${BUILD_SHARED_LIBS}" && "${BUILD_SHARED_LIBS}" == "ON" ]]; then CMAKE_OPTIONS+=("-DBUILD_SHARED_LIBS=ON") diff --git a/cmake/find-package-support-functions.cmake b/cmake/find-package-support-functions.cmake index e6582224ac..2d6d82faf8 100644 --- a/cmake/find-package-support-functions.cmake +++ b/cmake/find-package-support-functions.cmake @@ -27,6 +27,23 @@ function(resolve_deprecated_components requested_components_inout) set(${requested_components_inout} "${_result}" PARENT_SCOPE) endfunction() +#------------------------------------------------------------------------- +# Function to set the __FOUND variable for requested +# deprecated component names that have a replacement component. +#------------------------------------------------------------------------- +function(set_deprecated_components_found requested_components_in) + foreach(_COMPONENT IN LISTS ${requested_components_in}) + if(${_COMPONENT} IN_LIST OTEL_DEPRECATED_COMPONENTS_LIST) + set(_replacement_var "COMPONENT_${_COMPONENT}_REPLACEMENT") + if(DEFINED ${_replacement_var} + AND ${CMAKE_FIND_PACKAGE_NAME}_${${_replacement_var}}_FOUND) + set(${CMAKE_FIND_PACKAGE_NAME}_${_COMPONENT}_FOUND TRUE + CACHE BOOL "whether ${CMAKE_FIND_PACKAGE_NAME} deprecated component ${_COMPONENT} is found (via replacement ${${_replacement_var}})" FORCE) + endif() + endif() + endforeach() +endfunction() + #------------------------------------------------------------------------- # Function to get installed components. #------------------------------------------------------------------------- diff --git a/cmake/otel-install-functions.cmake b/cmake/otel-install-functions.cmake index 4da3685486..3a48e57df9 100644 --- a/cmake/otel-install-functions.cmake +++ b/cmake/otel-install-functions.cmake @@ -322,7 +322,9 @@ endfunction() # Each target is assigned to the component and its dependencies are identified based on the LINK_LIBRARIES property. # An alias target is also created for each target in the form of PROJECT_NAME::TARGET_EXPORT_NAME. # DEPRECATED_NAMES lists old component names that are redirected to this component with a deprecation warning. -# DEPRECATED marks a component that has been fully removed with no replacement (no TARGETS required). +# +# TODO: add a DEPRECATED tag to support deprecated components that are still installed but will be removed in the future. +# # Usage: # otel_add_component( # COMPONENT @@ -331,9 +333,6 @@ endfunction() # [FILES_DIRECTORY # FILES_DESTINATION # FILES_MATCHING ]) -# otel_add_component( -# COMPONENT -# DEPRECATED) #----------------------------------------------------------------------- function(otel_add_component) set(optionArgs DEPRECATED) @@ -345,15 +344,15 @@ function(otel_add_component) message(FATAL_ERROR "otel_add_component: COMPONENT is required") endif() - if(_OTEL_ADD_COMP_DEPRECATED) - # TODO: Support deprecated components that still install their targets, and - # mark those targets deprecated during the deprecation window. - get_property(_deprecated_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) - list(APPEND _deprecated_components "${_OTEL_ADD_COMP_COMPONENT}") - set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST "${_deprecated_components}") - message(DEBUG " DEPRECATED: ${_OTEL_ADD_COMP_COMPONENT} (no replacement)") - return() - endif() + # TODO: Support deprecated components that still install their targets, and mark those targets deprecated during the deprecation window. + # + # if(_OTEL_ADD_COMP_DEPRECATED) + # get_property(_deprecated_components DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST) + # list(APPEND _deprecated_components "${_OTEL_ADD_COMP_COMPONENT}") + # set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY OTEL_DEPRECATED_COMPONENTS_LIST "${_deprecated_components}") + # message(DEBUG " DEPRECATED: ${_OTEL_ADD_COMP_COMPONENT} (no replacement)") + # return() + # endif() if(NOT _OTEL_ADD_COMP_TARGETS) message(FATAL_ERROR "otel_add_component: TARGETS is required") @@ -462,7 +461,7 @@ function(otel_install_components) string(APPEND OTEL_COMPONENTS_REPLACEMENTS_BLOCK "set(COMPONENT_${_DEPRECATED_COMPONENT}_REPLACEMENT ${_REPLACEMENT_COMPONENT})\n") else() - message(STATUS " No replacement installed.") + message(FATAL_ERROR " no DEPRECATED_NAME on an installed component was found for ${_DEPRECATED_COMPONENT} -- deprecating components with no replacement is not currently supported.") endif() endforeach() diff --git a/cmake/templates/opentelemetry-cpp-config.cmake.in b/cmake/templates/opentelemetry-cpp-config.cmake.in index 4a62d36947..db43a99216 100644 --- a/cmake/templates/opentelemetry-cpp-config.cmake.in +++ b/cmake/templates/opentelemetry-cpp-config.cmake.in @@ -206,6 +206,10 @@ foreach(_COMPONENT IN LISTS _REQUESTED_COMPONENTS) CACHE BOOL "whether ${CMAKE_FIND_PACKAGE_NAME} component ${_COMPONENT} is found" FORCE) endforeach() +# set the component found flag for requested deprecated component names +# resolved to an imported replacement component +set_deprecated_components_found(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) + # get installed and requested targets set(_OPENTELEMETRY_CPP_TARGETS "") get_targets(_REQUESTED_COMPONENTS _OPENTELEMETRY_CPP_TARGETS) @@ -226,7 +230,6 @@ endforeach() # TRUE if all variables listed contain valid results, e.g. valid file paths. include("FindPackageHandleStandardArgs") -set(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${_REQUESTED_COMPONENTS}) set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE}) find_package_handle_standard_args( diff --git a/install/test/cmake/CMakeLists.txt b/install/test/cmake/CMakeLists.txt index dfe569bf8f..2e2024b3b0 100644 --- a/install/test/cmake/CMakeLists.txt +++ b/install/test/cmake/CMakeLists.txt @@ -50,48 +50,6 @@ set(INSTALL_TEST_SRC_DIR "${CMAKE_SOURCE_DIR}/../src") enable_testing() -# ----------------------------------------------------------- -# CMake Usage tests for find_package(opentelemetry-cpp ...) -# -# 1. Test find_package with no components specified -# 2. Test find_package with components specified but not sorted in dependency -# order -# 3. Test find_package with components specified but missing dependent components -# 4. Test find_package with components specified but including -# unsupported/unknown components - -add_test( - NAME cmake-usage-no-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/no_components -B - build-cmake-usage-no-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - -add_test( - NAME cmake-usage-unsorted-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/unsorted_components -B - build-cmake-usage-unsorted-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - -add_test( - NAME cmake-usage-missing-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/missing_components -B - build-cmake-usage-missing-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - -add_test( - NAME cmake-usage-unsupported-components-test - COMMAND - ${CMAKE_COMMAND} --log-level=DEBUG -S - ${CMAKE_SOURCE_DIR}/usage_tests/unsupported_components -B - build-cmake-usage-unsupported-components-test - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) - # ----------------------------------------------------------- # Test the full package install using legacy cmake build instructions # find_package(opentelemetry-cpp CONFIG REQUIRED) diff --git a/install/test/cmake/install_functions_test/CMakeLists.txt b/install/test/cmake/install_functions_test/CMakeLists.txt new file mode 100644 index 0000000000..d9fe784aef --- /dev/null +++ b/install/test/cmake/install_functions_test/CMakeLists.txt @@ -0,0 +1,79 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# opentelemetry-cpp CMake Install Functions Tests +# +# These tests cover the CMake install functions defined in +# install/cmake/install_functions.cmake. +# +# The tests require mock components to be added to the opentelemetry-cpp CMake +# project using OPENTELEMETRY_EXTERNAL_COMPONENT_PATH set to import componenents +# from install/test/cmake/install_functions_test/components + +# Usage: ./ci/do_ci.sh cmake.install_functions.test + +cmake_minimum_required(VERSION 3.16) +project(opentelemetry-cpp-install-functions-tests LANGUAGES NONE) + +enable_testing() + +# --------------------------------------------------------------- +# Test find_package with no components specified. All installed components and +# targets must be imported. +# ---------------------------------------------------------------- +add_test( + NAME install-functions-usage-no-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/no_components -B + build-cmake-usage-no-components-test + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${INSTALL_TEST_CMAKE_OPTIONS}) + +# --------------------------------------------------------------- +# Test find_package with a deprecated component name. A deprecation warning must +# be emitted and the replacement component must be imported. +# --------------------------------------------------------------- +add_test( + NAME install-functions-deprecated-name-test + COMMAND + ${CMAKE_COMMAND} -Wdeprecated --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/deprecated_name -B + build-deprecated-name-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") + +set_tests_properties( + install-functions-deprecated-name-test + PROPERTIES PASS_REGULAR_EXPRESSION "CMake Deprecation Warning" + FAIL_REGULAR_EXPRESSION "CMake Error") + +# --------------------------------------------------------------- +# Test find_package component dependency resolution. Unsorted components must be +# imported in the correct order. +# --------------------------------------------------------------- +add_test( + NAME install-functions-unsorted-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/unsorted_components -B + build-unsorted-components-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") + +# --------------------------------------------------------------- +# Test find_package component dependency resolution. Missing dependent +# components must be imported automatically. +# --------------------------------------------------------------- +add_test( + NAME install-functions-missing-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/missing_components -B + build-missing-components-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") + +# --------------------------------------------------------------- +# Test find_package on an unsupported/unknown component +# --------------------------------------------------------------- +add_test( + NAME install-functions-unsupported-components-test + COMMAND + ${CMAKE_COMMAND} --log-level=DEBUG -S + ${CMAKE_SOURCE_DIR}/post_install_tests/unsupported_components -B + build-unsupported-components-test + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") diff --git a/install/test/cmake/install_functions_test/components/CMakeLists.txt b/install/test/cmake/install_functions_test/components/CMakeLists.txt new file mode 100644 index 0000000000..3f781e8a2a --- /dev/null +++ b/install/test/cmake/install_functions_test/components/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Mock components used to test the otel install functions and the installed +# cmake package config machinery. This directory is injected into the +# opentelemetry-cpp build with OPENTELEMETRY_EXTERNAL_COMPONENT_PATH by the +# cmake.install_functions.test CI target. +# +# Each scenario is defined in its own cmake file: deprecated_name.cmake - a +# component with a deprecated name component_depends.cmake - two components with +# an internal dependency +# +# Planned scenarios (not yet implemented): thirdparty_depends.cmake - a +# component with a third-party dependency. Requires an extension point for +# OTEL_THIRDPARTY_DEPENDENCIES_SUPPORTED so external components can register +# additional dependencies. + +include(${CMAKE_CURRENT_LIST_DIR}/deprecated_name.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/component_depends.cmake) diff --git a/install/test/cmake/install_functions_test/components/component_depends.cmake b/install/test/cmake/install_functions_test/components/component_depends.cmake new file mode 100644 index 0000000000..1ebee21812 --- /dev/null +++ b/install/test/cmake/install_functions_test/components/component_depends.cmake @@ -0,0 +1,27 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Scenario: two components with an internal component dependency. +# +# COMPONENT test_component_depends links the target of +# COMPONENT test_component_base. The install functions must record the +# dependency so that consumers requesting only test_component_depends also +# get test_component_base imported automatically and in the correct order. + +add_library(opentelemetry_component_dependency_test_base_target INTERFACE) +set_target_properties(opentelemetry_component_dependency_test_base_target + PROPERTIES EXPORT_NAME test_component_base_target) + +add_library(opentelemetry_test_component_depends INTERFACE) +set_target_properties(opentelemetry_test_component_depends + PROPERTIES EXPORT_NAME test_component_depends_target) +target_link_libraries(opentelemetry_test_component_depends + INTERFACE opentelemetry_component_dependency_test_base_target) + +# Components must be added in dependency order (base first) so the dependency +# lookup in otel_add_component can resolve the base component. +otel_add_component(COMPONENT test_component_base TARGETS + opentelemetry_component_dependency_test_base_target) + +otel_add_component(COMPONENT test_component_depends TARGETS + opentelemetry_test_component_depends) diff --git a/install/test/cmake/install_functions_test/components/deprecated_name.cmake b/install/test/cmake/install_functions_test/components/deprecated_name.cmake new file mode 100644 index 0000000000..eb12e1b7a6 --- /dev/null +++ b/install/test/cmake/install_functions_test/components/deprecated_name.cmake @@ -0,0 +1,18 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Scenario: a component with a deprecated name. +# +# COMPONENT test_component_deprecated is the replacement for the deprecated +# component name test_component_deprecated_v1. Consumers requesting the +# deprecated name via find_package(... COMPONENTS test_component_deprecated_v1) +# must receive the replacement component and a deprecation warning. + +add_library(opentelemetry_deprecation_test_target INTERFACE) +set_target_properties(opentelemetry_deprecation_test_target + PROPERTIES EXPORT_NAME deprecation_test_target) + +otel_add_component( + COMPONENT deprecation_test_component_new + DEPRECATED_NAMES deprecation_test_component_old + TARGETS opentelemetry_deprecation_test_target) diff --git a/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt new file mode 100644 index 0000000000..865110d69e --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: find_package with a deprecated component name. +# +# Requesting the deprecated name must resolve to the replacement component and +# emit a deprecation warning. The parent harness runs this project with +# -Wdeprecated and asserts the "CMake Deprecation Warning" banner with +# PASS_REGULAR_EXPRESSION. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-deprecated-name-test LANGUAGES NONE) + +find_package(opentelemetry-cpp CONFIG REQUIRED + COMPONENTS deprecation_test_component_old) + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with a deprecated component name must set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_deprecation_test_component_old_FOUND) + message( + FATAL_ERROR + "the requested deprecated component name must set opentelemetry-cpp_deprecation_test_component_old_FOUND when its replacement is imported" + ) +endif() + +if(NOT opentelemetry-cpp_deprecation_test_component_new_FOUND) + message( + FATAL_ERROR + "the requested deprecated component name must set opentelemetry-cpp_deprecation_test_component_new_FOUND when its replacement is imported" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::deprecation_test_target) + message( + FATAL_ERROR "opentelemetry-cpp::deprecation_test_target target not imported" + ) +endif() diff --git a/install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt new file mode 100644 index 0000000000..e0df503ff0 --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/missing_components/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: missing dependent components are implicitly resolved. +# +# Only test_component_depends is requested. Its dependency test_component_base +# must be imported automatically. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-missing-components-test LANGUAGES NONE) + +find_package(opentelemetry-cpp CONFIG REQUIRED + COMPONENTS test_component_depends) + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with a missing dependent component must set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_test_component_depends_FOUND) + message( + FATAL_ERROR + "find_package must set opentelemetry-cpp_test_component_depends_FOUND") +endif() + +if(NOT opentelemetry-cpp_test_component_base_FOUND) + message( + FATAL_ERROR + "the implicitly imported dependency component must set opentelemetry-cpp_test_component_base_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_depends_target) + message( + FATAL_ERROR + "opentelemetry-cpp::test_component_depends_target target not imported") +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_base_target) + message( + FATAL_ERROR + "the dependency component target opentelemetry-cpp::test_component_base_target must be imported implicitly" + ) +endif() diff --git a/install/test/cmake/usage_tests/no_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/no_components/CMakeLists.txt similarity index 78% rename from install/test/cmake/usage_tests/no_components/CMakeLists.txt rename to install/test/cmake/install_functions_test/post_install_tests/no_components/CMakeLists.txt index 7e4f092b9f..bfd37915f0 100644 --- a/install/test/cmake/usage_tests/no_components/CMakeLists.txt +++ b/install/test/cmake/install_functions_test/post_install_tests/no_components/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) -project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) +project(opentelemetry-cpp-no-components-install-test LANGUAGES CXX) # specifying no components must import all installed components find_package(opentelemetry-cpp CONFIG REQUIRED) @@ -22,6 +22,12 @@ if(NOT opentelemetry-cpp_FOUND) ) endif() +# Test components added: +set(TEST_COMPONENT_TARGETS + opentelemetry-cpp::test_deprecation_target + opentelemetry-cpp::test_component_base_target + opentelemetry-cpp::test_component_depends_target) + if(NOT TARGET opentelemetry-cpp::api) message(FATAL_ERROR "opentelemetry-cpp::api target not found") endif() diff --git a/install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt new file mode 100644 index 0000000000..dfaa40e9ce --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/unsorted_components/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: components requested out of dependency order. +# +# test_component_depends depends on test_component_base but is listed first. The +# package config must import the components in the correct order without error. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-unsorted-components-test LANGUAGES NONE) + +find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS test_component_depends + test_component_base) + +if(NOT opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_test_component_depends_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_test_component_depends_FOUND" + ) +endif() + +if(NOT opentelemetry-cpp_test_component_base_FOUND) + message( + FATAL_ERROR + "find_package with out of order components must set opentelemetry-cpp_test_component_base_FOUND" + ) +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_base_target) + message( + FATAL_ERROR + "opentelemetry-cpp::test_component_base_target target not imported") +endif() + +if(NOT TARGET opentelemetry-cpp::test_component_depends_target) + message( + FATAL_ERROR + "opentelemetry-cpp::test_component_depends_target target not imported") +endif() diff --git a/install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt new file mode 100644 index 0000000000..d0d3d523b3 --- /dev/null +++ b/install/test/cmake/install_functions_test/post_install_tests/unsupported_components/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Post-install test: an unsupported/unknown component must not be found. + +cmake_minimum_required(VERSION 3.16) +project(otel-install-functions-unsupported-components-test LANGUAGES NONE) + +# request an unsupported/unknown component (without the REQUIRED arg) +find_package(opentelemetry-cpp CONFIG COMPONENTS test_component_base + an_unknown_component) + +if(OPENTELEMETRY_CPP_FOUND) + message( + FATAL_ERROR + "find_package with an unsupported component must not set OPENTELEMETRY_CPP_FOUND" + ) +endif() + +if(opentelemetry-cpp_FOUND) + message( + FATAL_ERROR + "find_package with an unsupported component must not set opentelemetry-cpp_FOUND" + ) +endif() + +if(opentelemetry-cpp_an_unknown_component_FOUND) + message( + FATAL_ERROR + "an unsupported component must not set opentelemetry-cpp_an_unknown_component_FOUND" + ) +endif() diff --git a/install/test/cmake/usage_tests/missing_components/CMakeLists.txt b/install/test/cmake/usage_tests/missing_components/CMakeLists.txt deleted file mode 100644 index 0f123511ad..0000000000 --- a/install/test/cmake/usage_tests/missing_components/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.16) - -project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) - -# Any missing component dependencies must be implicitly resolved. This tests -# implicitly resolves the sdk component dependency -find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS api - exporters_in_memory) - -if(NOT OPENTELEMETRY_CPP_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_exporters_in_memory_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_exporters_in_memory_FOUND" - ) -endif() - -if(NOT TARGET opentelemetry-cpp::api) - message(FATAL_ERROR "opentelemetry-cpp::api target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::sdk) - message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::in_memory_span_exporter) - message( - FATAL_ERROR "opentelemetry-cpp::in_memory_span_exporter target not found") -endif() diff --git a/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt deleted file mode 100644 index 7eb7465043..0000000000 --- a/install/test/cmake/usage_tests/unsorted_components/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.16) - -project(opentelemetry-cpp-unsorted-components-install-test LANGUAGES CXX) - -# components not provided in order of dependency must be imported in the correct -# order without error -find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_ostream api - sdk) - -if(NOT OPENTELEMETRY_CPP_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set OPENTELEMETRY_CPP_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_FOUND" - ) -endif() - -if(NOT opentelemetry-cpp_exporters_ostream_FOUND) - message( - FATAL_ERROR - "calling find_package with out of order components must import the components and set opentelemetry-cpp_exporters_ostream_FOUND" - ) -endif() - -if(NOT TARGET opentelemetry-cpp::api) - message(FATAL_ERROR "opentelemetry-cpp::api target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::sdk) - message(FATAL_ERROR "opentelemetry-cpp::sdk target not found") -endif() - -if(NOT TARGET opentelemetry-cpp::ostream_log_record_exporter) - message( - FATAL_ERROR - "opentelemetry-cpp::ostream_log_record_exporter target not found") -endif() diff --git a/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt b/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt deleted file mode 100644 index f799f4850b..0000000000 --- a/install/test/cmake/usage_tests/unsupported_components/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.16) - -project(opentelemetry-cpp-unsupported-components-install-test LANGUAGES CXX) - -# request an unsupported/unknown component (without the REQUIRED arg) -find_package(opentelemetry-cpp CONFIG COMPONENTS api an_unknown_component) - -if(OPENTELEMETRY_CPP_FOUND) - message( - FATAL_ERROR - "calling find_package with an unsuported component should not set OPENTELEMETRY_CPP_FOUND" - ) -endif() - -if(opentelemetry-cpp_FOUND) - message( - FATAL_ERROR - "calling find_package with an unsupported component should not set opentelemetry-cpp_FOUND" - ) -endif() From 84199e27dab1b6b4ca2d4457583833838b1d9ea8 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Thu, 23 Jul 2026 20:44:29 -0400 Subject: [PATCH 4/6] explicitly disable all extra componenents and tests --- ci/do_ci.ps1 | 8 +++++--- ci/do_ci.sh | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 7b604ab615..1fe875e49f 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -486,9 +486,11 @@ switch ($action) { "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake" ` "-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" ` -DOPENTELEMETRY_INSTALL=ON ` - -DWITH_EXAMPLES=OFF ` - -DBUILD_TESTING=OFF ` - "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=$SRC_DIR\install\test\cmake\install_functions_test\components" + "-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=$SRC_DIR\install\test\cmake\install_functions_test\components" ` + -DENABLE_EXAMPLES=OFF ` + -DENABLE_TESTS=OFF ` + -DENABLE_COMPONENTS=OFF ` + "-C $SRC_DIR/test_common/cmake/all-options-abiv1-preview.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 3b259dc69b..d9959b1fe9 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -478,9 +478,11 @@ elif [[ "$1" == "cmake.install_functions.test" ]]; then cmake "${CMAKE_OPTIONS[@]}" \ -DCMAKE_INSTALL_PREFIX=${INSTALL_TEST_DIR} \ -DOPENTELEMETRY_INSTALL=ON \ - -DWITH_EXAMPLES=OFF \ - -DBUILD_TESTING=OFF \ -DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${SRC_DIR}/install/test/cmake/install_functions_test/components \ + -DENABLE_COMPONENTS=OFF \ + -DENABLE_EXAMPLES=OFF \ + -DENABLE_TESTS=OFF \ + -C ${SRC_DIR}/test_common/cmake/all-options-abiv1-preview.cmake \ "${SRC_DIR}" cmake --build . "${CMAKE_BUILD_ARGS[@]}" From 47a21c1d9f0cb321cfe44b49137801d0ff2bc830 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Thu, 23 Jul 2026 21:14:48 -0400 Subject: [PATCH 5/6] disable preview options that bring in ryml --- ci/do_ci.ps1 | 3 ++- ci/do_ci.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 1fe875e49f..136f4a4883 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -490,7 +490,8 @@ switch ($action) { -DENABLE_EXAMPLES=OFF ` -DENABLE_TESTS=OFF ` -DENABLE_COMPONENTS=OFF ` - "-C $SRC_DIR/test_common/cmake/all-options-abiv1-preview.cmake" + -DENABLE_PREVIEW=OFF ` + "-C $SRC_DIR/test_common/cmake/all-options-abiv1.cmake" $exit = $LASTEXITCODE if ($exit -ne 0) { exit $exit diff --git a/ci/do_ci.sh b/ci/do_ci.sh index d9959b1fe9..351b977826 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -482,7 +482,8 @@ elif [[ "$1" == "cmake.install_functions.test" ]]; then -DENABLE_COMPONENTS=OFF \ -DENABLE_EXAMPLES=OFF \ -DENABLE_TESTS=OFF \ - -C ${SRC_DIR}/test_common/cmake/all-options-abiv1-preview.cmake \ + -DENABLE_PREVIEW=OFF \ + -C ${SRC_DIR}/test_common/cmake/all-options-abiv1.cmake \ "${SRC_DIR}" cmake --build . "${CMAKE_BUILD_ARGS[@]}" From 72cdd8853772a26be961865686142e5a5a5a579b Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 24 Jul 2026 17:11:25 -0400 Subject: [PATCH 6/6] remove check on the deprecation message. Newer versions of CMake have changed the structure of the message. --- install/test/cmake/install_functions_test/CMakeLists.txt | 5 ----- .../post_install_tests/deprecated_name/CMakeLists.txt | 4 +--- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/install/test/cmake/install_functions_test/CMakeLists.txt b/install/test/cmake/install_functions_test/CMakeLists.txt index d9fe784aef..b7724b1f9d 100644 --- a/install/test/cmake/install_functions_test/CMakeLists.txt +++ b/install/test/cmake/install_functions_test/CMakeLists.txt @@ -40,11 +40,6 @@ add_test( ${CMAKE_SOURCE_DIR}/post_install_tests/deprecated_name -B build-deprecated-name-test "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") -set_tests_properties( - install-functions-deprecated-name-test - PROPERTIES PASS_REGULAR_EXPRESSION "CMake Deprecation Warning" - FAIL_REGULAR_EXPRESSION "CMake Error") - # --------------------------------------------------------------- # Test find_package component dependency resolution. Unsorted components must be # imported in the correct order. diff --git a/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt b/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt index 865110d69e..5cfee589c0 100644 --- a/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt +++ b/install/test/cmake/install_functions_test/post_install_tests/deprecated_name/CMakeLists.txt @@ -4,9 +4,7 @@ # Post-install test: find_package with a deprecated component name. # # Requesting the deprecated name must resolve to the replacement component and -# emit a deprecation warning. The parent harness runs this project with -# -Wdeprecated and asserts the "CMake Deprecation Warning" banner with -# PASS_REGULAR_EXPRESSION. +# emit a deprecation warning. cmake_minimum_required(VERSION 3.16) project(otel-install-functions-deprecated-name-test LANGUAGES NONE)