From e307e6292b81d0d80a0df2a36de6b9da4ba2cc38 Mon Sep 17 00:00:00 2001 From: owent Date: Sat, 16 Dec 2023 02:00:09 +0800 Subject: [PATCH 1/4] Skip patch alias target --- cmake/tools.cmake | 412 ++++++++++++++++++++++++---------------------- 1 file changed, 213 insertions(+), 199 deletions(-) diff --git a/cmake/tools.cmake b/cmake/tools.cmake index ee191121ca..4e82fed49f 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -1,199 +1,213 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -macro(check_append_cxx_compiler_flag OUTPUT_VAR) - foreach(CHECK_FLAG ${ARGN}) - check_cxx_compiler_flag(${CHECK_FLAG} - "check_cxx_compiler_flag_${CHECK_FLAG}") - if(check_cxx_compiler_flag_${CHECK_FLAG}) - list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG}) - endif() - endforeach() -endmacro() - -if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET) - if(MSVC) - unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) - set(PATCH_PROTOBUF_SOURCES_OPTIONS /wd4244 /wd4251 /wd4267 /wd4309 /wd4668 /wd4946 /wd6001 /wd6244 /wd6246) - - if(MSVC_VERSION GREATER_EQUAL 1922) - # see - # https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162 - # for detail - list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054) - endif() - - if(MSVC_VERSION GREATER_EQUAL 1925) - list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996) - endif() - - if(MSVC_VERSION LESS 1910) - list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800) - endif() - else() - unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) - include(CheckCXXCompilerFlag) - check_append_cxx_compiler_flag( - PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits - -Wno-deprecated-declarations -Wno-unused-parameter) - endif() - set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE) - if(PATCH_PROTOBUF_SOURCES_OPTIONS) - set(PATCH_PROTOBUF_SOURCES_OPTIONS - ${PATCH_PROTOBUF_SOURCES_OPTIONS} - CACHE INTERNAL - "Options to disable warning of generated protobuf sources" FORCE) - endif() -endif() - -function(patch_protobuf_sources) - if(PATCH_PROTOBUF_SOURCES_OPTIONS) - foreach(PROTO_SRC ${ARGN}) - unset(PROTO_SRC_OPTIONS) - get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS) - if(PROTO_SRC_OPTIONS) - list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - else() - set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - endif() - - set_source_files_properties( - ${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}") - endforeach() - unset(PROTO_SRC) - unset(PROTO_SRC_OPTIONS) - endif() -endfunction() - -function(patch_protobuf_targets) - if(PATCH_PROTOBUF_SOURCES_OPTIONS) - foreach(PROTO_TARGET ${ARGN}) - unset(PROTO_TARGET_OPTIONS) - get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS) - if(PROTO_TARGET_OPTIONS) - list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - else() - set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - endif() - - set_target_properties( - ${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}") - endforeach() - unset(PROTO_TARGET) - unset(PROTO_TARGET_OPTIONS) - endif() -endfunction() - -function(project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME) - if(CMAKE_BUILD_TYPE) - string(TOUPPER "IMPORTED_LOCATION_${CMAKE_BUILD_TYPE}" - TRY_SPECIFY_IMPORTED_LOCATION) - get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} - ${TRY_SPECIFY_IMPORTED_LOCATION}) - endif() - if(NOT ${OUTPUT_VAR_NAME}) - get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} IMPORTED_LOCATION) - endif() - if(NOT ${OUTPUT_VAR_NAME}) - get_target_property( - project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS - ${TARGET_NAME} IMPORTED_CONFIGURATIONS) - foreach( - project_build_tools_get_imported_location_IMPORTED_CONFIGURATION IN - LISTS project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS) - get_target_property( - ${OUTPUT_VAR_NAME} - ${TARGET_NAME} - "IMPORTED_LOCATION_${project_build_tools_get_imported_location_IMPORTED_CONFIGURATION}" - ) - if(${OUTPUT_VAR_NAME}) - break() - endif() - endforeach() - endif() - if(${OUTPUT_VAR_NAME}) - set(${OUTPUT_VAR_NAME} - ${${OUTPUT_VAR_NAME}} - PARENT_SCOPE) - endif() -endfunction() - -#[[ -If we build third party packages with a different CONFIG setting from building -otel-cpp, cmake may not find a suitable file in imported targets (#705, #1359) -when linking. But on some platforms, different CONFIG settings can be used when -these CONFIG settings have the same ABI. For example, on Linux, we can build -gRPC and protobuf with -DCMAKE_BUILD_TYPE=Release, but build otel-cpp with --DCMAKE_BUILD_TYPE=Debug and link these libraries together. -The properties of imported targets can be found here: -https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets -]] -function(project_build_tools_patch_default_imported_config) - set(PATCH_VARS - IMPORTED_IMPLIB - IMPORTED_LIBNAME - IMPORTED_LINK_DEPENDENT_LIBRARIES - IMPORTED_LINK_INTERFACE_LANGUAGES - IMPORTED_LINK_INTERFACE_LIBRARIES - IMPORTED_LINK_INTERFACE_MULTIPLICITY - IMPORTED_LOCATION - IMPORTED_NO_SONAME - IMPORTED_OBJECTS - IMPORTED_SONAME) - foreach(TARGET_NAME ${ARGN}) - if(TARGET ${TARGET_NAME}) - get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED) - if(NOT IS_IMPORTED_TARGET) - continue() - endif() - - if(CMAKE_VERSION VERSION_LESS "3.19.0") - get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE) - if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY") - continue() - endif() - endif() - - get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION) - if(DO_NOT_OVERWRITE) - continue() - endif() - - # MSVC's STL and debug level must match the target, so we can only move - # out IMPORTED_LOCATION_NOCONFIG - if(MSVC) - set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG") - else() - get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME} - IMPORTED_CONFIGURATIONS) - endif() - - if(NOT PATCH_IMPORTED_CONFIGURATION) - continue() - endif() - - get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME} - "IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}") - if(NOT PATCH_TARGET_LOCATION) - continue() - endif() - - foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS) - get_target_property( - PATCH_IMPORTED_VALUE ${TARGET_NAME} - "${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}") - if(PATCH_IMPORTED_VALUE) - set_target_properties( - ${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}" - "${PATCH_IMPORTED_VALUE}") - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - message( - STATUS - "Patch: ${TARGET_NAME} ${PATCH_IMPORTED_KEY} will use ${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}(\"${PATCH_IMPORTED_VALUE}\") by default." - ) - endif() - endif() - endforeach() - endif() - endforeach() -endfunction() +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +macro(check_append_cxx_compiler_flag OUTPUT_VAR) + foreach(CHECK_FLAG ${ARGN}) + check_cxx_compiler_flag(${CHECK_FLAG} + "check_cxx_compiler_flag_${CHECK_FLAG}") + if(check_cxx_compiler_flag_${CHECK_FLAG}) + list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG}) + endif() + endforeach() +endmacro() + +if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET) + if(MSVC) + unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) + set(PATCH_PROTOBUF_SOURCES_OPTIONS + /wd4244 + /wd4251 + /wd4267 + /wd4309 + /wd4668 + /wd4946 + /wd6001 + /wd6244 + /wd6246) + + if(MSVC_VERSION GREATER_EQUAL 1922) + # see + # https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162 + # for detail + list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054) + endif() + + if(MSVC_VERSION GREATER_EQUAL 1925) + list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996) + endif() + + if(MSVC_VERSION LESS 1910) + list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800) + endif() + else() + unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) + include(CheckCXXCompilerFlag) + check_append_cxx_compiler_flag( + PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits + -Wno-deprecated-declarations -Wno-unused-parameter) + endif() + set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE) + if(PATCH_PROTOBUF_SOURCES_OPTIONS) + set(PATCH_PROTOBUF_SOURCES_OPTIONS + ${PATCH_PROTOBUF_SOURCES_OPTIONS} + CACHE INTERNAL + "Options to disable warning of generated protobuf sources" FORCE) + endif() +endif() + +function(patch_protobuf_sources) + if(PATCH_PROTOBUF_SOURCES_OPTIONS) + foreach(PROTO_SRC ${ARGN}) + unset(PROTO_SRC_OPTIONS) + get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS) + if(PROTO_SRC_OPTIONS) + list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + else() + set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + endif() + + set_source_files_properties( + ${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}") + endforeach() + unset(PROTO_SRC) + unset(PROTO_SRC_OPTIONS) + endif() +endfunction() + +function(patch_protobuf_targets) + if(PATCH_PROTOBUF_SOURCES_OPTIONS) + foreach(PROTO_TARGET ${ARGN}) + unset(PROTO_TARGET_OPTIONS) + get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS) + if(PROTO_TARGET_OPTIONS) + list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + else() + set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + endif() + + set_target_properties( + ${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}") + endforeach() + unset(PROTO_TARGET) + unset(PROTO_TARGET_OPTIONS) + endif() +endfunction() + +function(project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME) + if(CMAKE_BUILD_TYPE) + string(TOUPPER "IMPORTED_LOCATION_${CMAKE_BUILD_TYPE}" + TRY_SPECIFY_IMPORTED_LOCATION) + get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} + ${TRY_SPECIFY_IMPORTED_LOCATION}) + endif() + if(NOT ${OUTPUT_VAR_NAME}) + get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} IMPORTED_LOCATION) + endif() + if(NOT ${OUTPUT_VAR_NAME}) + get_target_property( + project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS + ${TARGET_NAME} IMPORTED_CONFIGURATIONS) + foreach( + project_build_tools_get_imported_location_IMPORTED_CONFIGURATION IN + LISTS project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS) + get_target_property( + ${OUTPUT_VAR_NAME} + ${TARGET_NAME} + "IMPORTED_LOCATION_${project_build_tools_get_imported_location_IMPORTED_CONFIGURATION}" + ) + if(${OUTPUT_VAR_NAME}) + break() + endif() + endforeach() + endif() + if(${OUTPUT_VAR_NAME}) + set(${OUTPUT_VAR_NAME} + ${${OUTPUT_VAR_NAME}} + PARENT_SCOPE) + endif() +endfunction() + +#[[ +If we build third party packages with a different CONFIG setting from building +otel-cpp, cmake may not find a suitable file in imported targets (#705, #1359) +when linking. But on some platforms, different CONFIG settings can be used when +these CONFIG settings have the same ABI. For example, on Linux, we can build +gRPC and protobuf with -DCMAKE_BUILD_TYPE=Release, but build otel-cpp with +-DCMAKE_BUILD_TYPE=Debug and link these libraries together. +The properties of imported targets can be found here: +https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets +]] +function(project_build_tools_patch_default_imported_config) + set(PATCH_VARS + IMPORTED_IMPLIB + IMPORTED_LIBNAME + IMPORTED_LINK_DEPENDENT_LIBRARIES + IMPORTED_LINK_INTERFACE_LANGUAGES + IMPORTED_LINK_INTERFACE_LIBRARIES + IMPORTED_LINK_INTERFACE_MULTIPLICITY + IMPORTED_LOCATION + IMPORTED_NO_SONAME + IMPORTED_OBJECTS + IMPORTED_SONAME) + foreach(TARGET_NAME ${ARGN}) + if(TARGET ${TARGET_NAME}) + get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED) + if(NOT IS_IMPORTED_TARGET) + continue() + endif() + + get_target_property(IS_ALIAS_TARGET ${TARGET_NAME} ALIASED_TARGET) + if(IS_ALIAS_TARGET) + continue() + endif() + + if(CMAKE_VERSION VERSION_LESS "3.19.0") + get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE) + if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY") + continue() + endif() + endif() + + get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION) + if(DO_NOT_OVERWRITE) + continue() + endif() + + # MSVC's STL and debug level must match the target, so we can only move + # out IMPORTED_LOCATION_NOCONFIG + if(MSVC) + set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG") + else() + get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME} + IMPORTED_CONFIGURATIONS) + endif() + + if(NOT PATCH_IMPORTED_CONFIGURATION) + continue() + endif() + + get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME} + "IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}") + if(NOT PATCH_TARGET_LOCATION) + continue() + endif() + + foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS) + get_target_property( + PATCH_IMPORTED_VALUE ${TARGET_NAME} + "${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}") + if(PATCH_IMPORTED_VALUE) + set_target_properties( + ${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}" + "${PATCH_IMPORTED_VALUE}") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + message( + STATUS + "Patch: ${TARGET_NAME} ${PATCH_IMPORTED_KEY} will use ${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}(\"${PATCH_IMPORTED_VALUE}\") by default." + ) + endif() + endif() + endforeach() + endif() + endforeach() +endfunction() From bf58cb13b2b9ca7e5a45a7a11b370227ecbdb062 Mon Sep 17 00:00:00 2001 From: owent Date: Sat, 16 Dec 2023 02:05:23 +0800 Subject: [PATCH 2/4] Patch new targets of curl for cmake Patch CURL::libcurl_static and CURL::libcurl_shared --- cmake/patch-imported-config.cmake | 285 +++++++++++++++--------------- 1 file changed, 144 insertions(+), 141 deletions(-) diff --git a/cmake/patch-imported-config.cmake b/cmake/patch-imported-config.cmake index ec68d74099..fe3e88b3ad 100644 --- a/cmake/patch-imported-config.cmake +++ b/cmake/patch-imported-config.cmake @@ -1,141 +1,144 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -# Some prebuilt or installed targets may have different CONFIG settings than -# what we use to configure otel-cpp. This file applies patches to the imported -# targets in order to use compatible CONFIG settings for fallback. - -# Common dependencies -project_build_tools_patch_default_imported_config(ZLIB::ZLIB) - -# protobuf targets -if(Protobuf_FOUND OR PROTOBUF_FOUND) - project_build_tools_patch_default_imported_config( - utf8_range::utf8_range utf8_range::utf8_validity protobuf::libprotobuf-lite - protobuf::libprotobuf protobuf::libprotoc) -endif() - -# cares targets -if(TARGET c-ares::cares) - project_build_tools_patch_default_imported_config(c-ares::cares) -endif() - -# curl targets -if(TARGET CURL::libcurl) - project_build_tools_patch_default_imported_config(CURL::libcurl) -endif() - -# abseil targets -if(WITH_ABSEIL) - project_build_tools_patch_default_imported_config( - absl::bad_variant_access - absl::raw_logging_internal - absl::log_severity - absl::log_internal_check_op - absl::log_internal_nullguard - absl::strings - absl::strings_internal - absl::base - absl::spinlock_wait - absl::int128 - absl::throw_delegate - absl::log_internal_message - absl::examine_stack - absl::stacktrace - absl::debugging_internal - absl::symbolize - absl::demangle_internal - absl::malloc_internal - absl::log_internal_format - absl::log_internal_globals - absl::time - absl::civil_time - absl::time_zone - absl::str_format_internal - absl::log_internal_proto - absl::log_internal_log_sink_set - absl::log_globals - absl::hash - absl::city - absl::bad_optional_access - absl::low_level_hash - absl::log_entry - absl::log_sink - absl::synchronization - absl::graphcycles_internal - absl::strerror - absl::log_internal_conditions - absl::cord - absl::cord_internal - absl::crc_cord_state - absl::crc32c - absl::crc_cpu_detect - absl::crc_internal - absl::cordz_functions - absl::exponential_biased - absl::cordz_info - absl::cordz_handle - absl::leak_check - absl::die_if_null - absl::flags - absl::flags_commandlineflag - absl::flags_commandlineflag_internal - absl::flags_config - absl::flags_program_name - absl::flags_internal - absl::flags_marshalling - absl::flags_reflection - absl::flags_private_handle_accessor - absl::raw_hash_set - absl::hashtablez_sampler - absl::log_initialize - absl::status - absl::statusor) -endif() - -# gRPC targets -if(TARGET gRPC::grpc++) - project_build_tools_patch_default_imported_config( - gRPC::cares - gRPC::re2 - gRPC::ssl - gRPC::crypto - gRPC::zlibstatic - gRPC::address_sorting - gRPC::gpr - gRPC::grpc - gRPC::grpc_unsecure - gRPC::grpc++ - gRPC::grpc++_alts - gRPC::grpc++_error_details - gRPC::grpc++_reflection - gRPC::grpc++_unsecure - gRPC::grpc_authorization_provider - gRPC::grpc_plugin_support - gRPC::grpcpp_channelz - gRPC::upb) -endif() - -# prometheus targets -if(TARGET prometheus-cpp::core) - project_build_tools_patch_default_imported_config( - prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push) -endif() - -# civetweb targets -if(TARGET civetweb::civetweb) - project_build_tools_patch_default_imported_config( - civetweb::civetweb civetweb::server civetweb::civetweb-cpp) -endif() - -if(BUILD_TESTING) - project_build_tools_patch_default_imported_config( - GTest::gtest - GTest::gtest_main - GTest::gmock - GTest::gmock_main - GTest::GTest - GTest::Main - benchmark::benchmark - benchmark::benchmark_main) -endif() +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Some prebuilt or installed targets may have different CONFIG settings than +# what we use to configure otel-cpp. This file applies patches to the imported +# targets in order to use compatible CONFIG settings for fallback. + +# Common dependencies +project_build_tools_patch_default_imported_config(ZLIB::ZLIB) + +# protobuf targets +if(Protobuf_FOUND OR PROTOBUF_FOUND) + project_build_tools_patch_default_imported_config( + utf8_range::utf8_range utf8_range::utf8_validity protobuf::libprotobuf-lite + protobuf::libprotobuf protobuf::libprotoc) +endif() + +# cares targets +if(TARGET c-ares::cares) + project_build_tools_patch_default_imported_config(c-ares::cares) +endif() + +# curl targets +if(TARGET CURL::libcurl + OR TARGET CURL::libcurl_static + OR TARGET CURL::libcurl_shared) + project_build_tools_patch_default_imported_config( + CURL::libcurl CURL::libcurl_static CURL::libcurl_shared) +endif() + +# abseil targets +if(WITH_ABSEIL) + project_build_tools_patch_default_imported_config( + absl::bad_variant_access + absl::raw_logging_internal + absl::log_severity + absl::log_internal_check_op + absl::log_internal_nullguard + absl::strings + absl::strings_internal + absl::base + absl::spinlock_wait + absl::int128 + absl::throw_delegate + absl::log_internal_message + absl::examine_stack + absl::stacktrace + absl::debugging_internal + absl::symbolize + absl::demangle_internal + absl::malloc_internal + absl::log_internal_format + absl::log_internal_globals + absl::time + absl::civil_time + absl::time_zone + absl::str_format_internal + absl::log_internal_proto + absl::log_internal_log_sink_set + absl::log_globals + absl::hash + absl::city + absl::bad_optional_access + absl::low_level_hash + absl::log_entry + absl::log_sink + absl::synchronization + absl::graphcycles_internal + absl::strerror + absl::log_internal_conditions + absl::cord + absl::cord_internal + absl::crc_cord_state + absl::crc32c + absl::crc_cpu_detect + absl::crc_internal + absl::cordz_functions + absl::exponential_biased + absl::cordz_info + absl::cordz_handle + absl::leak_check + absl::die_if_null + absl::flags + absl::flags_commandlineflag + absl::flags_commandlineflag_internal + absl::flags_config + absl::flags_program_name + absl::flags_internal + absl::flags_marshalling + absl::flags_reflection + absl::flags_private_handle_accessor + absl::raw_hash_set + absl::hashtablez_sampler + absl::log_initialize + absl::status + absl::statusor) +endif() + +# gRPC targets +if(TARGET gRPC::grpc++) + project_build_tools_patch_default_imported_config( + gRPC::cares + gRPC::re2 + gRPC::ssl + gRPC::crypto + gRPC::zlibstatic + gRPC::address_sorting + gRPC::gpr + gRPC::grpc + gRPC::grpc_unsecure + gRPC::grpc++ + gRPC::grpc++_alts + gRPC::grpc++_error_details + gRPC::grpc++_reflection + gRPC::grpc++_unsecure + gRPC::grpc_authorization_provider + gRPC::grpc_plugin_support + gRPC::grpcpp_channelz + gRPC::upb) +endif() + +# prometheus targets +if(TARGET prometheus-cpp::core) + project_build_tools_patch_default_imported_config( + prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push) +endif() + +# civetweb targets +if(TARGET civetweb::civetweb) + project_build_tools_patch_default_imported_config( + civetweb::civetweb civetweb::server civetweb::civetweb-cpp) +endif() + +if(BUILD_TESTING) + project_build_tools_patch_default_imported_config( + GTest::gtest + GTest::gtest_main + GTest::gmock + GTest::gmock_main + GTest::GTest + GTest::Main + benchmark::benchmark + benchmark::benchmark_main) +endif() From 56abafc045a09da91366663fc534766f22f98abc Mon Sep 17 00:00:00 2001 From: owent Date: Sat, 16 Dec 2023 02:19:07 +0800 Subject: [PATCH 3/4] Fix style --- cmake/patch-imported-config.cmake | 288 +++++++++++++++--------------- 1 file changed, 144 insertions(+), 144 deletions(-) diff --git a/cmake/patch-imported-config.cmake b/cmake/patch-imported-config.cmake index fe3e88b3ad..a2d22ed398 100644 --- a/cmake/patch-imported-config.cmake +++ b/cmake/patch-imported-config.cmake @@ -1,144 +1,144 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -# Some prebuilt or installed targets may have different CONFIG settings than -# what we use to configure otel-cpp. This file applies patches to the imported -# targets in order to use compatible CONFIG settings for fallback. - -# Common dependencies -project_build_tools_patch_default_imported_config(ZLIB::ZLIB) - -# protobuf targets -if(Protobuf_FOUND OR PROTOBUF_FOUND) - project_build_tools_patch_default_imported_config( - utf8_range::utf8_range utf8_range::utf8_validity protobuf::libprotobuf-lite - protobuf::libprotobuf protobuf::libprotoc) -endif() - -# cares targets -if(TARGET c-ares::cares) - project_build_tools_patch_default_imported_config(c-ares::cares) -endif() - -# curl targets -if(TARGET CURL::libcurl - OR TARGET CURL::libcurl_static - OR TARGET CURL::libcurl_shared) - project_build_tools_patch_default_imported_config( - CURL::libcurl CURL::libcurl_static CURL::libcurl_shared) -endif() - -# abseil targets -if(WITH_ABSEIL) - project_build_tools_patch_default_imported_config( - absl::bad_variant_access - absl::raw_logging_internal - absl::log_severity - absl::log_internal_check_op - absl::log_internal_nullguard - absl::strings - absl::strings_internal - absl::base - absl::spinlock_wait - absl::int128 - absl::throw_delegate - absl::log_internal_message - absl::examine_stack - absl::stacktrace - absl::debugging_internal - absl::symbolize - absl::demangle_internal - absl::malloc_internal - absl::log_internal_format - absl::log_internal_globals - absl::time - absl::civil_time - absl::time_zone - absl::str_format_internal - absl::log_internal_proto - absl::log_internal_log_sink_set - absl::log_globals - absl::hash - absl::city - absl::bad_optional_access - absl::low_level_hash - absl::log_entry - absl::log_sink - absl::synchronization - absl::graphcycles_internal - absl::strerror - absl::log_internal_conditions - absl::cord - absl::cord_internal - absl::crc_cord_state - absl::crc32c - absl::crc_cpu_detect - absl::crc_internal - absl::cordz_functions - absl::exponential_biased - absl::cordz_info - absl::cordz_handle - absl::leak_check - absl::die_if_null - absl::flags - absl::flags_commandlineflag - absl::flags_commandlineflag_internal - absl::flags_config - absl::flags_program_name - absl::flags_internal - absl::flags_marshalling - absl::flags_reflection - absl::flags_private_handle_accessor - absl::raw_hash_set - absl::hashtablez_sampler - absl::log_initialize - absl::status - absl::statusor) -endif() - -# gRPC targets -if(TARGET gRPC::grpc++) - project_build_tools_patch_default_imported_config( - gRPC::cares - gRPC::re2 - gRPC::ssl - gRPC::crypto - gRPC::zlibstatic - gRPC::address_sorting - gRPC::gpr - gRPC::grpc - gRPC::grpc_unsecure - gRPC::grpc++ - gRPC::grpc++_alts - gRPC::grpc++_error_details - gRPC::grpc++_reflection - gRPC::grpc++_unsecure - gRPC::grpc_authorization_provider - gRPC::grpc_plugin_support - gRPC::grpcpp_channelz - gRPC::upb) -endif() - -# prometheus targets -if(TARGET prometheus-cpp::core) - project_build_tools_patch_default_imported_config( - prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push) -endif() - -# civetweb targets -if(TARGET civetweb::civetweb) - project_build_tools_patch_default_imported_config( - civetweb::civetweb civetweb::server civetweb::civetweb-cpp) -endif() - -if(BUILD_TESTING) - project_build_tools_patch_default_imported_config( - GTest::gtest - GTest::gtest_main - GTest::gmock - GTest::gmock_main - GTest::GTest - GTest::Main - benchmark::benchmark - benchmark::benchmark_main) -endif() +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Some prebuilt or installed targets may have different CONFIG settings than +# what we use to configure otel-cpp. This file applies patches to the imported +# targets in order to use compatible CONFIG settings for fallback. + +# Common dependencies +project_build_tools_patch_default_imported_config(ZLIB::ZLIB) + +# protobuf targets +if(Protobuf_FOUND OR PROTOBUF_FOUND) + project_build_tools_patch_default_imported_config( + utf8_range::utf8_range utf8_range::utf8_validity protobuf::libprotobuf-lite + protobuf::libprotobuf protobuf::libprotoc) +endif() + +# cares targets +if(TARGET c-ares::cares) + project_build_tools_patch_default_imported_config(c-ares::cares) +endif() + +# curl targets +if(TARGET CURL::libcurl + OR TARGET CURL::libcurl_static + OR TARGET CURL::libcurl_shared) + project_build_tools_patch_default_imported_config( + CURL::libcurl CURL::libcurl_static CURL::libcurl_shared) +endif() + +# abseil targets +if(WITH_ABSEIL) + project_build_tools_patch_default_imported_config( + absl::bad_variant_access + absl::raw_logging_internal + absl::log_severity + absl::log_internal_check_op + absl::log_internal_nullguard + absl::strings + absl::strings_internal + absl::base + absl::spinlock_wait + absl::int128 + absl::throw_delegate + absl::log_internal_message + absl::examine_stack + absl::stacktrace + absl::debugging_internal + absl::symbolize + absl::demangle_internal + absl::malloc_internal + absl::log_internal_format + absl::log_internal_globals + absl::time + absl::civil_time + absl::time_zone + absl::str_format_internal + absl::log_internal_proto + absl::log_internal_log_sink_set + absl::log_globals + absl::hash + absl::city + absl::bad_optional_access + absl::low_level_hash + absl::log_entry + absl::log_sink + absl::synchronization + absl::graphcycles_internal + absl::strerror + absl::log_internal_conditions + absl::cord + absl::cord_internal + absl::crc_cord_state + absl::crc32c + absl::crc_cpu_detect + absl::crc_internal + absl::cordz_functions + absl::exponential_biased + absl::cordz_info + absl::cordz_handle + absl::leak_check + absl::die_if_null + absl::flags + absl::flags_commandlineflag + absl::flags_commandlineflag_internal + absl::flags_config + absl::flags_program_name + absl::flags_internal + absl::flags_marshalling + absl::flags_reflection + absl::flags_private_handle_accessor + absl::raw_hash_set + absl::hashtablez_sampler + absl::log_initialize + absl::status + absl::statusor) +endif() + +# gRPC targets +if(TARGET gRPC::grpc++) + project_build_tools_patch_default_imported_config( + gRPC::cares + gRPC::re2 + gRPC::ssl + gRPC::crypto + gRPC::zlibstatic + gRPC::address_sorting + gRPC::gpr + gRPC::grpc + gRPC::grpc_unsecure + gRPC::grpc++ + gRPC::grpc++_alts + gRPC::grpc++_error_details + gRPC::grpc++_reflection + gRPC::grpc++_unsecure + gRPC::grpc_authorization_provider + gRPC::grpc_plugin_support + gRPC::grpcpp_channelz + gRPC::upb) +endif() + +# prometheus targets +if(TARGET prometheus-cpp::core) + project_build_tools_patch_default_imported_config( + prometheus-cpp::core prometheus-cpp::pull prometheus-cpp::push) +endif() + +# civetweb targets +if(TARGET civetweb::civetweb) + project_build_tools_patch_default_imported_config( + civetweb::civetweb civetweb::server civetweb::civetweb-cpp) +endif() + +if(BUILD_TESTING) + project_build_tools_patch_default_imported_config( + GTest::gtest + GTest::gtest_main + GTest::gmock + GTest::gmock_main + GTest::GTest + GTest::Main + benchmark::benchmark + benchmark::benchmark_main) +endif() From d58266926e43b2d643d6f6c345da666a9559ae98 Mon Sep 17 00:00:00 2001 From: owent Date: Sat, 16 Dec 2023 02:28:55 +0800 Subject: [PATCH 4/4] Fix style --- cmake/tools.cmake | 426 +++++++++++++++++++++++----------------------- 1 file changed, 213 insertions(+), 213 deletions(-) diff --git a/cmake/tools.cmake b/cmake/tools.cmake index 4e82fed49f..43c1a7b43f 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -1,213 +1,213 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -macro(check_append_cxx_compiler_flag OUTPUT_VAR) - foreach(CHECK_FLAG ${ARGN}) - check_cxx_compiler_flag(${CHECK_FLAG} - "check_cxx_compiler_flag_${CHECK_FLAG}") - if(check_cxx_compiler_flag_${CHECK_FLAG}) - list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG}) - endif() - endforeach() -endmacro() - -if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET) - if(MSVC) - unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) - set(PATCH_PROTOBUF_SOURCES_OPTIONS - /wd4244 - /wd4251 - /wd4267 - /wd4309 - /wd4668 - /wd4946 - /wd6001 - /wd6244 - /wd6246) - - if(MSVC_VERSION GREATER_EQUAL 1922) - # see - # https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162 - # for detail - list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054) - endif() - - if(MSVC_VERSION GREATER_EQUAL 1925) - list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996) - endif() - - if(MSVC_VERSION LESS 1910) - list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800) - endif() - else() - unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) - include(CheckCXXCompilerFlag) - check_append_cxx_compiler_flag( - PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits - -Wno-deprecated-declarations -Wno-unused-parameter) - endif() - set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE) - if(PATCH_PROTOBUF_SOURCES_OPTIONS) - set(PATCH_PROTOBUF_SOURCES_OPTIONS - ${PATCH_PROTOBUF_SOURCES_OPTIONS} - CACHE INTERNAL - "Options to disable warning of generated protobuf sources" FORCE) - endif() -endif() - -function(patch_protobuf_sources) - if(PATCH_PROTOBUF_SOURCES_OPTIONS) - foreach(PROTO_SRC ${ARGN}) - unset(PROTO_SRC_OPTIONS) - get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS) - if(PROTO_SRC_OPTIONS) - list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - else() - set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - endif() - - set_source_files_properties( - ${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}") - endforeach() - unset(PROTO_SRC) - unset(PROTO_SRC_OPTIONS) - endif() -endfunction() - -function(patch_protobuf_targets) - if(PATCH_PROTOBUF_SOURCES_OPTIONS) - foreach(PROTO_TARGET ${ARGN}) - unset(PROTO_TARGET_OPTIONS) - get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS) - if(PROTO_TARGET_OPTIONS) - list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - else() - set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) - endif() - - set_target_properties( - ${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}") - endforeach() - unset(PROTO_TARGET) - unset(PROTO_TARGET_OPTIONS) - endif() -endfunction() - -function(project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME) - if(CMAKE_BUILD_TYPE) - string(TOUPPER "IMPORTED_LOCATION_${CMAKE_BUILD_TYPE}" - TRY_SPECIFY_IMPORTED_LOCATION) - get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} - ${TRY_SPECIFY_IMPORTED_LOCATION}) - endif() - if(NOT ${OUTPUT_VAR_NAME}) - get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} IMPORTED_LOCATION) - endif() - if(NOT ${OUTPUT_VAR_NAME}) - get_target_property( - project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS - ${TARGET_NAME} IMPORTED_CONFIGURATIONS) - foreach( - project_build_tools_get_imported_location_IMPORTED_CONFIGURATION IN - LISTS project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS) - get_target_property( - ${OUTPUT_VAR_NAME} - ${TARGET_NAME} - "IMPORTED_LOCATION_${project_build_tools_get_imported_location_IMPORTED_CONFIGURATION}" - ) - if(${OUTPUT_VAR_NAME}) - break() - endif() - endforeach() - endif() - if(${OUTPUT_VAR_NAME}) - set(${OUTPUT_VAR_NAME} - ${${OUTPUT_VAR_NAME}} - PARENT_SCOPE) - endif() -endfunction() - -#[[ -If we build third party packages with a different CONFIG setting from building -otel-cpp, cmake may not find a suitable file in imported targets (#705, #1359) -when linking. But on some platforms, different CONFIG settings can be used when -these CONFIG settings have the same ABI. For example, on Linux, we can build -gRPC and protobuf with -DCMAKE_BUILD_TYPE=Release, but build otel-cpp with --DCMAKE_BUILD_TYPE=Debug and link these libraries together. -The properties of imported targets can be found here: -https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets -]] -function(project_build_tools_patch_default_imported_config) - set(PATCH_VARS - IMPORTED_IMPLIB - IMPORTED_LIBNAME - IMPORTED_LINK_DEPENDENT_LIBRARIES - IMPORTED_LINK_INTERFACE_LANGUAGES - IMPORTED_LINK_INTERFACE_LIBRARIES - IMPORTED_LINK_INTERFACE_MULTIPLICITY - IMPORTED_LOCATION - IMPORTED_NO_SONAME - IMPORTED_OBJECTS - IMPORTED_SONAME) - foreach(TARGET_NAME ${ARGN}) - if(TARGET ${TARGET_NAME}) - get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED) - if(NOT IS_IMPORTED_TARGET) - continue() - endif() - - get_target_property(IS_ALIAS_TARGET ${TARGET_NAME} ALIASED_TARGET) - if(IS_ALIAS_TARGET) - continue() - endif() - - if(CMAKE_VERSION VERSION_LESS "3.19.0") - get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE) - if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY") - continue() - endif() - endif() - - get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION) - if(DO_NOT_OVERWRITE) - continue() - endif() - - # MSVC's STL and debug level must match the target, so we can only move - # out IMPORTED_LOCATION_NOCONFIG - if(MSVC) - set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG") - else() - get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME} - IMPORTED_CONFIGURATIONS) - endif() - - if(NOT PATCH_IMPORTED_CONFIGURATION) - continue() - endif() - - get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME} - "IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}") - if(NOT PATCH_TARGET_LOCATION) - continue() - endif() - - foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS) - get_target_property( - PATCH_IMPORTED_VALUE ${TARGET_NAME} - "${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}") - if(PATCH_IMPORTED_VALUE) - set_target_properties( - ${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}" - "${PATCH_IMPORTED_VALUE}") - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - message( - STATUS - "Patch: ${TARGET_NAME} ${PATCH_IMPORTED_KEY} will use ${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}(\"${PATCH_IMPORTED_VALUE}\") by default." - ) - endif() - endif() - endforeach() - endif() - endforeach() -endfunction() +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +macro(check_append_cxx_compiler_flag OUTPUT_VAR) + foreach(CHECK_FLAG ${ARGN}) + check_cxx_compiler_flag(${CHECK_FLAG} + "check_cxx_compiler_flag_${CHECK_FLAG}") + if(check_cxx_compiler_flag_${CHECK_FLAG}) + list(APPEND ${OUTPUT_VAR} ${CHECK_FLAG}) + endif() + endforeach() +endmacro() + +if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET) + if(MSVC) + unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) + set(PATCH_PROTOBUF_SOURCES_OPTIONS + /wd4244 + /wd4251 + /wd4267 + /wd4309 + /wd4668 + /wd4946 + /wd6001 + /wd6244 + /wd6246) + + if(MSVC_VERSION GREATER_EQUAL 1922) + # see + # https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=vs-2019#improvements_162 + # for detail + list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd5054) + endif() + + if(MSVC_VERSION GREATER_EQUAL 1925) + list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4996) + endif() + + if(MSVC_VERSION LESS 1910) + list(APPEND PATCH_PROTOBUF_SOURCES_OPTIONS /wd4800) + endif() + else() + unset(PATCH_PROTOBUF_SOURCES_OPTIONS CACHE) + include(CheckCXXCompilerFlag) + check_append_cxx_compiler_flag( + PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type-limits + -Wno-deprecated-declarations -Wno-unused-parameter) + endif() + set(PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE) + if(PATCH_PROTOBUF_SOURCES_OPTIONS) + set(PATCH_PROTOBUF_SOURCES_OPTIONS + ${PATCH_PROTOBUF_SOURCES_OPTIONS} + CACHE INTERNAL + "Options to disable warning of generated protobuf sources" FORCE) + endif() +endif() + +function(patch_protobuf_sources) + if(PATCH_PROTOBUF_SOURCES_OPTIONS) + foreach(PROTO_SRC ${ARGN}) + unset(PROTO_SRC_OPTIONS) + get_source_file_property(PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS) + if(PROTO_SRC_OPTIONS) + list(APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + else() + set(PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + endif() + + set_source_files_properties( + ${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS}") + endforeach() + unset(PROTO_SRC) + unset(PROTO_SRC_OPTIONS) + endif() +endfunction() + +function(patch_protobuf_targets) + if(PATCH_PROTOBUF_SOURCES_OPTIONS) + foreach(PROTO_TARGET ${ARGN}) + unset(PROTO_TARGET_OPTIONS) + get_target_property(PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS) + if(PROTO_TARGET_OPTIONS) + list(APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + else() + set(PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS}) + endif() + + set_target_properties( + ${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS}") + endforeach() + unset(PROTO_TARGET) + unset(PROTO_TARGET_OPTIONS) + endif() +endfunction() + +function(project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME) + if(CMAKE_BUILD_TYPE) + string(TOUPPER "IMPORTED_LOCATION_${CMAKE_BUILD_TYPE}" + TRY_SPECIFY_IMPORTED_LOCATION) + get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} + ${TRY_SPECIFY_IMPORTED_LOCATION}) + endif() + if(NOT ${OUTPUT_VAR_NAME}) + get_target_property(${OUTPUT_VAR_NAME} ${TARGET_NAME} IMPORTED_LOCATION) + endif() + if(NOT ${OUTPUT_VAR_NAME}) + get_target_property( + project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS + ${TARGET_NAME} IMPORTED_CONFIGURATIONS) + foreach( + project_build_tools_get_imported_location_IMPORTED_CONFIGURATION IN + LISTS project_build_tools_get_imported_location_IMPORTED_CONFIGURATIONS) + get_target_property( + ${OUTPUT_VAR_NAME} + ${TARGET_NAME} + "IMPORTED_LOCATION_${project_build_tools_get_imported_location_IMPORTED_CONFIGURATION}" + ) + if(${OUTPUT_VAR_NAME}) + break() + endif() + endforeach() + endif() + if(${OUTPUT_VAR_NAME}) + set(${OUTPUT_VAR_NAME} + ${${OUTPUT_VAR_NAME}} + PARENT_SCOPE) + endif() +endfunction() + +#[[ +If we build third party packages with a different CONFIG setting from building +otel-cpp, cmake may not find a suitable file in imported targets (#705, #1359) +when linking. But on some platforms, different CONFIG settings can be used when +these CONFIG settings have the same ABI. For example, on Linux, we can build +gRPC and protobuf with -DCMAKE_BUILD_TYPE=Release, but build otel-cpp with +-DCMAKE_BUILD_TYPE=Debug and link these libraries together. +The properties of imported targets can be found here: +https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets +]] +function(project_build_tools_patch_default_imported_config) + set(PATCH_VARS + IMPORTED_IMPLIB + IMPORTED_LIBNAME + IMPORTED_LINK_DEPENDENT_LIBRARIES + IMPORTED_LINK_INTERFACE_LANGUAGES + IMPORTED_LINK_INTERFACE_LIBRARIES + IMPORTED_LINK_INTERFACE_MULTIPLICITY + IMPORTED_LOCATION + IMPORTED_NO_SONAME + IMPORTED_OBJECTS + IMPORTED_SONAME) + foreach(TARGET_NAME ${ARGN}) + if(TARGET ${TARGET_NAME}) + get_target_property(IS_IMPORTED_TARGET ${TARGET_NAME} IMPORTED) + if(NOT IS_IMPORTED_TARGET) + continue() + endif() + + get_target_property(IS_ALIAS_TARGET ${TARGET_NAME} ALIASED_TARGET) + if(IS_ALIAS_TARGET) + continue() + endif() + + if(CMAKE_VERSION VERSION_LESS "3.19.0") + get_target_property(TARGET_TYPE_NAME ${TARGET_NAME} TYPE) + if(TARGET_TYPE_NAME STREQUAL "INTERFACE_LIBRARY") + continue() + endif() + endif() + + get_target_property(DO_NOT_OVERWRITE ${TARGET_NAME} IMPORTED_LOCATION) + if(DO_NOT_OVERWRITE) + continue() + endif() + + # MSVC's STL and debug level must match the target, so we can only move + # out IMPORTED_LOCATION_NOCONFIG + if(MSVC) + set(PATCH_IMPORTED_CONFIGURATION "NOCONFIG") + else() + get_target_property(PATCH_IMPORTED_CONFIGURATION ${TARGET_NAME} + IMPORTED_CONFIGURATIONS) + endif() + + if(NOT PATCH_IMPORTED_CONFIGURATION) + continue() + endif() + + get_target_property(PATCH_TARGET_LOCATION ${TARGET_NAME} + "IMPORTED_LOCATION_${PATCH_IMPORTED_CONFIGURATION}") + if(NOT PATCH_TARGET_LOCATION) + continue() + endif() + + foreach(PATCH_IMPORTED_KEY IN LISTS PATCH_VARS) + get_target_property( + PATCH_IMPORTED_VALUE ${TARGET_NAME} + "${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}") + if(PATCH_IMPORTED_VALUE) + set_target_properties( + ${TARGET_NAME} PROPERTIES "${PATCH_IMPORTED_KEY}" + "${PATCH_IMPORTED_VALUE}") + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + message( + STATUS + "Patch: ${TARGET_NAME} ${PATCH_IMPORTED_KEY} will use ${PATCH_IMPORTED_KEY}_${PATCH_IMPORTED_CONFIGURATION}(\"${PATCH_IMPORTED_VALUE}\") by default." + ) + endif() + endif() + endforeach() + endif() + endforeach() +endfunction()