-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
details: #12
- Loading branch information
Showing
15 changed files
with
99 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_subdirectory(atomic) | ||
add_subdirectory(block) | ||
add_subdirectory(counter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,28 @@ | ||
cmake_minimum_required(VERSION 2.8.10) | ||
project(atomic C CXX) | ||
|
||
option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF) | ||
option(LINK_TCMALLOC "Link tcmalloc if possible" ON) | ||
|
||
execute_process( | ||
COMMAND bash -c "find ${CMAKE_SOURCE_DIR}/../.. -type d -path \"*output/include/braft\" | xargs dirname | xargs dirname | tr -d '\n'" | ||
OUTPUT_VARIABLE OUTPUT_PATH | ||
) | ||
|
||
set(CMAKE_PREFIX_PATH ${OUTPUT_PATH}) | ||
|
||
include(FindThreads) | ||
include(FindProtobuf) | ||
|
||
if (NOT PROTOBUF_PROTOC_EXECUTABLE) | ||
get_filename_component(PROTO_LIB_DIR ${PROTOBUF_LIBRARY} DIRECTORY) | ||
set (PROTOBUF_PROTOC_EXECUTABLE "${PROTO_LIB_DIR}/../bin/protoc") | ||
endif() | ||
|
||
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER atomic.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) | ||
find_library(BRAFT_LIB NAMES braft) | ||
else() | ||
find_library(BRPC_LIB NAMES libbrpc.a brpc) | ||
find_library(BRAFT_LIB NAMES libbraft.a braft) | ||
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(BRAFT_INCLUDE_PATH NAMES braft/raft.h) | ||
if ((NOT BRAFT_INCLUDE_PATH) OR (NOT BRAFT_LIB)) | ||
message (FATAL_ERROR "Fail to find braft") | ||
endif() | ||
include_directories(${BRAFT_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}) | ||
|
||
find_path(GLOG_INCLUDE_PATH glog/logging.h) | ||
find_library(GLOG_LIBRARY NAMES glog libglog) | ||
if((NOT GLOG_INCLUDE_PATH) OR (NOT GLOG_LIBRARY)) | ||
message(FATAL_ERROR "Fail to find glog") | ||
endif() | ||
include_directories(${GLOG_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() | ||
|
||
if (LINK_TCMALLOC) | ||
find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h) | ||
find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler) | ||
if (GPERFTOOLS_INCLUDE_DIR AND GPERFTOOLS_LIBRARIES) | ||
set(CMAKE_CXX_FLAGS "-DBRPC_ENABLE_CPU_PROFILER") | ||
include_directories(${GPERFTOOLS_INCLUDE_DIR}) | ||
else () | ||
set (GPERFTOOLS_LIBRARIES "") | ||
endif () | ||
endif () | ||
|
||
set(CMAKE_CPP_FLAGS "-DGFLAGS_NS=${GFLAGS_NS}") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -D__const__=__unused__ -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer") | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
# require at least gcc 4.8 | ||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) | ||
message(FATAL_ERROR "GCC is too old, please install a newer version supporting C++11") | ||
endif() | ||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
# require at least clang 3.3 | ||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3) | ||
message(FATAL_ERROR "Clang is too old, please install a newer version supporting C++11") | ||
endif() | ||
else() | ||
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.") | ||
endif() | ||
|
||
if(CMAKE_VERSION VERSION_LESS "3.1.3") | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
endif() | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++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}) | ||
|
||
add_executable(atomic_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) | ||
add_executable(atomic_server server.cpp ${PROTO_SRC} ${PROTO_HEADER}) | ||
add_executable(atomic_test test.cpp ${PROTO_SRC} ${PROTO_HEADER}) | ||
|
||
set(DYNAMIC_LIB | ||
${CMAKE_THREAD_LIBS_INIT} | ||
${GFLAGS_LIBRARY} | ||
${GLOG_LIBRARY} | ||
${PROTOBUF_LIBRARY} | ||
${GPERFTOOLS_LIBRARIES} | ||
${LEVELDB_LIB} | ||
${BRAFT_LIB} | ||
${BRPC_LIB} | ||
rt | ||
ssl | ||
crypto | ||
dl | ||
z | ||
) | ||
target_link_libraries(atomic_client braft-static) | ||
target_link_libraries(atomic_server braft-static) | ||
target_link_libraries(atomic_test braft-static) | ||
|
||
message("--- ${CMAKE_CURRENT_BINARY_DIR}") | ||
message("--- ${CMAKE_CURRENT_SOURCE_DIR}") | ||
message("--- ${CMAKE_CURRENT_LIST_DIR}") | ||
|
||
# Copy start/stop scripts | ||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ | ||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ | ||
FILES_MATCHING | ||
PATTERN "run_client.sh" | ||
PATTERN "run_server.sh" | ||
PATTERN "stop.sh" | ||
) | ||
|
||
target_link_libraries(atomic_client | ||
"-Xlinker \"-(\"" | ||
${DYNAMIC_LIB} | ||
"-Xlinker \"-)\"") | ||
target_link_libraries(atomic_server | ||
"-Xlinker \"-(\"" | ||
${DYNAMIC_LIB} | ||
"-Xlinker \"-)\"") | ||
target_link_libraries(atomic_test | ||
"-Xlinker \"-(\"" | ||
${DYNAMIC_LIB} | ||
"-Xlinker \"-)\"") | ||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../shflags | ||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.