Skip to content

Commit

Permalink
fix CMakeList.txt in examples and rename BUILD to BUILD.bazel to avoi…
Browse files Browse the repository at this point in the history
…d conflict with cmake
  • Loading branch information
jamesge committed Dec 5, 2020
1 parent 8ff49b3 commit e93e0c2
Show file tree
Hide file tree
Showing 46 changed files with 192 additions and 2,085 deletions.
File renamed without changes.
87 changes: 16 additions & 71 deletions docs/cn/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,32 @@ $ sh run_tests.sh

### Compile brpc with cmake
```shell
mkdir bld && cd bld && cmake .. && make
cmake -B build && cmake --build build -j6
```
To change compiler to clang, overwrite environment variable CC and CXX to clang and clang++.
To help VSCode or Emacs(LSP) to understand code correctly, add `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to generate `compile_commands.json`

To not link debugging symbols, use `rm -f CMakeCache.txt && cmake -DWITH_DEBUG_SYMBOLS=OFF ..` and compiled binaries will be much smaller.
To change compiler to clang, overwrite environment variable `CC` and `CXX` to `clang` and `clang++` respectively.

To use brpc with glog, add `-DWITH_GLOG=ON`.
To not link debugging symbols, remove `build/CMakeCache.txt` and cmake with `-DWITH_DEBUG_SYMBOLS=OFF`

To enable [thrift support](../en/thrift.md), install thrift first and add `-DWITH_THRIFT=ON`.
To use brpc with glog, cmake with `-DWITH_GLOG=ON`.

To enable [thrift support](../en/thrift.md), install thrift first and cmake with `-DWITH_THRIFT=ON`.

**Run example with cmake**

```shell
$ cd example/echo_c++
$ mkdir bld && cd bld && cmake .. && make
$ cmake -B build && cmake --build build -j4
$ ./echo_server &
$ ./echo_client
```
Examples link brpc statically, if you need to link the shared version, use `rm -f CMakeCache.txt && cmake -DLINK_SO=ON ..`
Examples link brpc statically, if you need to link the shared version, remove `CMakeCache.txt` and cmake with `-DLINK_SO=ON`

**Run tests**

```shell
$ mkdir bld && cd bld && cmake -DBUILD_UNIT_TESTS=ON .. && make && make test
$ mkdir build && cd build && cmake -DBUILD_UNIT_TESTS=ON .. && make && make test
```

## Fedora/CentOS
Expand Down Expand Up @@ -161,31 +165,7 @@ $ sh run_tests.sh
```

### Compile brpc with cmake
```shell
mkdir bld && cd bld && cmake .. && make
```
To change compiler to clang, overwrite environment variable CC and CXX to clang and clang++.

To not link debugging symbols, use `rm -f CMakeCache.txt && cmake -DWITH_DEBUG_SYMBOLS=OFF ..` and compiled binaries will be much smaller.

To use brpc with glog, add `-DWITH_GLOG=ON`.

To enable [thrift support](../en/thrift.md), install thrift first and add `-DWITH_THRIFT=ON`.

**Run example**

```shell
$ cd example/echo_c++
$ mkdir bld && cd bld && cmake .. && make
$ ./echo_server &
$ ./echo_client
```
Examples link brpc statically, if you need to link the shared version, use `rm -f CMakeCache.txt && cmake -DLINK_SO=ON ..`

**Run tests**
```shell
$ mkdir bld && cd bld && cmake -DBUILD_UNIT_TESTS=ON .. && make && make test
```
Same with [here](#compile-brpc-with-cmake)

## Linux with self-built deps

Expand Down Expand Up @@ -229,20 +209,7 @@ $ make
```

### Compile brpc with cmake

git clone brpc. cd into the repo and run

```shell
mkdir bld && cd bld && 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++.

To not link debugging symbols, use `rm -f CMakeCache.txt && cmake -DWITH_DEBUG_SYMBOLS=OFF ..` and compiled binaries will be much smaller.

To use brpc with glog, add `-DWITH_GLOG=ON`.

To enable [thrift support](../en/thrift.md), install thrift first and add `-DWITH_THRIFT=ON`.
Same with [here](#compile-brpc-with-cmake)

## MacOS

Expand All @@ -267,7 +234,7 @@ brew install gperftools

If you need to run tests, download and compile googletest (which is not compiled yet):
```shell
git clone https://github.com/google/googletest -b release-1.10.0 && cd googletest/googletest && mkdir bld && cd bld && cmake -DCMAKE_CXX_FLAGS="-std=c++11" .. && make
git clone https://github.com/google/googletest -b release-1.10.0 && cd googletest/googletest && mkdir build && cd build && cmake -DCMAKE_CXX_FLAGS="-std=c++11" .. && make
```
After the compilation, copy include/ and lib/ into /usr/local/include and /usr/local/lib respectively to expose gtest to all apps

Expand Down Expand Up @@ -302,29 +269,7 @@ $ sh run_tests.sh
```

### Compile brpc with cmake
```shell
mkdir bld && cd bld && cmake .. && make
```

To not link debugging symbols, use `rm -f CMakeCache.txt && cmake -DWITH_DEBUG_SYMBOLS=OFF ..` and compiled binaries will be much smaller.

To use brpc with glog, add `-DWITH_GLOG=ON`.

To enable [thrift support](../en/thrift.md), install thrift first and add `-DWITH_THRIFT=ON`.

**Run example with cmake**
```shell
$ cd example/echo_c++
$ mkdir bld && cd bld && cmake .. && make
$ ./echo_server &
$ ./echo_client
```
Examples link brpc statically, if you need to link the shared version, use `rm -f CMakeCache.txt && cmake -DLINK_SO=ON ..`

**Run tests**
```shell
$ mkdir bld && cd bld && cmake -DBUILD_UNIT_TESTS=ON .. && make && make test
```
Same with [here](#compile-brpc-with-cmake)

# Supported deps

Expand Down
2 changes: 1 addition & 1 deletion docs/cn/thrift.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib --with-thrift
# Fedora/CentOS
sh config_brpc.sh --headers=/usr/include --libs=/usr/lib64 --with-thrift
# Or use cmake
mkdir bld && cd bld && cmake ../ -DWITH_THRIFT=1
mkdir build && cd build && cmake ../ -DWITH_THRIFT=1
```
更多编译选项请阅读[Getting Started](../cn/getting_started.md)

Expand Down
2 changes: 1 addition & 1 deletion docs/en/thrift.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib --with-thrift
# Fedora/CentOS
sh config_brpc.sh --headers=/usr/include --libs=/usr/lib64 --with-thrift
# Or use cmake
mkdir bld && cd bld && cmake ../ -DWITH_THRIFT=ON
mkdir build && cd build && cmake ../ -DWITH_THRIFT=ON
```
Read [Getting Started](../cn/getting_started.md) for more compilation options.

Expand Down
17 changes: 8 additions & 9 deletions example/asynchronous_echo_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
endif()
include_directories(${LEVELDB_INCLUDE_PATH})

find_library(SSL_LIB NAMES ssl)
if (NOT SSL_LIB)
message(FATAL_ERROR "Fail to find ssl")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OPENSSL_ROOT_DIR
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()

find_library(CRYPTO_LIB NAMES crypto)
if (NOT CRYPTO_LIB)
message(FATAL_ERROR "Fail to find crypto")
endif()
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${THRIFT_LIB}
${THRIFTNB_LIB}
dl
Expand Down
19 changes: 10 additions & 9 deletions example/auto_concurrency_limiter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,24 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
endif()
include_directories(${LEVELDB_INCLUDE_PATH})

find_library(SSL_LIB NAMES ssl)
if (NOT SSL_LIB)
message(FATAL_ERROR "Fail to find ssl")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OPENSSL_ROOT_DIR
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()

find_library(CRYPTO_LIB NAMES crypto)
if (NOT CRYPTO_LIB)
message(FATAL_ERROR "Fail to find crypto")
endif()
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${THRIFT_LIB}
${THRIFTNB_LIB}
dl
)

Expand Down
17 changes: 8 additions & 9 deletions example/backup_request_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
endif()
include_directories(${LEVELDB_INCLUDE_PATH})

find_library(SSL_LIB NAMES ssl)
if (NOT SSL_LIB)
message(FATAL_ERROR "Fail to find ssl")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OPENSSL_ROOT_DIR
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()

find_library(CRYPTO_LIB NAMES crypto)
if (NOT CRYPTO_LIB)
message(FATAL_ERROR "Fail to find crypto")
endif()
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${THRIFT_LIB}
${THRIFTNB_LIB}
dl
Expand Down
17 changes: 8 additions & 9 deletions example/cancel_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
endif()
include_directories(${LEVELDB_INCLUDE_PATH})

find_library(SSL_LIB NAMES ssl)
if (NOT SSL_LIB)
message(FATAL_ERROR "Fail to find ssl")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OPENSSL_ROOT_DIR
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()

find_library(CRYPTO_LIB NAMES crypto)
if (NOT CRYPTO_LIB)
message(FATAL_ERROR "Fail to find crypto")
endif()
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${THRIFT_LIB}
${THRIFTNB_LIB}
dl
Expand Down
17 changes: 8 additions & 9 deletions example/cascade_echo_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,22 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
endif()
include_directories(${LEVELDB_INCLUDE_PATH})

find_library(SSL_LIB NAMES ssl)
if (NOT SSL_LIB)
message(FATAL_ERROR "Fail to find ssl")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OPENSSL_ROOT_DIR
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()

find_library(CRYPTO_LIB NAMES crypto)
if (NOT CRYPTO_LIB)
message(FATAL_ERROR "Fail to find crypto")
endif()
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${THRIFT_LIB}
${THRIFTNB_LIB}
dl
Expand Down
18 changes: 9 additions & 9 deletions example/dynamic_partition_echo_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB))
endif()
include_directories(${LEVELDB_INCLUDE_PATH})

find_library(SSL_LIB NAMES ssl)
if (NOT SSL_LIB)
message(FATAL_ERROR "Fail to find ssl")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OPENSSL_ROOT_DIR
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()

find_library(CRYPTO_LIB NAMES crypto)
if (NOT CRYPTO_LIB)
message(FATAL_ERROR "Fail to find crypto")
endif()
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})


set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${SSL_LIB}
${CRYPTO_LIB}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${THRIFT_LIB}
${THRIFTNB_LIB}
dl
Expand Down
9 changes: 5 additions & 4 deletions example/echo_c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
"/usr/local/opt/openssl" # Homebrew installed OpenSSL
)
endif()
include_directories(${OPENSSL_INCLUDE_DIR})
find_package(OpenSSL)

add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

set(DYNAMIC_LIB
${CMAKE_THREAD_LIBS_INIT}
Expand Down Expand Up @@ -139,5 +137,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
"-Wl,-U,_ProfilerStop")
endif()

add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})

target_link_libraries(echo_client ${BRPC_LIB} ${DYNAMIC_LIB})
target_link_libraries(echo_server ${BRPC_LIB} ${DYNAMIC_LIB})
Loading

0 comments on commit e93e0c2

Please sign in to comment.