# 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. cmake_minimum_required(VERSION 3.16...3.28) project(redis_c++ C CXX) include(${CMAKE_CURRENT_LIST_DIR}/../cmake/BrpcExample.cmake) # Install dependencies: # With apt: # sudo apt-get install libreadline-dev # sudo apt-get install ncurses-dev # With yum: # sudo yum install readline-devel # sudo yum install ncurses-devel option(LINK_SO "Whether examples are linked dynamically" OFF) execute_process( COMMAND bash -c "find ${PROJECT_SOURCE_DIR}/../.. -type d -regex \".*output/include$\" | head -n1 | xargs dirname | tr -d '\n'" OUTPUT_VARIABLE OUTPUT_PATH ) if(OUTPUT_PATH) list(PREPEND CMAKE_PREFIX_PATH ${OUTPUT_PATH}) endif() find_package(Threads REQUIRED) find_package(Protobuf REQUIRED) find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h) find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler) # Search for libthrift* by best effort. If it is not found and brpc is # compiled with thrift protocol enabled, a link error would be reported. find_library(THRIFT_LIB NAMES thrift) if (NOT THRIFT_LIB) set(THRIFT_LIB "") endif() find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h) if(LINK_SO) find_library(BRPC_LIB NAMES brpc) else() find_library(BRPC_LIB NAMES libbrpc.a brpc) endif() if((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB)) message(FATAL_ERROR "Fail to find brpc") endif() find_path(GFLAGS_INCLUDE_PATH gflags/gflags.h) find_library(GFLAGS_LIBRARY NAMES gflags libgflags) if((NOT GFLAGS_INCLUDE_PATH) OR (NOT GFLAGS_LIBRARY)) message(FATAL_ERROR "Fail to find gflags") endif() 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() 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 REQUIRED) set(DYNAMIC_LIB Threads::Threads ${GFLAGS_LIBRARY} ${PROTOBUF_LIBRARIES} ${LEVELDB_LIB} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} ${THRIFT_LIB} ${GPERFTOOLS_LIBRARIES} dl ) if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(DYNAMIC_LIB ${DYNAMIC_LIB} pthread "-framework CoreFoundation" "-framework CoreGraphics" "-framework CoreData" "-framework CoreText" "-framework Security" "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" "-Wl,-U,_ProfilerStop" "-Wl,-U,__Z13GetStackTracePPvii" "-Wl,-U,_mallctl" "-Wl,-U,_malloc_stats_print" ) endif() add_executable(redis_cli redis_cli.cpp) brpc_example_configure_target(redis_cli) add_executable(redis_press redis_press.cpp) brpc_example_configure_target(redis_press) add_executable(redis_server redis_server.cpp) brpc_example_configure_target(redis_server) add_executable(redis_cluster_client redis_cluster_client.cpp) brpc_example_configure_target(redis_cluster_client) set(AUX_LIB readline ncurses) target_link_libraries(redis_cli PRIVATE ${BRPC_LIB} ${DYNAMIC_LIB} ${AUX_LIB}) target_link_libraries(redis_press PRIVATE ${BRPC_LIB} ${DYNAMIC_LIB}) target_link_libraries(redis_server PRIVATE ${BRPC_LIB} ${DYNAMIC_LIB}) target_link_libraries(redis_cluster_client PRIVATE ${BRPC_LIB} ${DYNAMIC_LIB})