wwbmmm commented on code in PR #3596: URL: https://github.com/apache/brpc/pull/3596#discussion_r4244981551
########## cmake/brpc-config.cmake.in: ########## @@ -0,0 +1,239 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +@PACKAGE_INIT@ +set(brpc_FOUND TRUE) +unset(brpc_NOT_FOUND_MESSAGE) + +# Build every library, but consumers need only their selected dependency closure. +set(_brpc_components ${brpc_FIND_COMPONENTS}) +if(NOT _brpc_components) + set(_brpc_components butil bvar bthread json2pb mcpack2pb brpc) +endif() +if("brpc" IN_LIST _brpc_components) + list(APPEND _brpc_components bthread bvar json2pb mcpack2pb) +endif() +if("bthread" IN_LIST _brpc_components) + list(APPEND _brpc_components bvar) +endif() +list(APPEND _brpc_components butil) + +include(CMakeFindDependencyMacro) +find_dependency(Threads) +find_dependency(Protobuf) +if(Protobuf_VERSION VERSION_GREATER 4.21 OR + (@WITH_BTHREAD_TRACER@ AND "bthread" IN_LIST _brpc_components)) + find_dependency(absl CONFIG) +endif() +if(@WITH_BORINGSSL@) + find_path(_brpc_boringssl_include NAMES openssl/base.h + HINTS ${BORINGSSL_ROOT_DIR}/include) + find_library(_brpc_boringssl_ssl_library NAMES ssl + HINTS ${BORINGSSL_ROOT_DIR}/lib) + find_library(_brpc_boringssl_crypto_library NAMES crypto + HINTS ${BORINGSSL_ROOT_DIR}/lib) + if(NOT _brpc_boringssl_include OR NOT _brpc_boringssl_ssl_library OR + NOT _brpc_boringssl_crypto_library) + set(brpc_FOUND FALSE) + set(brpc_NOT_FOUND_MESSAGE "brpc requires BoringSSL") + return() + endif() + foreach(_brpc_lib SSL CRYPTO) + string(TOLOWER ${_brpc_lib} _brpc_lib_lower) + if(NOT TARGET brpc::boringssl_${_brpc_lib_lower}) + add_library(brpc::boringssl_${_brpc_lib_lower} UNKNOWN IMPORTED) + set_target_properties(brpc::boringssl_${_brpc_lib_lower} PROPERTIES + IMPORTED_LOCATION "${_brpc_boringssl_${_brpc_lib_lower}_library}" + INTERFACE_INCLUDE_DIRECTORIES "${_brpc_boringssl_include}") + endif() + endforeach() +else() + find_dependency(OpenSSL) +endif() + +if(NOT TARGET brpc::gflags) + find_package(gflags CONFIG QUIET) + if(TARGET gflags::gflags OR TARGET gflags) + add_library(brpc::gflags INTERFACE IMPORTED) + if(TARGET gflags::gflags) + set_property(TARGET brpc::gflags PROPERTY + INTERFACE_LINK_LIBRARIES gflags::gflags) + else() + set_property(TARGET brpc::gflags PROPERTY + INTERFACE_LINK_LIBRARIES gflags) + endif() + else() + # Older system packages may provide only headers and libraries. + find_path(GFLAGS_INCLUDE_PATH NAMES gflags/gflags.h) + find_library(GFLAGS_LIBRARY NAMES gflags libgflags) + if(NOT GFLAGS_INCLUDE_PATH OR NOT GFLAGS_LIBRARY) + set(brpc_FOUND FALSE) + set(brpc_NOT_FOUND_MESSAGE "brpc requires gflags") + return() + endif() + add_library(brpc::gflags UNKNOWN IMPORTED) + set_target_properties(brpc::gflags PROPERTIES + IMPORTED_LOCATION "${GFLAGS_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GFLAGS_INCLUDE_PATH}") + endif() +endif() + +if("brpc" IN_LIST _brpc_components) + find_dependency(ZLIB) + find_package(leveldb CONFIG QUIET) + if(NOT TARGET brpc::leveldb) + if(TARGET leveldb::leveldb) + get_target_property(_brpc_leveldb_link_libraries leveldb::leveldb + INTERFACE_LINK_LIBRARIES) + if("snappy" IN_LIST _brpc_leveldb_link_libraries AND NOT TARGET snappy) + find_library(_brpc_leveldb_snappy_library NAMES snappy) + if(NOT _brpc_leveldb_snappy_library) + set(brpc_FOUND FALSE) + set(brpc_NOT_FOUND_MESSAGE + "LevelDB requires the Snappy development library") + return() + endif() + add_library(snappy UNKNOWN IMPORTED) + set_property(TARGET snappy PROPERTY IMPORTED_LOCATION + "${_brpc_leveldb_snappy_library}") + endif() + add_library(brpc::leveldb INTERFACE IMPORTED) + set_property(TARGET brpc::leveldb PROPERTY + INTERFACE_LINK_LIBRARIES leveldb::leveldb) + else() + find_library(_brpc_leveldb_library NAMES leveldb) + find_path(_brpc_leveldb_include NAMES leveldb/db.h) + if(NOT _brpc_leveldb_library OR NOT _brpc_leveldb_include) + set(brpc_FOUND FALSE) + set(brpc_NOT_FOUND_MESSAGE "brpc requires LevelDB") + return() + endif() + add_library(brpc::leveldb UNKNOWN IMPORTED) + set_target_properties(brpc::leveldb PROPERTIES + IMPORTED_LOCATION "${_brpc_leveldb_library}" + INTERFACE_INCLUDE_DIRECTORIES "${_brpc_leveldb_include}") + endif() + endif() +endif() + +if("brpc" IN_LIST _brpc_components AND @WITH_URMA@ AND NOT TARGET brpc::urma) + find_path(_brpc_urma_include NAMES urma_api.h + HINTS ENV URMA_ROOT + PATH_SUFFIXES ub/umdk/urma umdk/urma urma + src/urma/lib/urma/core/include) + if(NOT _brpc_urma_include) + set(brpc_FOUND FALSE) + set(brpc_NOT_FOUND_MESSAGE "brpc requires UMDK headers even in URMA mock mode") + return() + endif() + find_path(_brpc_urma_bond_include NAMES urma_ubagg.h + HINTS ENV URMA_ROOT + PATH_SUFFIXES ub/umdk/urma umdk/urma urma + src/urma/lib/urma/bond/include) + if(@BRPC_COMPONENT_URMA_REAL@) + find_library(_brpc_urma_library NAMES urma + HINTS ENV URMA_ROOT PATH_SUFFIXES lib lib64) + if(NOT _brpc_urma_library) + set(brpc_FOUND FALSE) + set(brpc_NOT_FOUND_MESSAGE "brpc requires liburma") + return() + endif() + endif() + add_library(brpc::urma INTERFACE IMPORTED) + set_property(TARGET brpc::urma PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${_brpc_urma_include}") + if(_brpc_urma_bond_include) + set_property(TARGET brpc::urma APPEND PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${_brpc_urma_bond_include}") + endif() + if(@BRPC_COMPONENT_URMA_REAL@) + set_property(TARGET brpc::urma PROPERTY + INTERFACE_LINK_LIBRARIES "${_brpc_urma_library}") + endif() +endif() + +foreach(_brpc_dep glog mesalink unwind unwind_x86_64 thrift rdma snappy ub) Review Comment: [replied by brpc-oncall robot] `brpc-config.cmake.in` still hand-reimplements discovery for gflags/leveldb/OpenSSL/BoringSSL/glog/thrift/rdma/snappy/urma/unwind with bespoke `find_library`/`find_path` blocks, duplicating the logic that now lives in the per-module CMakeLists (src/butil, src/brpc, src/bthread). Each optional dependency must be kept in sync across the module files, this template and the pkg-config strings, and the URMA mock/real split shows how quickly this grows. Consider deriving the exported dependency list from the component targets, or at least documenting the sync points next to these loops, so a new `WITH_*` feature cannot silently be handled in only some of them. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
