Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
4eeeeb19
Commit
4eeeeb19
authored
Jan 07, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make all examples compiled alone
parent
c1e16611
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
1744 additions
and
193 deletions
+1744
-193
build_in_travis_ci.sh
build_in_travis_ci.sh
+2
-2
CMakeLists.txt
example/CMakeLists.txt
+0
-30
CMakeLists.txt
example/asynchronous_echo_c++/CMakeLists.txt
+76
-7
CMakeLists.txt
example/backup_request_c++/CMakeLists.txt
+76
-7
CMakeLists.txt
example/cancel_c++/CMakeLists.txt
+76
-7
CMakeLists.txt
example/cascade_echo_c++/CMakeLists.txt
+76
-7
CMakeLists.txt
example/dynamic_partition_echo_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/echo_c++_hulu_pbrpc/CMakeLists.txt
+76
-7
CMakeLists.txt
example/echo_c++_sofa_pbrpc/CMakeLists.txt
+76
-7
CMakeLists.txt
example/echo_c++_ubrpc_compack/CMakeLists.txt
+83
-15
idl_options.proto
example/echo_c++_ubrpc_compack/idl_options.proto
+40
-0
CMakeLists.txt
example/http_c++/CMakeLists.txt
+82
-9
CMakeLists.txt
example/memcache_c++/CMakeLists.txt
+77
-4
CMakeLists.txt
example/multi_threaded_echo_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/multi_threaded_echo_fns_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/multi_threaded_mcpack_c++/CMakeLists.txt
+87
-15
idl_options.proto
example/multi_threaded_mcpack_c++/idl_options.proto
+40
-0
CMakeLists.txt
example/nshead_extension_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/nshead_pb_extension_c++/CMakeLists.txt
+76
-7
CMakeLists.txt
example/parallel_echo_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/partition_echo_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/redis_c++/CMakeLists.txt
+85
-6
CMakeLists.txt
example/selective_echo_c++/CMakeLists.txt
+80
-7
CMakeLists.txt
example/session_data_and_thread_local/CMakeLists.txt
+80
-7
CMakeLists.txt
example/streaming_echo_c++/CMakeLists.txt
+76
-7
No files found.
build_in_travis_ci.sh
View file @
4eeeeb19
...
...
@@ -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
-DB
RPC_DEBUG
=
OFF
-DBUILD_EXAMPLE
=
OFF
-DB
UILD_UNIT_TESTS
=
ON ..
;
then
if
!
cmake
-DBUILD_UNIT_TESTS
=
ON ..
;
then
echo
"Fail to generate Makefile by cmake"
exit
1
fi
...
...
example/CMakeLists.txt
deleted
100644 → 0
View file @
c1e16611
if
(
BUILD_UNIT_TESTS
)
return
()
endif
()
find_package
(
Gperftools
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
add_subdirectory
(
http_c++
)
add_subdirectory
(
asynchronous_echo_c++
)
add_subdirectory
(
backup_request_c++
)
add_subdirectory
(
cancel_c++
)
add_subdirectory
(
cascade_echo_c++
)
add_subdirectory
(
dynamic_partition_echo_c++
)
add_subdirectory
(
echo_c++
)
add_subdirectory
(
echo_c++_hulu_pbrpc
)
add_subdirectory
(
echo_c++_sofa_pbrpc
)
add_subdirectory
(
echo_c++_ubrpc_compack
)
add_subdirectory
(
memcache_c++
)
add_subdirectory
(
multi_threaded_echo_c++
)
add_subdirectory
(
multi_threaded_echo_fns_c++
)
add_subdirectory
(
multi_threaded_mcpack_c++
)
add_subdirectory
(
nshead_extension_c++
)
add_subdirectory
(
nshead_pb_extension_c++
)
add_subdirectory
(
parallel_echo_c++
)
add_subdirectory
(
partition_echo_c++
)
# need readline library
# add_subdirectory(redis_c++)
add_subdirectory
(
selective_echo_c++
)
add_subdirectory
(
session_data_and_thread_local
)
add_subdirectory
(
streaming_echo_c++
)
example/asynchronous_echo_c++/CMakeLists.txt
View file @
4eeeeb19
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
()
example/backup_request_c++/CMakeLists.txt
View file @
4eeeeb19
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
()
example/cancel_c++/CMakeLists.txt
View file @
4eeeeb19
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
()
example/cascade_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
cascade_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
(
cascade_echo_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
cascade_echo_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
cascade_echo_client
brpc
)
target_link_libraries
(
cascade_echo_server
brpc
)
target_link_libraries
(
cascade_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
cascade_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
cascade_echo_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
cascade_echo_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
cascade_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
cascade_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/dynamic_partition_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
dynamic_partition_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
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
dynamic_partition_echo_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
dynamic_partition_echo_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
dynamic_partition_echo_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
dynamic_partition_echo_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
dynamic_partition_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
dynamic_partition_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
dynamic_partition_echo_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
dynamic_partition_echo_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
dynamic_partition_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
dynamic_partition_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/echo_c++_hulu_pbrpc/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
echo_c++_hulu_pbrpc 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
(
echo_hulu_pbrpc_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
echo_hulu_pbrpc_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
echo_hulu_pbrpc_client
brpc
)
target_link_libraries
(
echo_hulu_pbrpc_server
brpc
)
target_link_libraries
(
echo_hulu_pbrpc_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_hulu_pbrpc_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
echo_hulu_pbrpc_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_hulu_pbrpc_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_hulu_pbrpc_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_hulu_pbrpc_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/echo_c++_sofa_pbrpc/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
echo_c++_sofa_pbrpc 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
(
echo_sofa_pbrpc_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
echo_sofa_pbrpc_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
echo_sofa_pbrpc_client
brpc
)
target_link_libraries
(
echo_sofa_pbrpc_server
brpc
)
target_link_libraries
(
echo_sofa_pbrpc_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_sofa_pbrpc_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
echo_sofa_pbrpc_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_sofa_pbrpc_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_sofa_pbrpc_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_sofa_pbrpc_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/echo_c++_ubrpc_compack/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
echo_c++_ubrpc_compack 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
)
set
(
PROTOC_GEN_MCPACK_PATH
""
CACHE STRING
"the path to protoc_gen_mcpack"
)
if
(
"
${
PROTOC_GEN_MCPACK_PATH
}
"
STREQUAL
""
)
message
(
FATAL_ERROR
"Please set PROTOC_GEN_MCPACK_PATH variable(-DPROTOC_GEN_MCPACK_PATH=<value>)."
)
endif
()
include
(
FindThreads
)
include
(
FindProtobuf
)
protobuf_generate_cpp
(
PROTO_SRC PROTO_HEADER echo.proto
)
# include PROTO_HEADER
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
add_custom_target
(
CUSTOM_PROTO ALL
COMMAND
${
PROTOBUF_PROTOC_EXECUTABLE
}
${
PROTO_FLAGS
}
--cpp_out=
${
CMAKE_CURRENT_BINARY_DIR
}
--proto_path=
${
PROTOBUF_INCLUDE_DIR
}
--proto_path=
${
CMAKE_SOURCE_DIR
}
/src --proto_path=
${
CMAKE_SOURCE_DIR
}
/example/echo_c++_ubrpc_compack/ --plugin=protoc-gen-mcpack=
${
CMAKE_CURRENT_BINARY_DIR
}
/../../src/protoc-gen-mcpack --mcpack_out=
${
CMAKE_CURRENT_BINARY_DIR
}
${
CMAKE_SOURCE_DIR
}
/example/echo_c++_ubrpc_compack/echo.proto
DEPENDS protoc-gen-mcpack
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set_source_files_properties
(
${
CMAKE_CURRENT_BINARY_DIR
}
/echo.pb.cc PROPERTIES GENERATED TRUE
)
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
)
execute_process
(
COMMAND
${
PROTOBUF_PROTOC_EXECUTABLE
}
${
PROTO_FLAGS
}
--cpp_out=
${
CMAKE_CURRENT_BINARY_DIR
}
--proto_path=
${
PROTOBUF_INCLUDE_DIR
}
--proto_path=
${
CMAKE_SOURCE_DIR
}
--plugin=protoc-gen-mcpack=
${
PROTOC_GEN_MCPACK_PATH
}
/protoc-gen-mcpack --mcpack_out=
${
CMAKE_CURRENT_BINARY_DIR
}
${
CMAKE_SOURCE_DIR
}
/echo.proto
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
add_executable
(
echo_ubrpc_compack_client client.cpp
${
CMAKE_CURRENT_BINARY_DIR
}
/echo.pb.cc
)
add_executable
(
echo_ubrpc_compack_server server.cpp
${
CMAKE_CURRENT_BINARY_DIR
}
/echo.pb.cc
)
add_dependencies
(
echo_ubrpc_compack_client CUSTOM_PROTO
)
add_dependencies
(
echo_ubrpc_compack_server CUSTOM_PROTO
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
echo_ubrpc_compack_client
brpc
)
target_link_libraries
(
echo_ubrpc_compack_server
brpc
)
target_link_libraries
(
echo_ubrpc_compack_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_ubrpc_compack_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
echo_ubrpc_compack_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_ubrpc_compack_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_ubrpc_compack_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
echo_ubrpc_compack_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/echo_c++_ubrpc_compack/idl_options.proto
0 → 100644
View file @
4eeeeb19
syntax
=
"proto2"
;
// mcpack2pb - Make protobuf be front-end of mcpack/compack
// Copyright (c) 2015 Baidu, Inc.
// Author: Ge,Jun (gejun@baidu.com)
// Date: Mon Oct 19 17:17:36 CST 2015
import
"google/protobuf/descriptor.proto"
;
extend
google
.
protobuf.FileOptions
{
// True to generate mcpack parsing/serializing code
optional
bool
idl_support
=
91000
;
}
enum
ConvertibleIdlType
{
IDL_AUTO
=
0
;
IDL_INT8
=
1
;
IDL_INT16
=
2
;
IDL_INT32
=
3
;
IDL_INT64
=
4
;
IDL_UINT8
=
5
;
IDL_UINT16
=
6
;
IDL_UINT32
=
7
;
IDL_UINT64
=
8
;
IDL_BOOL
=
9
;
IDL_FLOAT
=
10
;
IDL_DOUBLE
=
11
;
IDL_BINARY
=
12
;
IDL_STRING
=
13
;
}
extend
google
.
protobuf.FieldOptions
{
// Mark the idl-type which is inconsistent with proto-type.
optional
ConvertibleIdlType
idl_type
=
91001
;
// Mark the non-optional() vector/array in idl.
optional
int32
idl_on
=
91002
;
// Use this name as the field name for packing instead of the one in proto.
optional
string
idl_name
=
91003
;
}
example/http_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
http_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 http.proto
)
get_filename_component
(
HEADER_DIR
${
PROTO_HEADER
}
DIRECTORY
)
include_directories
(
${
HEADER_DIR
}
)
# include PROTO_HEADER
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
http_client http_client.cpp
)
add_executable
(
http_server http_server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
benchmark_http benchmark_http.cpp
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
http_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
http_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
benchmark_http
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
http_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
http_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
benchmark_http
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
http_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
http_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
benchmark_http
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
http_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
http_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
benchmark_http
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/memcache_c++/CMakeLists.txt
View file @
4eeeeb19
add_executable
(
memcache_client client.cpp
)
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
memcache_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
)
# include PROTO_HEADER
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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
(
memcache_client client.cpp
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
memcache_client
brpc
)
target_link_libraries
(
memcache_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
memcache_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
memcache_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/multi_threaded_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
multi_threaded_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
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
multi_threaded_echo_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
multi_threaded_echo_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
multi_threaded_echo_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
multi_threaded_echo_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/multi_threaded_echo_fns_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
multi_threaded_echo_fns_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
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
multi_threaded_echo_fns_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
multi_threaded_echo_fns_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
multi_threaded_echo_fns_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_fns_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_fns_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_fns_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
multi_threaded_echo_fns_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_fns_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_fns_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_echo_fns_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/multi_threaded_mcpack_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
multi_threaded_mcpack_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
)
set
(
PROTOC_GEN_MCPACK_PATH
""
CACHE STRING
"the path to protoc_gen_mcpack"
)
if
(
"
${
PROTOC_GEN_MCPACK_PATH
}
"
STREQUAL
""
)
message
(
FATAL_ERROR
"Please set PROTOC_GEN_MCPACK_PATH variable(-DPROTOC_GEN_MCPACK_PATH=<value>)."
)
endif
()
include
(
FindThreads
)
include
(
FindProtobuf
)
protobuf_generate_cpp
(
PROTO_SRC PROTO_HEADER echo.proto
)
# include PROTO_HEADER
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
add_custom_target
(
CUSTOM_PROTO_MULTI_THREAD ALL
COMMAND
${
PROTOBUF_PROTOC_EXECUTABLE
}
${
PROTO_FLAGS
}
--cpp_out=
${
CMAKE_CURRENT_BINARY_DIR
}
--proto_path=
${
PROTOBUF_INCLUDE_DIR
}
--proto_path=
${
CMAKE_SOURCE_DIR
}
/src --proto_path=
${
CMAKE_SOURCE_DIR
}
/example/multi_threaded_mcpack_c++ --plugin=protoc-gen-mcpack=
${
CMAKE_CURRENT_BINARY_DIR
}
/../../src/protoc-gen-mcpack --mcpack_out=
${
CMAKE_CURRENT_BINARY_DIR
}
${
CMAKE_SOURCE_DIR
}
/example/multi_threaded_mcpack_c++/echo.proto
DEPENDS protoc-gen-mcpack
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
set_source_files_properties
(
${
CMAKE_CURRENT_BINARY_DIR
}
/echo.pb.cc PROPERTIES GENERATED TRUE
)
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
)
execute_process
(
COMMAND
${
PROTOBUF_PROTOC_EXECUTABLE
}
${
PROTO_FLAGS
}
--cpp_out=
${
CMAKE_CURRENT_BINARY_DIR
}
--proto_path=
${
PROTOBUF_INCLUDE_DIR
}
--proto_path=
${
CMAKE_SOURCE_DIR
}
--plugin=protoc-gen-mcpack=
${
PROTOC_GEN_MCPACK_PATH
}
/protoc-gen-mcpack --mcpack_out=
${
CMAKE_CURRENT_BINARY_DIR
}
${
CMAKE_SOURCE_DIR
}
/echo.proto
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
add_executable
(
multi_threaded_mcpack_client client.cpp
${
CMAKE_CURRENT_BINARY_DIR
}
/echo.pb.cc
)
add_executable
(
multi_threaded_mcpack_server server.cpp
${
CMAKE_CURRENT_BINARY_DIR
}
/echo.pb.cc
)
add_dependencies
(
multi_threaded_mcpack_client CUSTOM_PROTO_MULTI_THREAD
)
add_dependencies
(
multi_threaded_mcpack_server CUSTOM_PROTO_MULTI_THREAD
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
multi_threaded_mcpack_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_mcpack_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_mcpack_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_mcpack_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
multi_threaded_mcpack_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_mcpack_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_mcpack_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
multi_threaded_mcpack_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/multi_threaded_mcpack_c++/idl_options.proto
0 → 100644
View file @
4eeeeb19
syntax
=
"proto2"
;
// mcpack2pb - Make protobuf be front-end of mcpack/compack
// Copyright (c) 2015 Baidu, Inc.
// Author: Ge,Jun (gejun@baidu.com)
// Date: Mon Oct 19 17:17:36 CST 2015
import
"google/protobuf/descriptor.proto"
;
extend
google
.
protobuf.FileOptions
{
// True to generate mcpack parsing/serializing code
optional
bool
idl_support
=
91000
;
}
enum
ConvertibleIdlType
{
IDL_AUTO
=
0
;
IDL_INT8
=
1
;
IDL_INT16
=
2
;
IDL_INT32
=
3
;
IDL_INT64
=
4
;
IDL_UINT8
=
5
;
IDL_UINT16
=
6
;
IDL_UINT32
=
7
;
IDL_UINT64
=
8
;
IDL_BOOL
=
9
;
IDL_FLOAT
=
10
;
IDL_DOUBLE
=
11
;
IDL_BINARY
=
12
;
IDL_STRING
=
13
;
}
extend
google
.
protobuf.FieldOptions
{
// Mark the idl-type which is inconsistent with proto-type.
optional
ConvertibleIdlType
idl_type
=
91001
;
// Mark the non-optional() vector/array in idl.
optional
int32
idl_on
=
91002
;
// Use this name as the field name for packing instead of the one in proto.
optional
string
idl_name
=
91003
;
}
example/nshead_extension_c++/CMakeLists.txt
View file @
4eeeeb19
add_executable
(
nshead_extension_client client.cpp
)
add_executable
(
nshead_extension_server server.cpp
)
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
nshead_extension_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
)
# include PROTO_HEADER
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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
(
nshead_extension_client client.cpp
)
add_executable
(
nshead_extension_server server.cpp
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
nshead_extension_client
brpc
)
target_link_libraries
(
nshead_extension_server
brpc
)
target_link_libraries
(
nshead_extension_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_extension_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
nshead_extension_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_extension_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_extension_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_extension_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/nshead_pb_extension_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
nshead_pb_extension_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
(
nshead_pb_extension_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
nshead_pb_extension_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
nshead_pb_extension_client
brpc
)
target_link_libraries
(
nshead_pb_extension_server
brpc
)
target_link_libraries
(
nshead_pb_extension_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_pb_extension_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
nshead_pb_extension_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_pb_extension_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_pb_extension_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
nshead_pb_extension_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
example/parallel_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
parallel_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
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
parallel_echo_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
parallel_echo_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
parallel_echo_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
parallel_echo_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
parallel_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
parallel_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
parallel_echo_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
parallel_echo_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
parallel_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
parallel_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/partition_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
partition_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
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/redis_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
redis_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)
# 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
(
EXAMPLE_LINK_SO
"Whether examples are linked dynamically"
OFF
)
include
(
FindThreads
)
include
(
FindProtobuf
)
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
(
redis_cli redis_cli.cpp
)
add_executable
(
redis_press redis_press.cpp
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-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"
)
set
(
AUX_LIB readline ncurses
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
redis_cli
brpc
${
AUX_LIB
}
)
target_link_libraries
(
redis_press
brpc
${
AUX_LIB
}
)
target_link_libraries
(
redis_cli
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
AUX_LIB
}
)
target_link_libraries
(
redis_press
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
AUX_LIB
}
)
else
()
target_link_libraries
(
redis_cli
brpc_static
${
DYNAMIC_LIB
}
${
AUX_LIB
}
)
target_link_libraries
(
redis_press
brpc_static
${
DYNAMIC_LIB
}
${
AUX_LIB
}
)
target_link_libraries
(
redis_cli
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
AUX_LIB
}
)
target_link_libraries
(
redis_press
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
AUX_LIB
}
)
endif
()
example/selective_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
selective_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
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
selective_echo_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
selective_echo_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
selective_echo_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
selective_echo_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
selective_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
selective_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
selective_echo_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
selective_echo_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
selective_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
selective_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/session_data_and_thread_local/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
session_data_and_thread_local 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
}
)
find_path
(
GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h
)
find_library
(
GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
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
}
)
set
(
CMAKE_CPP_FLAGS
"-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
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"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DBRPC_ENABLE_CPU_PROFILER"
)
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
(
session_data_and_thread_local_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
session_data_and_thread_local_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
session_data_and_thread_local_client
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
session_data_and_thread_local_server
brpc
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
session_data_and_thread_local_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
session_data_and_thread_local_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
else
()
target_link_libraries
(
session_data_and_thread_local_client
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
session_data_and_thread_local_server
brpc_static
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
session_data_and_thread_local_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
target_link_libraries
(
session_data_and_thread_local_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
${
GPERFTOOLS_LIBRARIES
}
)
endif
()
example/streaming_echo_c++/CMakeLists.txt
View file @
4eeeeb19
cmake_minimum_required
(
VERSION 2.8.10
)
project
(
streaming_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
(
streaming_echo_client client.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
add_executable
(
streaming_echo_server server.cpp
${
PROTO_SRC
}
${
PROTO_HEADER
}
)
if
(
EXAMPLE_LINK_SO
)
target_link_libraries
(
streaming_echo_client
brpc
)
target_link_libraries
(
streaming_echo_server
brpc
)
target_link_libraries
(
streaming_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
streaming_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
else
()
target_link_libraries
(
streaming_echo_client
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
streaming_echo_server
brpc_static
${
DYNAMIC_LIB
}
)
target_link_libraries
(
streaming_echo_client
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
target_link_libraries
(
streaming_echo_server
${
BRPC_LIB
}
${
DYNAMIC_LIB
}
)
endif
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment