Skip to content

Commit

Permalink
make all examples compiled alone
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujiashun committed Jan 7, 2018
1 parent c1e1661 commit 4eeeeb1
Show file tree
Hide file tree
Showing 25 changed files with 1,744 additions and 193 deletions.
4 changes: 2 additions & 2 deletions build_in_travis_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ fi
echo "start building by cmake"
rm -rf build && mkdir build && cd build
if [ "$PURPOSE" = "compile" ]; then
if ! cmake -DBRPC_DEBUG=OFF -DBUILD_EXAMPLE=OFF -DBUILD_UNIT_TESTS=OFF ..; then
if ! cmake ..; then
echo "Fail to generate Makefile by cmake"
exit 1
fi
make -j4
elif [ "$PURPOSE" = "unittest" ]; then
if ! cmake -DBRPC_DEBUG=OFF -DBUILD_EXAMPLE=OFF -DBUILD_UNIT_TESTS=ON ..; then
if ! cmake -DBUILD_UNIT_TESTS=ON ..; then
echo "Fail to generate Makefile by cmake"
exit 1
fi
Expand Down
30 changes: 0 additions & 30 deletions example/CMakeLists.txt

This file was deleted.

83 changes: 76 additions & 7 deletions example/asynchronous_echo_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
cmake_minimum_required(VERSION 2.8.10)
project(asynchronous_echo_c++ C CXX)

# if you want to specify the path of brpc header and lib,
# set the following two variables.
#set(CMAKE_INCLUDE_PATH /path/to/include)
#set(CMAKE_LIBRARY_PATH /path/to/lib)

option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)

include(FindThreads)
include(FindProtobuf)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
# include PROTO_HEADER
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h)
if(EXAMPLE_LINK_SO)
find_library(BRPC_LIB NAMES brpc)
else()
find_library(BRPC_LIB NAMES libbrpc_static.a brpc)
endif()
if((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
message(FATAL_ERROR "Fail to find brpc")
endif()
include_directories(${BRPC_INCLUDE_PATH})

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()
include_directories(${GFLAGS_INCLUDE_PATH})

execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
if(${GFLAGS_NS} STREQUAL "GFLAGS_NAMESPACE")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
endif()
set(CMAKE_CPP_FLAGS "-DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")

if(CMAKE_VERSION VERSION_LESS "3.1.3")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
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()
include_directories(${LEVELDB_INCLUDE_PATH})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
ssl
crypto
dl
)

add_executable(asynchronous_echo_client client.cpp ${PROTO_SRC})
add_executable(asynchronous_echo_server server.cpp ${PROTO_SRC})

if(EXAMPLE_LINK_SO)
target_link_libraries(asynchronous_echo_client brpc)
target_link_libraries(asynchronous_echo_server brpc)
target_link_libraries(asynchronous_echo_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(asynchronous_echo_server ${BRPC_LIB} ${DYNAMIC_LIB})
else()
target_link_libraries(asynchronous_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(asynchronous_echo_server brpc_static ${DYNAMIC_LIB})
target_link_libraries(asynchronous_echo_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(asynchronous_echo_server ${BRPC_LIB} ${DYNAMIC_LIB})
endif()
83 changes: 76 additions & 7 deletions example/backup_request_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
cmake_minimum_required(VERSION 2.8.10)
project(backup_request_c++ C CXX)

# if you want to specify the path of brpc header and lib,
# set the following two variables.
#set(CMAKE_INCLUDE_PATH /path/to/include)
#set(CMAKE_LIBRARY_PATH /path/to/lib)

option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)

include(FindThreads)
include(FindProtobuf)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
# include PROTO_HEADER
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h)
if(EXAMPLE_LINK_SO)
find_library(BRPC_LIB NAMES brpc)
else()
find_library(BRPC_LIB NAMES libbrpc_static.a brpc)
endif()
if((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
message(FATAL_ERROR "Fail to find brpc")
endif()
include_directories(${BRPC_INCLUDE_PATH})

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()
include_directories(${GFLAGS_INCLUDE_PATH})

execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
if(${GFLAGS_NS} STREQUAL "GFLAGS_NAMESPACE")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
endif()
set(CMAKE_CPP_FLAGS "-DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")

if(CMAKE_VERSION VERSION_LESS "3.1.3")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
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()
include_directories(${LEVELDB_INCLUDE_PATH})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
ssl
crypto
dl
)

add_executable(backup_request_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(backup_request_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})

if(EXAMPLE_LINK_SO)
target_link_libraries(backup_request_client brpc)
target_link_libraries(backup_request_server brpc)
target_link_libraries(backup_request_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(backup_request_server ${BRPC_LIB} ${DYNAMIC_LIB})
else()
target_link_libraries(backup_request_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(backup_request_server brpc_static ${DYNAMIC_LIB})
target_link_libraries(backup_request_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(backup_request_server ${BRPC_LIB} ${DYNAMIC_LIB})
endif()
83 changes: 76 additions & 7 deletions example/cancel_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
cmake_minimum_required(VERSION 2.8.10)
project(cancel_c++ C CXX)

# if you want to specify the path of brpc header and lib,
# set the following two variables.
#set(CMAKE_INCLUDE_PATH /path/to/include)
#set(CMAKE_LIBRARY_PATH /path/to/lib)

option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)

include(FindThreads)
include(FindProtobuf)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
# include PROTO_HEADER
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h)
if(EXAMPLE_LINK_SO)
find_library(BRPC_LIB NAMES brpc)
else()
find_library(BRPC_LIB NAMES libbrpc_static.a brpc)
endif()
if((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB))
message(FATAL_ERROR "Fail to find brpc")
endif()
include_directories(${BRPC_INCLUDE_PATH})

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()
include_directories(${GFLAGS_INCLUDE_PATH})

execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
if(${GFLAGS_NS} STREQUAL "GFLAGS_NAMESPACE")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
endif()
set(CMAKE_CPP_FLAGS "-DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")

if(CMAKE_VERSION VERSION_LESS "3.1.3")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
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()
include_directories(${LEVELDB_INCLUDE_PATH})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
ssl
crypto
dl
)

add_executable(cancel_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(cancel_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})

if(EXAMPLE_LINK_SO)
target_link_libraries(cancel_client brpc)
target_link_libraries(cancel_server brpc)
target_link_libraries(cancel_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(cancel_server ${BRPC_LIB} ${DYNAMIC_LIB})
else()
target_link_libraries(cancel_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(cancel_server brpc_static ${DYNAMIC_LIB})
target_link_libraries(cancel_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(cancel_server ${BRPC_LIB} ${DYNAMIC_LIB})
endif()
Loading

0 comments on commit 4eeeeb1

Please sign in to comment.