Unverified Commit 5c90441f authored by Ge Jun's avatar Ge Jun Committed by GitHub

Merge pull request #197 from brpc/cmake_support

make tools/ support cmake & modify docs/cn/getting_started.md to add cmake
parents b958dfad 55728a34
......@@ -309,6 +309,7 @@ add_subdirectory(src)
if(BUILD_UNIT_TESTS)
add_subdirectory(test)
endif()
add_subdirectory(tools)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/idl_options.pb.h
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/output/include)
......
......@@ -23,10 +23,6 @@ echo "build combination: PURPOSE=$PURPOSE CXX=$CXX CC=$CC"
if [ "$PURPOSE" = "compile-with-bazel" ]; then
runcmd "bazel build -j 12 -c opt --copt -DHAVE_ZLIB=1 //..."
runcmd "bazel test -j 12 -c opt --copt -DHAVE_ZLIB=1 --define=unittest=true //..."
# Build with glog
runcmd "bazel build -j 12 -c opt --copt -DHAVE_ZLIB=1 --define=with_glog=true //..."
runcmd "bazel test -j 12 -c opt --copt -DHAVE_ZLIB=1 --define=with_glog=true --define=unittest=true //..."
exit 0
fi
......
......@@ -36,6 +36,14 @@ To change compiler to clang, add `--cxx=clang++ --cc=clang`.
To not link debugging symbols, add `--nodebugsymbols` and compiled binaries will be much smaller.
### Compile brpc with cmake
```
$ mkdir build && cd build && cmake .. && make
```
To change compiler to clang, overwrite environment variable CC and CXX to clang and clang++.
Use `cmake -DWITH_DEBUG_SYMBOLS=ON ..` to link debugging symbols.
### Run example
```
......@@ -48,6 +56,15 @@ Examples link brpc statically, if you need to link the shared version, `make cle
To run examples with cpu/heap profilers, install `libgoogle-perftools-dev` and re-run `config_brpc.sh` before compiling.
### Run example with cmake
```
$ cd example/echo_c++
$ mkdir build && cd build && cmake .. && make
$ ./echo_server &
$ ./echo_client
```
Examples link brpc statically, if you need to link the shared version, use `cmake -DEXAMPLE_LINK_SO=ON ..`
### Run tests
Install and compile libgtest-dev (which is not compiled yet):
......@@ -59,6 +76,15 @@ The directory of gtest source code may be changed, try `/usr/src/googletest/goog
Rerun `config_brpc.sh`, `make` in test/, and `sh run_tests.sh`
### Run tests with cmake
Install gtest like just written above.
```
$ mkdir build && cd build && cmake -DBUILD_UNIT_TESTS=ON .. && make
$ cd test && sh run_tests.sh
```
## Fedora/CentOS
### Prepare deps
......@@ -89,6 +115,14 @@ To change compiler to clang, add `--cxx=clang++ --cc=clang`.
To not link debugging symbols, add `--nodebugsymbols` and compiled binaries will be much smaller.
### Compile brpc with cmake
```
$ mkdir build && cd build && cmake .. && make
```
To change compiler to clang, overwrite environment variable CC and CXX to clang and clang++.
Use `cmake -DWITH_DEBUG_SYMBOLS=ON ..` to link debugging symbols.
### Run example
```
......@@ -101,12 +135,28 @@ Examples link brpc statically, if you need to link the shared version, `make cle
To run examples with cpu/heap profilers, install `gperftools-devel` and re-run `config_brpc.sh` before compiling.
### Run example with cmake
```
$ cd example/echo_c++
$ mkdir build && cd build && cmake .. && make
$ ./echo_server &
$ ./echo_client
```
Examples link brpc statically, if you need to link the shared version, use `cmake -DEXAMPLE_LINK_SO=ON ..`
### Run tests
Install gtest-devel.
Rerun `config_brpc.sh`, `make` in test/, and `sh run_tests.sh`
### Run tests with cmake
```
$ mkdir build && cd build && cmake -DBUILD_UNIT_TESTS=ON .. && make
$ cd test && sh run_tests.sh
```
## Linux with self-built deps
### Prepare deps
......@@ -144,6 +194,18 @@ $ sh config_brpc.sh --headers=.. --libs=..
$ make
```
### Compile brpc with cmake
git clone brpc. cd into the repo and run
```
$ mkdir build && cd build && cmake -DCMAKE_INCLUDE_PATH="/path/to/dep1/include;/path/to/dep2/include" -DCMAKE_LIBRARY_PATH="/path/to/dep1/lib;/path/to/dep2/lib" .. && make
```
To change compiler to clang, overwrite environment variable CC and CXX to clang and clang++.
Add `-DWITH_DEBUG_SYMBOLS=ON` to link debugging symbols.
# Supported deps
## GCC: 4.8-7.1
......@@ -192,7 +254,7 @@ Code compiled with gcc 4.8.2 and linked to a tcmalloc compiled with earlier GCC
When you meet the issue, compile tcmalloc with the same GCC.
Another common issue with tcmalloc is that it does not return memory to system as early as ptmalloc. So when there's an invalid memory access, the program may not crash directly, instead it crashes at a unrelated place, or even not crash. When you program has weird memory issues, try removing tcmalloc.
Another common issue with tcmalloc is that it does not return memory to system as early as ptmalloc. So when there's an invalid memory access, the program may not crash directly, instead it crashes at a unrelated place, or even not crash. When you program has weird memory issues, try removing tcmalloc.
If you want to use [cpu profiler](cpu_profiler.md) or [heap profiler](heap_profiler.md), do link `libtcmalloc_and_profiler.a`. These two profilers are based on tcmalloc.[contention profiler](contention_profiler.md) does not require tcmalloc.
......@@ -200,11 +262,11 @@ When you remove tcmalloc, not only remove the linkage with tcmalloc but also the
## glog: 3.3+
brpc implementes a default [logging utility](../../src/butil/logging.h) which conflicts with glog. To replace this with glog, add *--with-glog* to config_brpc.sh
brpc implementes a default [logging utility](../../src/butil/logging.h) which conflicts with glog. To replace this with glog, add *--with-glog* to config_brpc.sh or add `-DWITH_GLOG=ON` to cmake.
## valgrind: 3.8+
brpc detects valgrind automatically (and registers stacks of bthread). Older valgrind (say 3.2) is not supported.
brpc detects valgrind automatically (and registers stacks of bthread). Older valgrind(say 3.2) is not supported.
# Track instances
......
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")
use_cxx11()
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/output/bin)
add_subdirectory(parallel_http)
add_subdirectory(rpc_press)
add_subdirectory(rpc_replay)
add_subdirectory(rpc_view)
add_subdirectory(trackme_server)
add_executable(parallel_http parallel_http.cpp)
target_link_libraries(parallel_http brpc_static ${DYNAMIC_LIB})
file(GLOB SOURCES "${CMAKE_SOURCE_DIR}/tools/rpc_press/*.cpp")
add_executable(rpc_press ${SOURCES})
target_link_libraries(rpc_press brpc_static ${DYNAMIC_LIB})
file(GLOB SOURCES "${CMAKE_SOURCE_DIR}/tools/rpc_replay/*.cpp")
add_executable(rpc_replay ${SOURCES})
target_link_libraries(rpc_replay brpc_static ${DYNAMIC_LIB})
include(FindProtobuf)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER view.proto)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(rpc_view rpc_view.cpp ${PROTO_SRC})
target_link_libraries(rpc_view brpc_static ${DYNAMIC_LIB})
add_executable(trackme_server trackme_server.cpp)
target_link_libraries(trackme_server brpc_static ${DYNAMIC_LIB})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment