Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix check for VCPKG_TOOLCHAIN in Cmake files #219

Merged
merged 3 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,37 @@ project(srpc
include(CheckIncludeFile)
include(CheckIncludeFileCXX)

find_library(LZ4_LIBRARY NAMES lz4)
check_include_file("lz4.h" LZ4_INSTALLED)
if (NOT LZ4_INSTALLED)
if (NOT LZ4_INSTALLED AND ${LZ4_LIBRARY} STREQUAL "LZ4_LIBRARY-NOTFOUND")
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lz4/lib/lz4.h")
message( FATAL_ERROR "Lz4 is neither installed not in third_party!")
endif ()
else ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lz4/lib/lz4.h")
message("Lz4 third_party FOUND. Use for source code dependencies.")
set(LZ4_INSTALLED 0)
set(LZ4_INSTALLED 0 CACHE INTERNAL "check_lz4_installed")
else ()
find_path(LZ4_INCLUDE_DIR NAMES "lz4.h")
include_directories(${LZ4_INCLUDE_DIR})
set(LZ4_INSTALLED 1 CACHE INTERNAL "check_lz4_installed")
endif ()
endif ()

find_package(Snappy)
check_include_file_cxx("snappy.h" SNAPPY_INSTALLED)
if (NOT SNAPPY_INSTALLED)
if (NOT SNAPPY_INSTALLED AND NOT ${Snappy_FOUND})
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/snappy/cmake")
message( FATAL_ERROR "Snappy is neither installed not in third_party!")
endif ()
else ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/snappy/cmake")
message("Snappy third_party FOUND. Use for source code dependencies.")
set(SNAPPY_INSTALLED 0)
set(SNAPPY_INSTALLED 0 CACHE INTERNAL "check_snappy_installed")
else ()
find_path(Snappy_INCLUDE_DIR NAMES "snappy.h")
include_directories(${Snappy_INCLUDE_DIR})
set(SNAPPY_INSTALLED 1 CACHE INTERNAL "check_snappy_installed")
endif ()
endif ()

Expand Down Expand Up @@ -99,10 +109,14 @@ add_subdirectory(src)
include(CMakePackageConfigHelpers)
set(CONFIG_INC_DIR ${INC_DIR})
set(CONFIG_LIB_DIR ${LIB_DIR})
if(NOT VCPKG_TOOLCHAIN)
set(CONFIG_BIN_DIR ${BIN_DIR})
else()

if (VCPKG_TOOLCHAIN AND EXISTS "${CMAKE_INSTALL_PREFIX}/tools/srpc")
set(CONFIG_BIN_DIR ${CMAKE_INSTALL_PREFIX}/tools/srpc)
set(WITH_VCPKG_TOOLCHAIN 1 CACHE INTERNAL "build_with_vcpkg_toolchain")
message("Install with VCPKG toolchain. Dir ${CMAKE_INSTALL_PREFIX}/tools/srpc.")
else()
set(CONFIG_BIN_DIR ${BIN_DIR})
set(WITH_VCPKG_TOOLCHAIN 0 CACHE INTERNAL "build_with_vcpkg_toolchain")
endif()

configure_package_config_file(
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists_Headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ if (NOT LZ4_INSTALLED)
)
endif ()

if(NOT VCPKG_TOOLCHAIN)
set(INCLUDE_HEADERS ${SRC_HEADERS} ${SNAPPY_HEADERS} ${LZ4_HEADERS})
else()
if (WITH_VCPKG_TOOLCHAIN)
set(INCLUDE_HEADERS ${SRC_HEADERS})
else()
set(INCLUDE_HEADERS ${SRC_HEADERS} ${SNAPPY_HEADERS} ${LZ4_HEADERS})
endif()

42 changes: 34 additions & 8 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ find_package(OpenSSL REQUIRED)
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")
if (WIN32)
find_package(Protobuf CONFIG REQUIRED)
find_library(LZ4_LIBRARY NAMES lz4)
find_package(Snappy CONFIG REQUIRED)
else ()
find_package(Protobuf REQUIRED)
endif ()
Expand Down Expand Up @@ -86,16 +88,40 @@ else ()
endif ()

if (APPLE)
set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf z)
set(SRPC_LIB
srpc
workflow
pthread
OpenSSL::SSL
OpenSSL::Crypto
protobuf
z
)
elseif (WIN32)
set(SRPC_LIB srpc workflow ws2_32 wsock32 OpenSSL::SSL OpenSSL::Crypto)
set(SRPC_LIB
srpc
workflow
ws2_32
wsock32
OpenSSL::SSL
OpenSSL::Crypto
protobuf::libprotobuf
ZLIB::ZLIB
Snappy::snappy
${LZ4_LIBRARY}
)
else ()
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/snappy/cmake)
set(SRPC_LIB srpc snappy lz4)
set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf snappy lz4 z)
else ()
set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf z)
endif ()
set(SRPC_LIB
srpc
workflow
pthread
OpenSSL::SSL
OpenSSL::Crypto
protobuf
z
${SNAPPY_LIB}
${LZ4_LIB}
)
endif ()

add_executable(server server.cc ${PROTO_SRCS} ${PROTO_HDRS})
Expand Down
8 changes: 4 additions & 4 deletions benchmark/client_cdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void do_echo_pb(CLIENT *client, int idx)

if (++query_count % 100 > 0)
{
client->echo_pb(&req, [client, ns_st, &latency_list, &mutex](EmptyPBMsg *response, RPCContext *ctx) {
client->echo_pb(&req, [ns_st, &latency_list, &mutex](EmptyPBMsg *response, RPCContext *ctx) {
if (ctx->success())
{
//printf("%s\n", ctx->get_remote_ip().c_str());
Expand All @@ -65,7 +65,7 @@ static void do_echo_pb(CLIENT *client, int idx)
}
else
{
client->slow_pb(&req, [client, ns_st](EmptyPBMsg *response, RPCContext *ctx) {
client->slow_pb(&req, [](EmptyPBMsg *response, RPCContext *ctx) {
slow_count++;
if (!ctx->success())
printf("status[%d] error[%d] errmsg:%s\n", ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
Expand Down Expand Up @@ -93,7 +93,7 @@ static void do_echo_thrift(CLIENT *client, int idx)

if (++query_count % 100 > 0)
{
client->echo_thrift(&req, [client, ns_st, &latency_list, &mutex](BenchmarkThrift::echo_thriftResponse *response, RPCContext *ctx) {
client->echo_thrift(&req, [ns_st, &latency_list, &mutex](BenchmarkThrift::echo_thriftResponse *response, RPCContext *ctx) {
if (ctx->success())
{
//printf("%s\n", ctx->get_remote_ip().c_str());
Expand All @@ -114,7 +114,7 @@ static void do_echo_thrift(CLIENT *client, int idx)
}
else
{
client->slow_thrift(&slow_req, [client, ns_st](BenchmarkThrift::slow_thriftResponse *response, RPCContext *ctx) {
client->slow_thrift(&slow_req, [](BenchmarkThrift::slow_thriftResponse *response, RPCContext *ctx) {
slow_count++;
if (!ctx->success())
printf("status[%d] error[%d] errmsg:%s\n", ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
Expand Down
8 changes: 3 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ else ()
set (HAVE_SYS_UIO_H_01 true)
endif ()

if (NOT VCPKG_TOOLCHAIN)

if (WITH_VCPKG_TOOLCHAIN)
find_package(Workflow REQUIRED CONFIG)
else ()
# Try to find the package if workflow is not installed, otherwise proceed with find_package()
if (NOT WORKFLOW_INSTALLED)
find_package(Workflow REQUIRED CONFIG HINTS ../workflow)
Expand All @@ -44,9 +45,6 @@ if (NOT VCPKG_TOOLCHAIN)
if (LZ4_INSTALLED)
set(LZ4_LIB lz4)
endif ()

else()
find_package(Workflow REQUIRED CONFIG)
endif()

include_directories(
Expand Down
16 changes: 4 additions & 12 deletions src/compress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ set(SRC

set_property(SOURCE rpc_compress_snappy.cc APPEND PROPERTY COMPILE_OPTIONS "-fno-rtti")

if (NOT VCPKG_TOOLCHAIN)

if (WITH_VCPKG_TOOLCHAIN)
add_library(${PROJECT_NAME} OBJECT ${SRC})
target_link_libraries(${PROJECT_NAME} lz4 snappy)
else ()
if (SNAPPY_INSTALLED)
set(SNAPPY_LIB snappy)
else ()
Expand Down Expand Up @@ -47,15 +49,5 @@ if (NOT VCPKG_TOOLCHAIN)
${SNAPPY_SRC}
${LZ4_SRC}
)

# if ("${SNAPPY_INSTALLED}${LZ4_INSTALLED}")
# target_link_libraries(${PROJECT_NAME} ${SNAPPY_LIB} ${LZ4_LIB})
# endif()
else()
add_library(
${PROJECT_NAME} OBJECT
${SRC}
)
target_link_libraries(${PROJECT_NAME} lz4 snappy)
endif()

2 changes: 0 additions & 2 deletions src/module/rpc_filter_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ RPCMetricsOTel::RPCMetricsOTel(const std::string& url,
redirect_max(redirect_max),
retry_max(retry_max),
policy(report_threshold, report_interval_msec),
report_status(false),
report_counts(0)
{
}
Expand All @@ -398,7 +397,6 @@ RPCMetricsOTel::RPCMetricsOTel(const std::string& url) :
redirect_max(OTLP_HTTP_REDIRECT_MAX),
retry_max(OTLP_HTTP_RETRY_MAX),
policy(RPC_REPORT_THREHOLD_DEFAULT, RPC_REPORT_INTERVAL_DEFAULT),
report_status(false),
report_counts(0)
{
}
Expand Down
1 change: 0 additions & 1 deletion src/module/rpc_filter_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ class RPCMetricsOTel : public RPCMetricsFilter
int retry_max;
Collector collector;
RPCFilterPolicy policy;
bool report_status;
size_t report_counts;
std::mutex mutex;
std::map<std::string, std::string> attributes;
Expand Down
36 changes: 32 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ endif ()
# find_package(Workflow REQUIRED)
#endif()

find_package(srpc REQUIRED CONFIG HINTS ..)
include_directories(
${OPENSSL_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
Expand Down Expand Up @@ -103,9 +102,28 @@ add_custom_target(
set(GTEST_LIB GTest::GTest GTest::Main)

if (APPLE)
set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf z)
set(SRPC_LIB
srpc
workflow
pthread
OpenSSL::SSL
OpenSSL::Crypto
protobuf
z
)
elseif (WIN32)
set(SRPC_LIB srpc workflow ws2_32 wsock32 OpenSSL::SSL OpenSSL::Crypto)
set(SRPC_LIB
srpc
workflow
ws2_32
wsock32
OpenSSL::SSL
OpenSSL::Crypto
protobuf::libprotobuf
ZLIB::ZLIB
Snappy::snappy
${LZ4_LIBRARY}
)
set(GTEST_LIB GTest::gtest GTest::gtest_main)
else ()
if (SNAPPY_INSTALLED)
Expand All @@ -116,7 +134,17 @@ else ()
set(LZ4_LIB lz4)
endif ()

set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf z ${SNAPPY_LIB} ${LZ4_LIB})
set(SRPC_LIB
srpc
workflow
pthread
OpenSSL::SSL
OpenSSL::Crypto
protobuf
z
${SNAPPY_LIB}
${LZ4_LIB}
)
endif ()

foreach(src ${TEST_LIST})
Expand Down
38 changes: 34 additions & 4 deletions tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ find_package(srpc REQUIRED CONFIG HINTS ..)
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")
if (WIN32)
find_package(Protobuf CONFIG REQUIRED)
find_library(LZ4_LIBRARY NAMES lz4)
find_package(Snappy CONFIG REQUIRED)
else ()
find_package(Protobuf REQUIRED)
endif ()
Expand Down Expand Up @@ -53,7 +55,6 @@ find_package(ZLIB REQUIRED)
# find_package(Workflow REQUIRED)
#endif()

find_package(srpc REQUIRED CONFIG HINTS ..)
include_directories(
${OPENSSL_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
Expand Down Expand Up @@ -102,11 +103,40 @@ set(TUTORIAL_PB_LIST
)

if (APPLE)
set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf z)
set(SRPC_LIB
srpc
workflow
pthread
OpenSSL::SSL
OpenSSL::Crypto
protobuf
z
)
elseif (WIN32)
set(SRPC_LIB srpc workflow ws2_32 wsock32 OpenSSL::SSL OpenSSL::Crypto protobuf::libprotobuf ZLIB::ZLIB)
set(SRPC_LIB
srpc
workflow
ws2_32
wsock32
OpenSSL::SSL
OpenSSL::Crypto
protobuf::libprotobuf
ZLIB::ZLIB
Snappy::snappy
${LZ4_LIBRARY}
)
else ()
set(SRPC_LIB srpc workflow pthread OpenSSL::SSL OpenSSL::Crypto protobuf z ${SNAPPY_LIB} ${LZ4_LIB})
set(SRPC_LIB
srpc
workflow
pthread
OpenSSL::SSL
OpenSSL::Crypto
protobuf
z
${SNAPPY_LIB}
${LZ4_LIB}
)
endif ()

foreach(src ${TUTORIAL_PB_LIST})
Expand Down