mirror of https://github.com/microsoft/vcpkg.git
244 lines
8.1 KiB
Diff
244 lines
8.1 KiB
Diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index b10991f..a507685 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -77,7 +77,8 @@ endif()
|
|
|
|
if(WITH_THRIFT)
|
|
set(THRIFT_CPP_FLAG "-DENABLE_THRIFT_FRAMED_PROTOCOL")
|
|
- find_library(THRIFT_LIB NAMES thrift)
|
|
+ find_package(Thrift CONFIG REQUIRED)
|
|
+ set(THRIFT_LIB "thrift::thrift")
|
|
if (NOT THRIFT_LIB)
|
|
message(FATAL_ERROR "Fail to find Thrift")
|
|
endif()
|
|
@@ -115,7 +116,10 @@ configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_SOURCE_DIR}/src/butil
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
|
|
|
-find_package(GFLAGS REQUIRED)
|
|
+set(GFLAGS_USE_TARGET_NAMESPACE ON)
|
|
+find_package(gflags CONFIG REQUIRED)
|
|
+set(GFLAGS_INCLUDE_PATH "")
|
|
+set(GFLAGS_LIBRARY gflags::gflags)
|
|
|
|
include_directories(
|
|
${PROJECT_SOURCE_DIR}/src
|
|
@@ -180,12 +184,17 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
endif()
|
|
|
|
find_package(Protobuf REQUIRED)
|
|
+get_target_property(PROTOBUF_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
|
|
+set(PROTOBUF_INCLUDE_DIRS "")
|
|
+set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
|
|
if(Protobuf_VERSION GREATER 4.21)
|
|
# required by absl
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
find_package(absl REQUIRED CONFIG)
|
|
set(protobuf_ABSL_USED_TARGETS
|
|
+ "")
|
|
+ set(protobuf_ABSL_provided_by_vcpkg
|
|
absl::absl_check
|
|
absl::absl_log
|
|
absl::algorithm
|
|
@@ -225,29 +234,21 @@ else()
|
|
use_cxx11()
|
|
endif()
|
|
find_package(Threads REQUIRED)
|
|
+find_package(ZLIB REQUIRED)
|
|
+add_library(z ALIAS ZLIB::ZLIB)
|
|
|
|
-find_path(LEVELDB_INCLUDE_PATH NAMES leveldb/db.h)
|
|
-find_library(LEVELDB_LIB NAMES leveldb)
|
|
-if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
|
|
- message(FATAL_ERROR "Fail to find leveldb")
|
|
-endif()
|
|
+find_package(leveldb CONFIG REQUIRED)
|
|
+set(LEVELDB_INCLUDE_PATH "")
|
|
+set(LEVELDB_LIB leveldb::leveldb)
|
|
|
|
if(WITH_SNAPPY)
|
|
- find_path(SNAPPY_INCLUDE_PATH NAMES snappy.h)
|
|
- find_library(SNAPPY_LIB NAMES snappy)
|
|
- if ((NOT SNAPPY_INCLUDE_PATH) OR (NOT SNAPPY_LIB))
|
|
- message(FATAL_ERROR "Fail to find snappy")
|
|
- endif()
|
|
- include_directories(${SNAPPY_INCLUDE_PATH})
|
|
+ find_package(Snappy CONFIG REQUIRED)
|
|
+ set(SNAPPY_LIB Snappy::snappy)
|
|
endif()
|
|
|
|
if(WITH_GLOG)
|
|
- find_path(GLOG_INCLUDE_PATH NAMES glog/logging.h)
|
|
- find_library(GLOG_LIB NAMES glog)
|
|
- if((NOT GLOG_INCLUDE_PATH) OR (NOT GLOG_LIB))
|
|
- message(FATAL_ERROR "Fail to find glog")
|
|
- endif()
|
|
- include_directories(${GLOG_INCLUDE_PATH})
|
|
+ find_package(glog CONFIG REQUIRED)
|
|
+ set(GLOG_LIB glog::glog)
|
|
endif()
|
|
|
|
if(WITH_MESALINK)
|
|
@@ -270,7 +271,7 @@ if(WITH_RDMA)
|
|
endif()
|
|
endif()
|
|
|
|
-find_library(PROTOC_LIB NAMES protoc)
|
|
+set(PROTOC_LIB "protobuf::libprotoc")
|
|
if(NOT PROTOC_LIB)
|
|
message(FATAL_ERROR "Fail to find protoc lib")
|
|
endif()
|
|
@@ -280,9 +281,6 @@ if(WITH_BORINGSSL)
|
|
include_directories(${BORINGSSL_INCLUDE_DIR})
|
|
else()
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT OPENSSL_ROOT_DIR)
|
|
- set(OPENSSL_ROOT_DIR
|
|
- "/usr/local/opt/openssl" # Homebrew installed OpenSSL
|
|
- )
|
|
endif()
|
|
|
|
find_package(OpenSSL)
|
|
@@ -308,6 +306,8 @@ set(DYNAMIC_LIB
|
|
if(WITH_BORINGSSL)
|
|
list(APPEND DYNAMIC_LIB ${BORINGSSL_SSL_LIBRARY})
|
|
list(APPEND DYNAMIC_LIB ${BORINGSSL_CRYPTO_LIBRARY})
|
|
+elseif(1)
|
|
+ list(APPEND DYNAMIC_LIB OpenSSL::SSL)
|
|
else()
|
|
if(WITH_MESALINK)
|
|
list(APPEND DYNAMIC_LIB ${OPENSSL_CRYPTO_LIBRARY})
|
|
@@ -322,7 +322,8 @@ if(WITH_RDMA)
|
|
list(APPEND DYNAMIC_LIB ${RDMA_LIB})
|
|
endif()
|
|
|
|
-set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz")
|
|
+set(BRPC_PRIVATE_LIBS "-lleveldb -lprotoc -ldl")
|
|
+set(BRPC_PRIVATE_REQUIRES "gflags protobuf openssl zlib")
|
|
|
|
if(WITH_GLOG)
|
|
set(DYNAMIC_LIB ${GLOG_LIB} ${DYNAMIC_LIB})
|
|
@@ -331,7 +332,7 @@ endif()
|
|
|
|
if(WITH_SNAPPY)
|
|
set(DYNAMIC_LIB ${DYNAMIC_LIB} ${SNAPPY_LIB})
|
|
- set(BRPC_PRIVATE_LIBS "${BRPC_PRIVATE_LIBS} -lsnappy")
|
|
+ set(BRPC_PRIVATE_REQUIRES "${BRPC_PRIVATE_LIBS} snappy")
|
|
endif()
|
|
|
|
if (WITH_BTHREAD_TRACER)
|
|
@@ -556,6 +557,7 @@ compile_proto(PROTO_HDRS PROTO_SRCS ${PROJECT_BINARY_DIR}
|
|
${PROJECT_SOURCE_DIR}/src
|
|
"${PROTO_FILES}")
|
|
add_library(PROTO_LIB OBJECT ${PROTO_SRCS} ${PROTO_HDRS})
|
|
+target_link_libraries(PROTO_LIB PUBLIC ${DYNAMIC_LIB})
|
|
|
|
set(SOURCES
|
|
${BVAR_SOURCES}
|
|
diff --git a/cmake/brpc.pc.in b/cmake/brpc.pc.in
|
|
index 723dab4..36277cd 100644
|
|
--- a/cmake/brpc.pc.in
|
|
+++ b/cmake/brpc.pc.in
|
|
@@ -24,3 +24,4 @@ Version: @BRPC_VERSION@
|
|
Cflags: -I${includedir}
|
|
Libs: -L${libdir}/ -lbrpc
|
|
Libs.private: @BRPC_PRIVATE_LIBS@
|
|
+Requires.private: @BRPC_PRIVATE_REQUIRES@
|
|
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
index 1b4b233..f14d024 100644
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -26,6 +26,10 @@ include_directories(${PROJECT_SOURCE_DIR}/src)
|
|
add_library(BUTIL_LIB OBJECT ${BUTIL_SOURCES})
|
|
add_library(SOURCES_LIB OBJECT ${SOURCES})
|
|
add_dependencies(SOURCES_LIB PROTO_LIB)
|
|
+if(WITH_GLOG)
|
|
+ target_link_libraries(BUTIL_LIB PRIVATE glog::glog)
|
|
+ target_link_libraries(SOURCES_LIB PRIVATE glog::glog)
|
|
+endif()
|
|
|
|
# shared library needs POSITION_INDEPENDENT_CODE
|
|
set_property(TARGET ${SOURCES_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
|
|
@@ -59,9 +63,9 @@ function(check_thrift_version target_arg)
|
|
endfunction()
|
|
|
|
|
|
+target_link_libraries(brpc-static PUBLIC ${DYNAMIC_LIB})
|
|
+
|
|
if(WITH_THRIFT)
|
|
- target_link_libraries(brpc-static ${THRIFT_LIB})
|
|
- check_thrift_version(brpc-static)
|
|
endif()
|
|
|
|
SET_TARGET_PROPERTIES(brpc-static PROPERTIES OUTPUT_NAME brpc CLEAN_DIRECT_OUTPUT 1)
|
|
@@ -74,24 +78,25 @@ set(protoc_gen_mcpack_SOURCES
|
|
)
|
|
|
|
add_executable(protoc-gen-mcpack ${protoc_gen_mcpack_SOURCES})
|
|
+set_target_properties(protoc-gen-mcpack PROPERTIES EXCLUDE_FROM_ALL 1)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
+ set_target_properties(brpc-static PROPERTIES EXCLUDE_FROM_ALL 1)
|
|
add_library(brpc-shared SHARED $<TARGET_OBJECTS:BUTIL_LIB>
|
|
$<TARGET_OBJECTS:SOURCES_LIB>
|
|
$<TARGET_OBJECTS:PROTO_LIB>)
|
|
- target_link_libraries(brpc-shared ${DYNAMIC_LIB})
|
|
+ target_link_libraries(brpc-shared PUBLIC ${DYNAMIC_LIB})
|
|
if(WITH_GLOG)
|
|
- target_link_libraries(brpc-shared ${GLOG_LIB})
|
|
endif()
|
|
if(WITH_THRIFT)
|
|
- target_link_libraries(brpc-shared ${THRIFT_LIB})
|
|
- check_thrift_version(brpc-shared)
|
|
endif()
|
|
SET_TARGET_PROPERTIES(brpc-shared PROPERTIES OUTPUT_NAME brpc CLEAN_DIRECT_OUTPUT 1)
|
|
|
|
target_link_libraries(protoc-gen-mcpack brpc-shared ${DYNAMIC_LIB} pthread)
|
|
|
|
+ target_include_directories(brpc-shared PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
|
install(TARGETS brpc-shared
|
|
+ EXPORT unofficial-brpc-targets
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
@@ -102,8 +107,38 @@ endif()
|
|
|
|
|
|
|
|
+if(NOT BUILD_SHARED_LIBS)
|
|
+target_include_directories(brpc-static PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
|
install(TARGETS brpc-static
|
|
+ EXPORT unofficial-brpc-targets
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
)
|
|
+endif()
|
|
+
|
|
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/unofficial-brpc-config.cmake"
|
|
+[[include(CMakeFindDependencyMacro)
|
|
+find_dependency(OpenSSL)
|
|
+find_dependency(Threads)
|
|
+find_dependency(ZLIB)
|
|
+find_dependency(gflags CONFIG)
|
|
+find_dependency(protobuf CONFIG)
|
|
+find_dependency(leveldb CONFIG)
|
|
+find_dependency(Thrift CONFIG)
|
|
+find_dependency(glog CONFIG)
|
|
+include("${CMAKE_CURRENT_LIST_DIR}/unofficial-brpc-targets.cmake")
|
|
+if(NOT TARGET unofficial::brpc::brpc)
|
|
+ if(TARGET unofficial::brpc::brpc-static)
|
|
+ add_library(unofficial::brpc::brpc ALIAS unofficial::brpc::brpc-static)
|
|
+ else()
|
|
+ add_library(unofficial::brpc::brpc ALIAS unofficial::brpc::brpc-shared)
|
|
+ endif()
|
|
+endif()
|
|
+]])
|
|
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unofficial-brpc-config.cmake" DESTINATION share/unofficial-brpc)
|
|
+
|
|
+install(EXPORT unofficial-brpc-targets
|
|
+ NAMESPACE unofficial::brpc::
|
|
+ DESTINATION share/unofficial-brpc
|
|
+)
|