diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e77978b6b --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/build +local_install +*.pb.cc +*.pb.h +*.o +Makefile +/.lib +/lib +/.sbin +/.vscode \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 846c8ad4a..6d4b54d65 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,19 +1,15 @@ -[submodule "third_party/gtest"] - path = third_party/gtest - url = https://github.com/google/googletest - branch = release-1.6.0 [submodule "third_party/gflags"] path = third_party/gflags url = https://github.com/gflags/gflags -[submodule "third_party/protobuf"] - path = third_party/protobuf - url = https://github.com/google/protobuf [submodule "third_party/glog"] path = third_party/glog url = https://github.com/google/glog [submodule "third_party/leveldb"] path = third_party/leveldb url = https://github.com/google/leveldb -[submodule "third_party/gmock"] - path = third_party/gmock - url = https://github.com/google/googlemock +[submodule "third_party/googletest"] + path = third_party/googletest + url = https://github.com/google/googletest.git +[submodule "third_party/grpc"] + path = third_party/grpc + url = https://github.com/grpc/grpc.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..bc6a38388 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,105 @@ +cmake_minimum_required(VERSION 3.12) +project(phxpaxos) + +option(PHXPAXOS_BUILD_TOOLS "build tools" OFF) +option(PHXPAXOS_BUILD_UT "build ut" OFF) +option(PHXPAXOS_BUILD_TEST "build test" OFF) +option(PHXPAXOS_BUILD_BENCHMARK "build benchmark" OFF) +option(PHXPAXOS_BUILD_PLUGIN "build plugin" OFF) +option(PHXPAXOS_BUILD_SAMPLE_ECHO "build sample phxecho" OFF) +option(PHXPAXOS_BUILD_SAMPLE_ELECTION "build sample phxelection" OFF) +option(PHXPAXOS_BUILD_SAMPLE_KV "build sample phxkv" OFF) +option(PHXPAXOS_INSTALL "create target to install phxpaxos library and headers" ON) + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + # Release - Adds the -O3 -DNDEBUG flags to the compiler + # Debug - Adds the -g flag + # MinSizeRel - Adds -Os -DNDEBUG + # RelWithDebInfo - Adds -O2 -g -DNDEBUG flags + message("Setting build type to 'RelWithDebInfo' as none was specified.") + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +add_compile_options(-Wall -Werror -Wno-unused-local-typedefs -Wno-unused-variable) +add_compile_options(-Wl,--no-as-needed) +add_compile_options(-std=c++11) + +# for find_package in CONFIG mode to find Config.cmake and -config.cmake +list(APPEND CMAKE_PREFIX_PATH + "${PROJECT_SOURCE_DIR}/third_party/local_install/abseil/lib64/cmake/absl" + "${PROJECT_SOURCE_DIR}/third_party/local_install/grpc/lib/cmake/grpc" +) + +# for find_library find_path find_program +list(APPEND CMAKE_PREFIX_PATH + "${PROJECT_SOURCE_DIR}/third_party/local_install/gflags" + "${PROJECT_SOURCE_DIR}/third_party/local_install/glog" + "${PROJECT_SOURCE_DIR}/third_party/local_install/gmock" + "${PROJECT_SOURCE_DIR}/third_party/local_install/leveldb" + "${PROJECT_SOURCE_DIR}/third_party/local_install/protobuf" + "${PROJECT_SOURCE_DIR}/third_party/local_install/grpc" +) + +# for find_package in MODULE mode to find Find.cmake +list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake) + + +find_package(Leveldb MODULE REQUIRED) +find_package(Protobuf MODULE REQUIRED) + +add_subdirectory(src/algorithm) +add_subdirectory(src/checkpoint) +add_subdirectory(src/comm) +add_subdirectory(src/communicate) +add_subdirectory(src/config) +add_subdirectory(src/logstorage) +add_subdirectory(src/master) +add_subdirectory(src/node) +add_subdirectory(src/sm-base) +add_subdirectory(src/utils) + +if(PHXPAXOS_BUILD_TOOLS) + add_subdirectory(src/tools) +endif() + +if(PHXPAXOS_BUILD_UT) + find_package(Gtest MODULE REQUIRED) + find_package(Gmock MODULE REQUIRED) + add_subdirectory(src/ut) +endif() + +if(PHXPAXOS_BUILD_TEST) + add_subdirectory(src/test) +endif() + +if(PHXPAXOS_BUILD_BENCHMARK) + add_subdirectory(src/benchmark) +endif() + +if(PHXPAXOS_BUILD_PLUGIN + OR PHXPAXOS_BUILD_SAMPLE_ECHO + OR PHXPAXOS_BUILD_SAMPLE_ELECTION + OR PHXPAXOS_BUILD_SAMPLE_KV) + find_package(Gflags MODULE REQUIRED) + find_package(Glog MODULE REQUIRED) + add_subdirectory(plugin) +endif() + +if(PHXPAXOS_BUILD_SAMPLE_ECHO) + add_subdirectory(sample/phxecho) +endif() + +if(PHXPAXOS_BUILD_SAMPLE_ELECTION) + add_subdirectory(sample/phxelection) +endif() + +if(PHXPAXOS_BUILD_SAMPLE_KV) + find_package(absl CONFIG REQUIRED) + find_package(gRPC CONFIG REQUIRED) + include(${PROJECT_SOURCE_DIR}/cmake/gRPCHelper.cmake) + add_subdirectory(sample/phxkv) +endif() diff --git a/README.md b/README.md index 041c452a0..c12011c06 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,14 @@ Following is a dependency relationship tablet of all directories. | sample/phxkv | Executable program | libphxpaxos.a,libphxpaxos_plugin.a | grpc | | src/ut | Unit tests | None | gtest,gmock | -We only need 2 third party libs: Protobuf and Leveldb while compiling PhxPaxos library(target is libphxpaoxs.a).But we need GLOG and GRPC while compiling other directories. All these third party libs should be prepared and palced in our `third_party` directory before PhxPaxos compilation. You can `git clone` them by adding `--recurse-submodules` on just download and link them. +We only need 2 third party libs: Protobuf and Leveldb while compiling PhxPaxos library(target is libphxpaoxs.a).But we need GLOG and GRPC while compiling other directories. All these third party libs should be prepared and palced in our `third_party` directory before PhxPaxos compilation. You can `git clone` them by adding `--recurse-submodules` on just download and link them. For already cloned repos, use `git submodule update --init --recursive`. + +Then switch to the `third_party` directory, execute `autoinstall.sh` to compile deps. The script `autoinstall.sh` will compile all deps and install them to `third_party/local_install` directory. + +```Bash +cd third_party +./autoinstall.sh +``` ### Compilation Enviroment * Linux @@ -106,6 +113,8 @@ We only need 2 third party libs: Protobuf and Leveldb while compiling PhxPaxos l ### Compilation and Installation +#### AutoTools + ###### How to Complie libphxpaxos.a. Execute following shell commands in root directory of PhxPaxos @@ -123,6 +132,19 @@ make make install ``` +#### CMake + +Execute following shell commands in root directory of PhxPaxos. +``` +mkdir -p build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. +make +make install +``` + +See CMakeLists.txt in project root directory for all building options. + # How to Wrap Your Own Code Around PhxPaxos. ### First choose a single node service. We will show you this by a PhxEcho service in our `sample` directory, Echo is a common test functions while writing an RPC service. We will wrap this service's code around PhxPaxos to make Echo into a multi-node service. diff --git a/README.zh_CN.md b/README.zh_CN.md index 52f3c9663..2fd2faaf8 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -104,13 +104,24 @@ | src/ut | 单元测试 | 无 | gtest,gmock | 编译我们的Phxpaxo(libphxpaxos.a)类库,只需要protobuf和leveldb两个第三方库;而编译其他目录则需要glog和grpc这两个库。 -在编译前,需要先准备好这些第三方库,放在我们的third_party目录,可以直接放置,也可以通过软链的形式,也可以git clone时加上--recursive参数获取third_party目录下所有的submodule。 +在编译前,需要先准备好这些第三方库,放在我们的third_party目录,可以在`git clone`时加上`--recurse-submodules`参数获取third_party目录下所有的submodule。 +如果已经clone,可以在phxpaxos根目录执行 `git submodule update --init --recursive`来获取third_party下所有依赖。 + +确认`third_party`下所有submodule(以及submodule的submodule)都已准备完成后,进入`third_party`下,执行`autoinstall.sh`脚本,编译安装依赖。该脚本会逐一编译所有的依赖,并将其安装到`third_party/local_install`目录下。 + +```Bash +cd third_party +./autoinstall.sh +``` ### 编译环境 * Linux。 * GCC-4.8及以上版本。 ### 编译安装方法 + +#### AutoTools + ###### 编译libphxpaxos.a 在PhxPaxos根目录下 @@ -128,6 +139,20 @@ make make install ``` +#### CMake + +在PhxPaxos根目录下 +```Bash +mkdir -p build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. +make +make install +``` + +其他的编译选项,可参见项目根目录的 CMakeLists.txt 文件。 + + # 如何嵌入PhxPaxos到自己的代码 ### 选择一个单机服务 我们选用sample目录里面的PhxEcho来说明PhxPaxos的使用方法。Echo是我们编写RPC服务的常见测试函数, diff --git a/cmake/FindGflags.cmake b/cmake/FindGflags.cmake new file mode 100644 index 000000000..9c3b1c232 --- /dev/null +++ b/cmake/FindGflags.cmake @@ -0,0 +1,21 @@ +find_path(GFLAGS_INCLUDE_DIR + NAMES gflags/gflags.h + PATHS "${CMAKE_PREFIX_PATH}/include" +) +mark_as_advanced(GFLAGS_INCLUDE_DIR) + +find_library(GFLAGS_LIBRARY + NAMES gflags + PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" +) +mark_as_advanced(GFLAGS_LIBRARY) + +add_library(gflags STATIC IMPORTED) +set_target_properties(gflags PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GFLAGS_INCLUDE_DIR} + IMPORTED_LOCATION ${GFLAGS_LIBRARY} +) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(gflags DEFAULT_MSG + GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindGlog.cmake b/cmake/FindGlog.cmake new file mode 100644 index 000000000..1d0866e7e --- /dev/null +++ b/cmake/FindGlog.cmake @@ -0,0 +1,21 @@ +find_path(GLOG_INCLUDE_DIR + NAMES glog/logging.h + PATHS "${CMAKE_PREFIX_PATH}/include" +) +mark_as_advanced(GLOG_INCLUDE_DIR) + +find_library(GLOG_LIBRARY + NAMES glog + PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" +) +mark_as_advanced(GLOG_LIBRARY) + +add_library(glog STATIC IMPORTED) +set_target_properties(glog PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GLOG_INCLUDE_DIR} + IMPORTED_LOCATION ${GLOG_LIBRARY} +) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(glog DEFAULT_MSG + GLOG_LIBRARY GLOG_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindGmock.cmake b/cmake/FindGmock.cmake new file mode 100644 index 000000000..7400c8e48 --- /dev/null +++ b/cmake/FindGmock.cmake @@ -0,0 +1,21 @@ +find_path(GMOCK_INCLUDE_DIR + NAMES gmock/gmock.h + PATHS "${CMAKE_PREFIX_PATH}/include" +) +mark_as_advanced(GMOCK_INCLUDE_DIR) + +find_library(GMOCK_LIBRARY + NAMES gmock + PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" +) +mark_as_advanced(GMOCK_LIBRARY) + +add_library(gmock STATIC IMPORTED) +set_target_properties(gmock PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GMOCK_INCLUDE_DIR} + IMPORTED_LOCATION ${GMOCK_LIBRARY} +) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(gmock DEFAULT_MSG + GMOCK_LIBRARY GMOCK_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindGtest.cmake b/cmake/FindGtest.cmake new file mode 100644 index 000000000..b40c6bd1f --- /dev/null +++ b/cmake/FindGtest.cmake @@ -0,0 +1,21 @@ +find_path(GTEST_INCLUDE_DIR + NAMES gtest/gtest.h + PATHS "${CMAKE_PREFIX_PATH}/include" +) +mark_as_advanced(GTEST_INCLUDE_DIR) + +find_library(GTEST_LIBRARY + NAMES gtest + PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" +) +mark_as_advanced(GTEST_LIBRARY) + +add_library(gtest STATIC IMPORTED) +set_target_properties(gtest PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR} + IMPORTED_LOCATION ${GTEST_LIBRARY} +) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(gtest DEFAULT_MSG + GTEST_LIBRARY GTEST_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindLeveldb.cmake b/cmake/FindLeveldb.cmake new file mode 100644 index 000000000..c333afefb --- /dev/null +++ b/cmake/FindLeveldb.cmake @@ -0,0 +1,21 @@ +find_path(LEVELDB_INCLUDE_DIR + NAMES leveldb/db.h + PATHS "${CMAKE_PREFIX_PATH}/include" +) +mark_as_advanced(LEVELDB_INCLUDE_DIR) + +find_library(LEVELDB_LIBRARY + NAMES leveldb + PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" +) +mark_as_advanced(LEVELDB_LIBRARY) + +add_library(leveldb STATIC IMPORTED) +set_target_properties(leveldb PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${LEVELDB_INCLUDE_DIR} + IMPORTED_LOCATION ${LEVELDB_LIBRARY} +) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(leveldb DEFAULT_MSG + LEVELDB_LIBRARY LEVELDB_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindProtobuf.cmake b/cmake/FindProtobuf.cmake new file mode 100644 index 000000000..6524d25b2 --- /dev/null +++ b/cmake/FindProtobuf.cmake @@ -0,0 +1,127 @@ +# +# Generates C++ sources from the .proto files +# +# protobuf_generate_cpp ( [...]) +# +# SRCS - variable to define with autogenerated source files +# HDRS - variable to define with autogenerated header files +# DEST - directory where the source files will be created +# ARGN - .proto files +# +function(PROTOBUF_GENERATE_CPP SRCS HDRS DEST) + if(NOT ARGN) + message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files") + return() + endif() + + if(PROTOBUF_GENERATE_CPP_APPEND_PATH) + # Create an include path for each file specified + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(ABS_PATH ${ABS_FIL} PATH) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + else() + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + if(DEFINED PROTOBUF_IMPORT_DIRS) + foreach(DIR ${PROTOBUF_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + endif() + + set(${SRCS}) + set(${HDRS}) + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(FIL_WE ${FIL} NAME_WE) + + list(APPEND ${SRCS} "${DEST}/${FIL_WE}.pb.cc") + list(APPEND ${HDRS} "${DEST}/${FIL_WE}.pb.h") + + add_custom_command( + OUTPUT "${DEST}/${FIL_WE}.pb.cc" + "${DEST}/${FIL_WE}.pb.h" + COMMAND protobuf::protoc + ARGS --cpp_out ${DEST} ${_protobuf_include_path} ${ABS_FIL} + DEPENDS ${ABS_FIL} protobuf::protoc + COMMENT "Running C++ protocol buffer compiler on ${FIL}" + VERBATIM ) + endforeach() + + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) + set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set(${HDRS} ${${HDRS}} PARENT_SCOPE) +endfunction() + +# By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc +# for each directory where a proto file is referenced. +if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH) + set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE) +endif() + + +# +# Locate and configure the Google Protocol Buffers library +# +# Adds the following targets: +# +# protobuf::libprotobuf - Protobuf library +# protobuf::libprotobuf-lite - Protobuf lite library +# protobuf::libprotoc - Protobuf Protoc Library +# protobuf::protoc - protoc executable +# + +# Find the include directory +find_path(PROTOBUF_INCLUDE_DIR google/protobuf/service.h) +mark_as_advanced(PROTOBUF_INCLUDE_DIR) + +# The Protobuf library +find_library(PROTOBUF_LIBRARY NAMES protobuf) +mark_as_advanced(PROTOBUF_LIBRARY) +add_library(protobuf::libprotobuf STATIC IMPORTED) +set_target_properties(protobuf::libprotobuf PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES pthread + IMPORTED_LOCATION ${PROTOBUF_LIBRARY} +) + +# The Protobuf lite library +find_library(PROTOBUF_LITE_LIBRARY NAMES protobuf-lite) +mark_as_advanced(PROTOBUF_LITE_LIBRARY) +add_library(protobuf::libprotobuf-lite STATIC IMPORTED) +set_target_properties(protobuf::libprotobuf-lite PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES pthread + IMPORTED_LOCATION ${PROTOBUF_LITE_LIBRARY} +) + +# The Protobuf Protoc Library +find_library(PROTOBUF_PROTOC_LIBRARY NAMES protoc) +mark_as_advanced(PROTOBUF_PROTOC_LIBRARY) +add_library(protobuf::libprotoc STATIC IMPORTED) +set_target_properties(protobuf::libprotoc PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES protobuf::libprotobuf + IMPORTED_LOCATION ${PROTOBUF_PROTOC_LIBRARY} +) + +# Find the protoc Executable +find_program(PROTOBUF_PROTOC_EXECUTABLE NAMES protoc) +mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE) +add_executable(protobuf::protoc IMPORTED) +set_target_properties(protobuf::protoc PROPERTIES + IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE} +) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf DEFAULT_MSG + PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR PROTOBUF_PROTOC_EXECUTABLE) \ No newline at end of file diff --git a/cmake/gRPCHelper.cmake b/cmake/gRPCHelper.cmake new file mode 100644 index 000000000..ec7a84d90 --- /dev/null +++ b/cmake/gRPCHelper.cmake @@ -0,0 +1,76 @@ +# +# Generates C++ sources from the .proto files +# +# grpc_generate_cpp ( [...]) +# +# SRCS - variable to define with autogenerated source files +# HDRS - variable to define with autogenerated header files +# DEST - directory where the source files will be created +# ARGN - .proto files +# +function(GRPC_GENERATE_CPP SRCS HDRS DEST) + if(NOT ARGN) + message(SEND_ERROR "Error: GRPC_GENERATE_CPP() called without any proto files") + return() + endif() + + if(GRPC_GENERATE_CPP_APPEND_PATH) + # Create an include path for each file specified + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(ABS_PATH ${ABS_FIL} PATH) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + else() + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + if(DEFINED PROTOBUF_IMPORT_DIRS) + foreach(DIR ${PROTOBUF_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + endif() + + set(${SRCS}) + set(${HDRS}) + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(FIL_WE ${FIL} NAME_WE) + + list(APPEND ${SRCS} "${DEST}/${FIL_WE}.grpc.pb.cc") + list(APPEND ${HDRS} "${DEST}/${FIL_WE}.grpc.pb.h") + + add_custom_command( + OUTPUT "${DEST}/${FIL_WE}.grpc.pb.cc" + "${DEST}/${FIL_WE}.grpc.pb.h" + COMMAND protobuf::protoc + ARGS --grpc_out ${DEST} ${_protobuf_include_path} --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} ${ABS_FIL} + DEPENDS ${ABS_FIL} protobuf::protoc gRPC::grpc_cpp_plugin + COMMENT "Running C++ gRPC compiler on ${FIL}" + VERBATIM ) + endforeach() + + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) + set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set(${HDRS} ${${HDRS}} PARENT_SCOPE) +endfunction() + +# By default have GRPC_GENERATE_CPP macro pass -I to protoc +# for each directory where a proto file is referenced. +if(NOT DEFINED GRPC_GENERATE_CPP_APPEND_PATH) + set(GRPC_GENERATE_CPP_APPEND_PATH TRUE) +endif() + +# Find gRPC CPP generator +find_program(GRPC_CPP_PLUGIN NAMES grpc_cpp_plugin) +mark_as_advanced(GRPC_CPP_PLUGIN) + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GRPC_CPP_PLUGIN DEFAULT_MSG GRPC_CPP_PLUGIN) \ No newline at end of file diff --git a/makefile.mk b/makefile.mk index 73a18e115..8517e0aff 100644 --- a/makefile.mk +++ b/makefile.mk @@ -6,20 +6,21 @@ PHX_EXTLIB_PATH = $(PHX_LIB_PATH)/extlib NANOPBPATH=$(SRC_BASE_PATH)/third_party/nanopb/ -PROTOBUF_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/protobuf/include -GRPC_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/grpc/include -LEVELDB_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/leveldb/include -GFLAGS_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/gflags/include -GLOG_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/glog/include +PROTOBUF_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/local_install/protobuf/include +ABSL_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/local_install/abseil/include +GRPC_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/local_install/grpc/include +LEVELDB_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/local_install/leveldb/include +GFLAGS_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/local_install/gflags/include +GLOG_INCLUDE_PATH=$(SRC_BASE_PATH)/third_party/local_install/glog/include PHXPAXOS_INCLUDE_PATH=$(SRC_BASE_PATH)/include PHXPAXOS_PLUGIN_PATH=$(SRC_BASE_PATH)/plugin/include -PROTOBUF_LIB_PATH=$(SRC_BASE_PATH)/third_party/protobuf/lib -LEVELDB_LIB_PATH=$(SRC_BASE_PATH)/third_party/leveldb/lib -GFLAGS_LIB_PATH=$(SRC_BASE_PATH)/third_party/gflags/lib -GLOG_LIB_PATH=$(SRC_BASE_PATH)/third_party/glog/lib -GRPC_LIBE_PATH=$(SRC_BASE_PATH)/third_party/grpc/lib -OPEN_SSL_LIB_PATH=$(SRC_BASE_PATH)/third_party/openssl/lib +PROTOBUF_LIB_PATH=$(SRC_BASE_PATH)/third_party/local_install/protobuf/lib +LEVELDB_LIB_PATH=$(SRC_BASE_PATH)/third_party/local_install/leveldb/lib64 +GFLAGS_LIB_PATH=$(SRC_BASE_PATH)/third_party/local_install/gflags/lib +GLOG_LIB_PATH=$(SRC_BASE_PATH)/third_party/local_install/glog/lib +ABSL_LIBE_PATH=$(SRC_BASE_PATH)/third_party/local_install/abseil/lib64 +GRPC_LIBE_PATH=$(SRC_BASE_PATH)/third_party/local_install/grpc/lib PHXPAXOS_LIB_PATH=$(SRC_BASE_PATH)/lib ifeq ($(debug),y) @@ -33,22 +34,22 @@ endif CXX=g++ CXXFLAGS+=-std=c++11 $(OPT) CPPFLAGS+=-I$(SRC_BASE_PATH) -I$(PROTOBUF_INCLUDE_PATH) -I$(LEVELDB_INCLUDE_PATH) -CPPFLAGS+=-I$(GFLAGS_INCLUDE_PATH) -I$(GLOG_INCLUDE_PATH) +CPPFLAGS+=-I$(GFLAGS_INCLUDE_PATH) -I$(GLOG_INCLUDE_PATH) -I$(ABSL_INCLUDE_PATH) CPPFLAGS+=-Wall -fPIC -m64 -Wno-unused-local-typedefs #LDFLAGS+=-shared #LDFLAGS+=-static LDFLAGS+=-L$(PHX_LIB_PATH) -L$(PROTOBUF_LIB_PATH) -L$(LEVELDB_LIB_PATH) -LDFLAGS+=-L$(GFLAGS_LIB_PATH) -L$(GLOG_LIB_PATH) -L$(GRPC_LIBE_PATH) -L$(OPEN_SSL_LIB_PATH) -g +LDFLAGS+=-L$(GFLAGS_LIB_PATH) -L$(GLOG_LIB_PATH) -L$(GRPC_LIBE_PATH) -L$(ABSL_LIBE_PATH) -g LDFLAGS+=-Wl,--no-as-needed #===================================================================================================== -PROTOC = $(SRC_BASE_PATH)/third_party/protobuf/bin/protoc +PROTOC = $(SRC_BASE_PATH)/third_party/local_install/protobuf/bin/protoc PROTOS_PATH = . GRPC_CPP_PLUGIN = grpc_cpp_plugin -GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` +GRPC_CPP_PLUGIN_PATH ?= $(SRC_BASE_PATH)/third_party/local_install/grpc/bin/grpc_cpp_plugin NANOPB_PLUGIN_PATH=$(NANOPBPATH)/generator/protoc-gen-nanopb vpath %.proto $(PROTOS_PATH) diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt new file mode 100644 index 000000000..1835536e6 --- /dev/null +++ b/plugin/CMakeLists.txt @@ -0,0 +1,24 @@ +set(PHXPAXOS_PLUGIN_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/logger_google/logger_google.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/logger_google/logger_google_impl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/monitor/monitor.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/monitor/monitor_bp.cpp +) +add_library(phxpaxos_plugin STATIC ${PHXPAXOS_PLUGIN_SRCS}) +add_library(phxpaxos::plugin ALIAS phxpaxos_plugin) +target_link_libraries( + phxpaxos_plugin + PRIVATE + phxpaxos + glog + gflags +) +target_include_directories( + phxpaxos_plugin + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/logger_google + ${CMAKE_CURRENT_SOURCE_DIR}/monitor +) \ No newline at end of file diff --git a/plugin/logger_google/Makefile.define b/plugin/logger_google/Makefile.define index 917e43f39..c54a9719b 100644 --- a/plugin/logger_google/Makefile.define +++ b/plugin/logger_google/Makefile.define @@ -23,9 +23,9 @@ LOGGER_GOOGLE_OBJ=logger_google.o LOGGER_GOOGLE_LIB=logger_google plugin/include:include -LOGGER_GOOGLE_SYS_LIB=$(PHXPAXOS_LIB_PATH)/libphxpaxos.a $(LEVELDB_LIB_PATH)/libleveldb.a $(PROTOBUF_LIB_PATH)/libprotobuf.a $(GLOG_LIB_PATH)/libglog.a $(GFLAGS_LIB_PATH)/libgflags.a-lpthread +LOGGER_GOOGLE_SYS_LIB=$(PHXPAXOS_LIB_PATH)/libphxpaxos.a $(LEVELDB_LIB_PATH)/libleveldb.a $(PROTOBUF_LIB_PATH)/libprotobuf.a $(GLOG_LIB_PATH)/libglog.a $(GFLAGS_LIB_PATH)/libgflags.a -lpthread -LOGGER_GOOGLE_INCS=$(SRC_BASE_PATH)/plugin/logger_google $(PHXPAXOS_INCLUDE_PATH) $(LEVELDB_INCLUDE_PATH) $(PROTOBUF_INCLUDE_PATH) +LOGGER_GOOGLE_INCS=$(SRC_BASE_PATH)/plugin/logger_google $(PHXPAXOS_INCLUDE_PATH) $(LEVELDB_INCLUDE_PATH) $(PROTOBUF_INCLUDE_PATH) LOGGER_GOOGLE_EXTRA_CPPFLAGS=-Wall -Werror diff --git a/sample/phxecho/CMakeLists.txt b/sample/phxecho/CMakeLists.txt new file mode 100644 index 000000000..b7380e9a9 --- /dev/null +++ b/sample/phxecho/CMakeLists.txt @@ -0,0 +1,17 @@ +set(PHXECHO_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/echo_server.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/echo_sm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp +) +add_executable(phxecho ${PHXECHO_SRCS}) +target_include_directories( + phxecho + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) +target_link_libraries( + phxecho + PRIVATE + phxpaxos + phxpaxos::plugin +) \ No newline at end of file diff --git a/sample/phxelection/CMakeLists.txt b/sample/phxelection/CMakeLists.txt new file mode 100644 index 000000000..b360e3569 --- /dev/null +++ b/sample/phxelection/CMakeLists.txt @@ -0,0 +1,16 @@ +set(PHXELECTION_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/election.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/election_main.cpp +) +add_executable(phxelection ${PHXELECTION_SRCS}) +target_include_directories( + phxelection + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) +target_link_libraries( + phxelection + PRIVATE + phxpaxos + phxpaxos::plugin +) \ No newline at end of file diff --git a/sample/phxkv/CMakeLists.txt b/sample/phxkv/CMakeLists.txt new file mode 100644 index 000000000..d2ef95491 --- /dev/null +++ b/sample/phxkv/CMakeLists.txt @@ -0,0 +1,81 @@ +set(PHXKV_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/phxkv.proto) +protobuf_generate_cpp(PHXKV_PROTO_SRCS PHXKV_PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR} ${PHXKV_PROTOS}) +grpc_generate_cpp(PHXKV_GRPC_SRCS PHXKV_GRPC_HDRS ${CMAKE_CURRENT_SOURCE_DIR} ${PHXKV_PROTOS}) + +set(PHXKV_CLIENT_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/kv_grpc_client.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kv_grpc_client_main.cpp +) +add_library(phxkv_client STATIC + ${PHXKV_CLIENT_SRCS} + ${PHXKV_PROTO_SRCS} + ${PHXKV_GRPC_SRCS} +) +target_include_directories( + phxkv_client + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) +target_link_libraries( + phxkv_client + PUBLIC + phxpaxos + gRPC::grpc + gRPC::grpc++_unsecure + absl::synchronization +) +target_compile_options(phxkv_client PRIVATE -Wall) + +set(PHXKV_CLIENT_TOOLS_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/kv_grpc_client.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kv_grpc_client_main.cpp +) +add_executable(phxkv_client_tools + ${PHXKV_CLIENT_TOOLS_SRCS} + ${PHXKV_PROTO_SRCS} + ${PHXKV_GRPC_SRCS} +) +target_include_directories( + phxkv_client_tools + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) +target_link_libraries( + phxkv_client_tools + PRIVATE + phxpaxos + gRPC::grpc + gRPC::grpc++_unsecure + absl::synchronization +) +target_compile_options(phxkv_client_tools PRIVATE -Wall) + +set(PHXKV_GRPCSERVER_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/kv.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kvsm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kv_paxos.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kv_grpc_server.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/kv_grpc_server_main.cpp +) +add_executable(phxkv_grpcserver + ${PHXKV_GRPCSERVER_SRCS} + ${PHXKV_PROTO_SRCS} + ${PHXKV_GRPC_SRCS} +) +target_include_directories( + phxkv_grpcserver + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) +target_link_libraries( + phxkv_grpcserver + PRIVATE + phxpaxos + phxpaxos::plugin + leveldb + gRPC::grpc + gRPC::grpc++_unsecure + absl::synchronization +) +target_compile_options(phxkv_grpcserver PRIVATE -Wall) diff --git a/sample/phxkv/Makefile.define b/sample/phxkv/Makefile.define index 978241f24..86abe0df3 100644 --- a/sample/phxkv/Makefile.define +++ b/sample/phxkv/Makefile.define @@ -17,6 +17,9 @@ # # See the AUTHORS file for names of contributors. +# +# This file is abandoned. Please use cmake to build phxkv + allobject=elibphxkv_client.a phxkv_client_tools phxkv_grpcserver PHXKV_CLIENT_OBJ=phxkv.pb.o phxkv.grpc.pb.o kv_grpc_client.o kv_grpc_client_main.o diff --git a/src/algorithm/CMakeLists.txt b/src/algorithm/CMakeLists.txt new file mode 100644 index 000000000..a27145804 --- /dev/null +++ b/src/algorithm/CMakeLists.txt @@ -0,0 +1,18 @@ +file(GLOB PHXPAXOS_ALGORITHM_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_algorithm STATIC ${PHXPAXOS_ALGORITHM_SRCS}) +add_library(phxpaxos::algorithm ALIAS phxpaxos_algorithm) +target_link_libraries( + phxpaxos_algorithm + PUBLIC + phxpaxos::comm + phxpaxos::logstorage + phxpaxos::smbase + phxpaxos::checkpoint + phxpaxos::config +) +target_include_directories( + phxpaxos_algorithm + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/include +) \ No newline at end of file diff --git a/src/benchmark/CMakeLists.txt b/src/benchmark/CMakeLists.txt new file mode 100644 index 000000000..fd0c75b0b --- /dev/null +++ b/src/benchmark/CMakeLists.txt @@ -0,0 +1,40 @@ +set(PHX_PAXOS_BENCH_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/bench_sm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/bench_server.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/bench_main.cpp +) +add_executable(phx_paxos_bench ${PHX_PAXOS_BENCH_SRCS}) +target_link_libraries( + phx_paxos_bench + PRIVATE + phxpaxos::utils + phxpaxos::algorithm + phxpaxos + leveldb + protobuf::libprotobuf + pthread +) +target_include_directories( + phx_paxos_bench + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/include +) + +set(BENCH_DB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/bench_db.cpp) +add_executable(bench_db ${BENCH_DB_SRCS}) +target_link_libraries( + bench_db + PRIVATE + phxpaxos + phxpaxos::logstorage + leveldb + protobuf::libprotobuf + pthread +) +target_include_directories( + bench_db + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/include +) \ No newline at end of file diff --git a/src/checkpoint/CMakeLists.txt b/src/checkpoint/CMakeLists.txt new file mode 100644 index 000000000..876291d0a --- /dev/null +++ b/src/checkpoint/CMakeLists.txt @@ -0,0 +1,17 @@ +file(GLOB PHXPAXOS_CHECKPOINT_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_checkpoint STATIC ${PHXPAXOS_CHECKPOINT_SRCS}) +add_library(phxpaxos::checkpoint ALIAS phxpaxos_checkpoint) +target_link_libraries( + phxpaxos_checkpoint + PUBLIC + phxpaxos::comm + phxpaxos::logstorage + phxpaxos::smbase + phxpaxos::utils + phxpaxos::config +) +target_include_directories( + phxpaxos_checkpoint + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/comm/CMakeLists.txt b/src/comm/CMakeLists.txt new file mode 100644 index 000000000..6f63d0353 --- /dev/null +++ b/src/comm/CMakeLists.txt @@ -0,0 +1,22 @@ +set(PHXPAXOS_COMM_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/paxos_msg.proto) +protobuf_generate_cpp(PHXPAXOS_COMM_PROTO_SRCS PHXPAXOS_COMM_PROTO_HDRS + ${CMAKE_CURRENT_SOURCE_DIR} ${PHXPAXOS_COMM_PROTOS}) + +file(GLOB PHXPAXOS_COMM_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_comm STATIC + ${PHXPAXOS_COMM_SRCS} + ${PHXPAXOS_COMM_PROTO_SRCS} +) +add_library(phxpaxos::comm ALIAS phxpaxos_comm) +target_link_libraries( + phxpaxos_comm + PUBLIC + phxpaxos::utils + protobuf::libprotobuf +) +target_include_directories( + phxpaxos_comm + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/include +) \ No newline at end of file diff --git a/src/communicate/CMakeLists.txt b/src/communicate/CMakeLists.txt new file mode 100644 index 000000000..6182a8c53 --- /dev/null +++ b/src/communicate/CMakeLists.txt @@ -0,0 +1,18 @@ +add_subdirectory(tcp) + +file(GLOB PHXPAXOS_COMMUNICATE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_communicate STATIC ${PHXPAXOS_COMMUNICATE_SRCS}) +add_library(phxpaxos::communicate ALIAS phxpaxos_communicate) +target_link_libraries( + phxpaxos_communicate + PUBLIC + phxpaxos::comm + phxpaxos::utils + phxpaxos::config + phxpaxos::communicate::tcp +) +target_include_directories( + phxpaxos_communicate + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/communicate/tcp/CMakeLists.txt b/src/communicate/tcp/CMakeLists.txt new file mode 100644 index 000000000..6eaff2fce --- /dev/null +++ b/src/communicate/tcp/CMakeLists.txt @@ -0,0 +1,14 @@ +file(GLOB PHXPAXOS_COMMUNICATE_TCP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_communicate_tcp STATIC ${PHXPAXOS_COMMUNICATE_TCP_SRCS}) +add_library(phxpaxos::communicate::tcp ALIAS phxpaxos_communicate_tcp) +target_link_libraries( + phxpaxos_communicate_tcp + PUBLIC + phxpaxos::utils + phxpaxos::comm +) +target_include_directories( + phxpaxos_communicate_tcp + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt new file mode 100644 index 000000000..ec7c7e6e2 --- /dev/null +++ b/src/config/CMakeLists.txt @@ -0,0 +1,15 @@ +file(GLOB PHXPAXOS_CONFIG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_config STATIC ${PHXPAXOS_CONFIG_SRCS}) +add_library(phxpaxos::config ALIAS phxpaxos_config) +target_link_libraries( + phxpaxos_config + PUBLIC + phxpaxos::comm + phxpaxos::logstorage + phxpaxos::smbase +) +target_include_directories( + phxpaxos_config + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/src/logstorage/CMakeLists.txt b/src/logstorage/CMakeLists.txt new file mode 100644 index 000000000..1985c55cd --- /dev/null +++ b/src/logstorage/CMakeLists.txt @@ -0,0 +1,14 @@ +file(GLOB PHXPAXOS_LOGSTORAGE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_logstorage STATIC ${PHXPAXOS_LOGSTORAGE_SRCS}) +add_library(phxpaxos::logstorage ALIAS phxpaxos_logstorage) +target_link_libraries( + phxpaxos_logstorage + PUBLIC + phxpaxos::comm + leveldb +) +target_include_directories( + phxpaxos_logstorage + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/master/CMakeLists.txt b/src/master/CMakeLists.txt new file mode 100644 index 000000000..da17ff1c9 --- /dev/null +++ b/src/master/CMakeLists.txt @@ -0,0 +1,23 @@ +set(PHXPAXOS_MASTER_PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/master_sm.proto) +protobuf_generate_cpp(PHXPAXOS_MASTER_PROTO_SRCS PHXPAXOS_MASTER_PROTO_HDRS + ${CMAKE_CURRENT_SOURCE_DIR} ${PHXPAXOS_MASTER_PROTOS}) + +file(GLOB PHXPAXOS_MASTER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_master STATIC + ${PHXPAXOS_MASTER_SRCS} + ${PHXPAXOS_MASTER_PROTO_SRCS} +) +add_library(phxpaxos::master ALIAS phxpaxos_master) +target_link_libraries( + phxpaxos_master + PUBLIC + phxpaxos::utils + phxpaxos::comm + phxpaxos::config + phxpaxos::logstorage +) +target_include_directories( + phxpaxos_master + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/node/CMakeLists.txt b/src/node/CMakeLists.txt new file mode 100644 index 000000000..e7a2e3065 --- /dev/null +++ b/src/node/CMakeLists.txt @@ -0,0 +1,46 @@ +set(PHXPAXOS_NODE_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/group.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pnode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/node.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/propose_batch.cpp +) +add_library(phxpaxos STATIC ${PHXPAXOS_NODE_SRCS}) +target_link_libraries(phxpaxos PRIVATE -static-libstdc++) +target_link_libraries( + phxpaxos + PRIVATE + phxpaxos::algorithm + phxpaxos::comm + phxpaxos::communicate + phxpaxos::config + phxpaxos::logstorage + phxpaxos::master +) +target_include_directories( + phxpaxos + PUBLIC + $ + $ + $ +) +if(PHXPAXOS_INSTALL) + install( + TARGETS phxpaxos + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + install( + DIRECTORY ${PROJECT_SOURCE_DIR}/include/phxpaxos + DESTINATION include + ) +endif() + + +set(TEST_PROPOSE_BATCH_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/test_propose_batch.cpp) +add_executable(test_propose_batch ${TEST_PROPOSE_BATCH_SRCS}) +target_link_libraries( + test_propose_batch + PRIVATE + phxpaxos::comm + phxpaxos +) \ No newline at end of file diff --git a/src/sm-base/CMakeLists.txt b/src/sm-base/CMakeLists.txt new file mode 100644 index 000000000..de50eed59 --- /dev/null +++ b/src/sm-base/CMakeLists.txt @@ -0,0 +1,13 @@ +file(GLOB PHXPAXOS_SMBASE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_smbase STATIC ${PHXPAXOS_SMBASE_SRCS}) +add_library(phxpaxos::smbase ALIAS phxpaxos_smbase) +target_link_libraries( + phxpaxos_smbase + PUBLIC + phxpaxos::comm +) +target_include_directories( + phxpaxos_smbase + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt new file mode 100644 index 000000000..6ea7606ee --- /dev/null +++ b/src/test/CMakeLists.txt @@ -0,0 +1,21 @@ +set(PHX_PAXOS_TEST_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_server.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_sm.cpp +) +add_executable(phx_paxos_test ${PHX_PAXOS_TEST_SRCS}) +target_link_libraries( + phx_paxos_test + PRIVATE + phxpaxos::utils + phxpaxos::comm + phxpaxos + leveldb + protobuf::libprotobuf + pthread +) +target_include_directories( + phx_paxos_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt new file mode 100644 index 000000000..5072d961c --- /dev/null +++ b/src/tools/CMakeLists.txt @@ -0,0 +1,27 @@ +add_executable(system_variables_tools system_variables_tools.cpp) +target_link_libraries( + system_variables_tools + PRIVATE + phxpaxos::comm + phxpaxos::config + phxpaxos::logstorage +) +target_compile_options(system_variables_tools PRIVATE -Wno-format) + +add_executable(paxos_log_tools paxos_log_tools.cpp) +target_link_libraries( + paxos_log_tools + PRIVATE + phxpaxos::comm + phxpaxos::logstorage +) +target_compile_options(paxos_log_tools PRIVATE -Wno-format) + +add_executable(vfile_fetch vfile_fetch.cpp) +target_link_libraries( + vfile_fetch + PRIVATE + phxpaxos::comm + phxpaxos::logstorage +) +target_compile_options(vfile_fetch PRIVATE -Wno-format) diff --git a/src/ut/CMakeLists.txt b/src/ut/CMakeLists.txt new file mode 100644 index 000000000..c5eb1cc75 --- /dev/null +++ b/src/ut/CMakeLists.txt @@ -0,0 +1,17 @@ +file(GLOB PHXPAXOS_UT_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_executable(phxpaxos_ut ${PHXPAXOS_UT_SRCS}) +target_link_libraries( + phxpaxos_ut + PRIVATE + phxpaxos::logstorage + phxpaxos::config + phxpaxos::algorithm + phxpaxos::communicate + gmock + gtest +) +target_include_directories( + phxpaxos_ut + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt new file mode 100644 index 000000000..92f67a5da --- /dev/null +++ b/src/utils/CMakeLists.txt @@ -0,0 +1,13 @@ +file(GLOB PHXPAXOS_UTILS_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +add_library(phxpaxos_utils STATIC ${PHXPAXOS_UTILS_SRCS}) +add_library(phxpaxos::utils ALIAS phxpaxos_utils) +target_link_libraries( + phxpaxos_utils + PUBLIC + pthread +) +target_include_directories( + phxpaxos_utils + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) \ No newline at end of file diff --git a/third_party/autoinstall.sh b/third_party/autoinstall.sh index f50a6f0e6..32fe46e3f 100755 --- a/third_party/autoinstall.sh +++ b/third_party/autoinstall.sh @@ -1,9 +1,12 @@ #!/bin/bash -current_path=$(pwd); +set -e -u -o pipefail -function perror() { +work_dir=$(cd `dirname $0` && pwd) +mkdir -p ${work_dir}/local_install/{gflags,glog,gmock,leveldb,abseil,protobuf,grpc} +install_prefix=${work_dir}/local_install +function perror() { echo -e "\033[0;31;1m$1\033[0m" } @@ -11,188 +14,104 @@ function psucc() { echo -e "\e[1;32m$1\e[0m" } -function go_back() -{ - cd $current_path; -} - -function check_dir_exist() -{ - dir_path=$current_path"/$1"; - if [ ! -d $dir_path ]; then - perror $dir_path" dir not exist."; - exit 1; - fi +# gflags +function install_gflags() { + cd ${work_dir}/gflags + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${install_prefix}/gflags \ + . + make + make install + psucc "install gflags ok." } -function check_file_exist() -{ - if [ ! -f $1 ]; then - return 1; - fi - return 0; +# glog +function install_glog() { + cd ${work_dir}/glog + mkdir -p build && cd build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${install_prefix}/glog \ + .. + make + make install + psucc "install glog ok." } -function check_lib_exist() -{ - go_back; - lib_dir_path="$current_path/$1/lib"; - if [ ! -d $lib_dir_path ]; then - return 1; - fi - - lib_file_path=$lib_dir_path"/lib$1.a"; - check_file_exist $lib_file_path; - ls "$lib_file_path" - return $? -} - -function install_leveldb() -{ - lib_name="leveldb"; - check_dir_exist $lib_name; - - # check if aready install. - check_lib_exist $lib_name; - if [ $? -eq 0 ]; then - psucc "$lib_name already installed." - return; - fi - # end check. - - go_back; - cd $lib_name; - make; - if [ ! -d lib ]; then - mkdir lib; - fi - cd lib; - if [ ! -f libleveldb.a ]; then - ln -s ../out-static/libleveldb.a libleveldb.a - fi - - check_lib_exist $lib_name; - if [ $? -eq 1 ]; then - perror "$lib_name install fail. please check compile error info." - exit 1; - fi - - psucc "install $lib_name ok." +# gmock +function install_gmock_and_gtest() { + cd ${work_dir}/googletest + mkdir -p build && cd build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${install_prefix}/gmock \ + -DBUILD_GMOCK=ON \ + .. + make + make install + psucc "install gmock & gtest ok." } -function check_protobuf_installed() -{ - cd $lib_name; - bin_dir=$(pwd)"/bin"; - include_dir=$(pwd)"/include"; - - if [ ! -d $bin_dir ]; then - return 1; - fi - if [ ! -d $include_dir ]; then - return 1; - fi - check_lib_exist $1; - return $?; +# leveldb +function install_leveldb() { + cd ${work_dir}/leveldb + # enable rtti + sed -i '/-fno-rtti/d' CMakeLists.txt + sed -i '/-frtti/d' CMakeLists.txt + mkdir -p build && cd build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DLEVELDB_BUILD_TESTS=OFF \ + -DLEVELDB_BUILD_BENCHMARKS=OFF \ + -DCMAKE_INSTALL_PREFIX=${install_prefix}/leveldb \ + .. + cmake --build . + make install + psucc "install leveldb ok." } -function install_protobuf() -{ - lib_name="protobuf"; - check_dir_exist $lib_name; - - # check if aready install. - check_protobuf_installed $lib_name; - if [ $? -eq 0 ]; then - psucc "$lib_name already installed." - return; - fi - # end check. - - go_back; - cd $lib_name; - - exist_gmock_dir="../gmock"; - if [ -d $exist_gmock_dir ]; then - if [ ! -d gmock ]; then - cp -r $exist_gmock_dir gmock; - fi - fi - - ./autogen.sh; - ./configure CXXFLAGS=-fPIC --prefix=$(pwd); - make && make install; - - check_protobuf_installed $lib_name; - if [ $? -eq 1 ]; then - perror "$lib_name install fail. please check compile error info." - exit 1; - fi - psucc "install $lib_name ok." +# abseil-cpp +function install_abseil() { + cd ${work_dir}/grpc/third_party/abseil-cpp + mkdir -p build && cd build + cmake \ + -DCMAKE_INSTALL_PREFIX=${install_prefix}/abseil \ + .. + make + make install + psucc "install abseil-cpp ok." } -function install_glog() -{ - lib_name="glog"; - check_dir_exist $lib_name; - - # check if aready install. - check_lib_exist $lib_name; - if [ $? -eq 0 ]; then - psucc "$lib_name already installed." - return; - fi - # end check. - - go_back; - cd $lib_name; +# protobuf +function install_protobuf() { + cd ${work_dir}/grpc/third_party/protobuf ./autogen.sh - exist_gflags_dir="../gflags"; - if [ -d $exist_gflags_dir ]; then - # use local gflags - ./configure CXXFLAGS=-fPIC --prefix=$(pwd) --with-gflags=$exist_gflags_dir; - else - # use system gflags - ./configure CXXFLAGS=-fPIC --prefix=$(pwd); - fi - make && make install; - - check_lib_exist $lib_name; - if [ $? -eq 1 ]; then - perror "$lib_name install fail. please check compile error info." - exit 1; - fi - psucc "install $lib_name ok." + ./configure --prefix=${install_prefix}/protobuf --disable-shared + make + make install + psucc "install protobuf ok." } -function install_gflags() -{ - lib_name="gflags"; - check_dir_exist $lib_name; - - # check if aready install. - check_lib_exist $lib_name; - if [ $? -eq 0 ]; then - psucc "$lib_name already installed." - return; - fi - # end check. - go_back; - cd $lib_name; - CXXFLAGS=-fPIC cmake . -DCMAKE_INSTALL_PREFIX=$(pwd); - make && make install; - - check_lib_exist $lib_name; - if [ $? -eq 1 ]; then - perror "$lib_name install fail. please check compile error info." - exit 1; - fi - psucc "install $lib_name ok." +# grpc +function install_grpc() { + cd ${work_dir}/grpc + mkdir -p cmake/build && cd cmake/build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${install_prefix}/grpc \ + ../.. + make + make install + psucc "install grpc ok." } -install_gflags; -install_glog; -install_leveldb; -install_protobuf; +install_gflags +install_glog +install_gmock_and_gtest +install_leveldb +install_abseil +install_protobuf +install_grpc psucc "all done." diff --git a/third_party/gmock b/third_party/gmock deleted file mode 160000 index f7d03d273..000000000 --- a/third_party/gmock +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f7d03d2734759ee12b57d2dbcb695607d89e8e05 diff --git a/third_party/googletest b/third_party/googletest new file mode 160000 index 000000000..703bd9caa --- /dev/null +++ b/third_party/googletest @@ -0,0 +1 @@ +Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e diff --git a/third_party/grpc b/third_party/grpc new file mode 160000 index 000000000..44c40ac23 --- /dev/null +++ b/third_party/grpc @@ -0,0 +1 @@ +Subproject commit 44c40ac23023b7b3dd82744372c06817cc203898 diff --git a/third_party/leveldb b/third_party/leveldb index a53934a3a..99b3c03b3 160000 --- a/third_party/leveldb +++ b/third_party/leveldb @@ -1 +1 @@ -Subproject commit a53934a3ae1244679f812d998a4f16f2c7f309a6 +Subproject commit 99b3c03b3284f5886f9ef9a4ef703d57373e61be diff --git a/third_party/protobuf b/third_party/protobuf deleted file mode 160000 index e8ae137c9..000000000 --- a/third_party/protobuf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e8ae137c96444ea313485ed1118c5e43b2099cf1