diff --git a/CMakeLists.txt b/CMakeLists.txt index d7f6049ef9..bfe0071498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,6 +275,10 @@ if(WITH_EXAMPLES_HTTP AND NOT WITH_EXAMPLES) message(FATAL_ERROR "WITH_EXAMPLES_HTTP=ON requires WITH_EXAMPLES=ON") endif() +if(WITH_GSL) + include("${opentelemetry-cpp_SOURCE_DIR}/cmake/ms-gsl.cmake") +endif() + find_package(Threads) function(set_target_version target_name) @@ -635,7 +639,9 @@ message(STATUS "CMake: ${CMAKE_VERSION}") message(STATUS "GTest: ${GTest_VERSION} (${GTest_PROVIDER})") message(STATUS "benchmark: ${benchmark_VERSION} (${benchmark_PROVIDER})") if(WITH_GSL) - message(STATUS "GSL: ${GSL_VERSION}") + message( + STATUS "Microsoft.GSL: ${Microsoft.GSL_VERSION} (${Microsoft.GSL_PROVIDER})" + ) endif() if(absl_FOUND) message(STATUS "Abseil: ${absl_VERSION}") diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 8430a52250..48c9098eaa 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -9,22 +9,7 @@ target_include_directories( set_target_properties(opentelemetry_api PROPERTIES EXPORT_NAME api) -otel_add_component( - COMPONENT - api - TARGETS - opentelemetry_api - FILES_DIRECTORY - "include/opentelemetry" - FILES_DESTINATION - "include" - FILES_MATCHING - PATTERN - "*.h") - -if(OPENTELEMETRY_INSTALL) - unset(TARGET_DEPS) -endif() +unset(TARGET_DEPS) if(BUILD_TESTING) add_subdirectory(test) @@ -74,18 +59,8 @@ endif() if(WITH_GSL) target_compile_definitions(opentelemetry_api INTERFACE HAVE_GSL) - - # Guidelines Support Library path. Used if we are not on not get C++20. - # - find_package(Microsoft.GSL QUIET) - if(TARGET Microsoft.GSL::GSL) - target_link_libraries(opentelemetry_api INTERFACE Microsoft.GSL::GSL) - list(APPEND TARGET_DEPS "gsl") - else() - set(GSL_DIR third_party/ms-gsl) - target_include_directories( - opentelemetry_api INTERFACE "$") - endif() + target_link_libraries(opentelemetry_api INTERFACE Microsoft.GSL::GSL) + list(APPEND TARGET_DEPS "gsl") endif() if(WITH_NO_GETENV) @@ -140,6 +115,19 @@ if(APPLE) target_link_libraries(opentelemetry_api INTERFACE "-framework CoreFoundation") endif() +otel_add_component( + COMPONENT + api + TARGETS + opentelemetry_api + FILES_DIRECTORY + "include/opentelemetry" + FILES_DESTINATION + "include" + FILES_MATCHING + PATTERN + "*.h") + include(${PROJECT_SOURCE_DIR}/cmake/pkgconfig.cmake) if(OPENTELEMETRY_INSTALL) diff --git a/ci/do_ci.ps1 b/ci/do_ci.ps1 index 42dd1c0140..0b21bbd866 100644 --- a/ci/do_ci.ps1 +++ b/ci/do_ci.ps1 @@ -344,6 +344,7 @@ switch ($action) { "-DCMAKE_INSTALL_PREFIX=$INSTALL_TEST_DIR" ` -DWITH_ABI_VERSION_1=OFF ` -DWITH_ABI_VERSION_2=ON ` + -DWITH_GSL=ON ` -DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON ` -DWITH_METRICS_EXEMPLAR_PREVIEW=ON ` -DWITH_ASYNC_EXPORT_PREVIEW=ON ` diff --git a/cmake/ms-gsl.cmake b/cmake/ms-gsl.cmake new file mode 100644 index 0000000000..72c157a627 --- /dev/null +++ b/cmake/ms-gsl.cmake @@ -0,0 +1,35 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +find_package(Microsoft.GSL CONFIG QUIET) +set(Microsoft.GSL_PROVIDER "find_package") + +if(NOT Microsoft.GSL_FOUND) + set(_Microsoft.GSL_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/ms-gsl") + if(EXISTS "${_Microsoft.GSL_SUBMODULE_DIR}/.git") + FetchContent_Declare( + "gsl" + SOURCE_DIR "${_Microsoft.GSL_SUBMODULE_DIR}" + ) + set(Microsoft.GSL_PROVIDER "fetch_source") + else() + FetchContent_Declare( + "gsl" + GIT_REPOSITORY "https://github.com/microsoft/GSL.git" + GIT_TAG "${ms-gsl_GIT_TAG}" + ) + set(Microsoft.GSL_PROVIDER "fetch_repository") + endif() + + set(GSL_TEST OFF CACHE BOOL "" FORCE) + set(GSL_INSTALL ${OPENTELEMETRY_INSTALL} CACHE BOOL "" FORCE) + + FetchContent_MakeAvailable(gsl) + + # Set the Microsoft.GSL_VERSION variable from the git tag. + string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" Microsoft.GSL_VERSION "${ms-gsl_GIT_TAG}") +endif() + +if(NOT TARGET Microsoft.GSL::GSL) + message(FATAL_ERROR "A required Microsoft.GSL target Microsoft.GSL::GSL was not imported") +endif() diff --git a/cmake/thirdparty-dependency-config.cmake b/cmake/thirdparty-dependency-config.cmake index 046e3a540f..42242b0aa8 100644 --- a/cmake/thirdparty-dependency-config.cmake +++ b/cmake/thirdparty-dependency-config.cmake @@ -8,6 +8,7 @@ #----------------------------------------------------------------------- set(OTEL_THIRDPARTY_DEPENDENCIES_SUPPORTED Threads + Microsoft.GSL ZLIB CURL nlohmann_json @@ -29,6 +30,7 @@ set(OTEL_Protobuf_TARGET_NAMESPACE "protobuf") # # set(OTEL__SEARCH_MODE "") #----------------------------------------------------------------------- set(OTEL_Threads_SEARCH_MODE "") +set(OTEL_Microsoft.GSL_SEARCH_MODE "CONFIG") set(OTEL_ZLIB_SEARCH_MODE "") set(OTEL_CURL_SEARCH_MODE "") set(OTEL_nlohmann_json_SEARCH_MODE "CONFIG")