diff --git a/.github/workflows/import_braft.yml b/.github/workflows/import_braft.yml index 06c54648e..1d890bd3e 100644 --- a/.github/workflows/import_braft.yml +++ b/.github/workflows/import_braft.yml @@ -26,7 +26,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build + - name: Build --verbose env: CPLUS_INCLUDE_PATH: /opt/homebrew/include run: | @@ -50,7 +50,7 @@ jobs: - name: Build run: | - bash build.sh + bash build.sh --verbose - name: Run Go E2E Tests working-directory: ${{ github.workspace }}/build-release diff --git a/.github/workflows/pikiwidb.yml b/.github/workflows/pikiwidb.yml index fb3f5ffe3..c6ea3d576 100644 --- a/.github/workflows/pikiwidb.yml +++ b/.github/workflows/pikiwidb.yml @@ -30,7 +30,7 @@ jobs: run: | brew install autoconf brew install go - sh build.sh + sh build.sh --verbose - name: GTest working-directory: ${{ github.workspace }}/build-release @@ -54,7 +54,7 @@ jobs: - name: Build run: | - bash build.sh + bash build.sh --verbose - name: GTest working-directory: ${{ github.workspace }}/build-release diff --git a/.gitignore b/.gitignore index f2252017f..c0e2b905a 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,8 @@ build-release/ build-debug/ buildtrees deps +deps-debug/ +deps-release/ #develop container .devcontainer @@ -83,4 +85,4 @@ build_support/__pycache__ build_support/clang_format_exclusions.txt # pkg -pkg \ No newline at end of file +pkg diff --git a/CMakeLists.txt b/CMakeLists.txt index 30de80b73..4a944b8c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.14) PROJECT(PikiwiDB) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -D'GIT_COMMIT_ID=\"${GIT_COMMIT_ID}\"'") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: IF (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") @@ -15,6 +15,7 @@ ENDIF () SET(CMAKE_CXX_STANDARD 20) SET(CMAKE_EXPORT_COMPILE_COMMANDS ON) + ENABLE_TESTING() IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -93,20 +94,23 @@ ELSEIF (HOST_ARCH MATCHES "arm") ENDIF () IF (CMAKE_BUILD_TYPE STREQUAL "Release") - SET(EP_BASE_SUFFIX "build-release/buildtrees") + SET(EP_BASE_SUFFIX "build-release") + SET(LIB_SUFFIX "deps-release") ELSE () - SET(EP_BASE_SUFFIX "build-debug/buildtrees") + SET(EP_BASE_SUFFIX "build-debug") + SET(LIB_SUFFIX "deps-debug") ENDIF () SET_PROPERTY(DIRECTORY PROPERTY EP_BASE ${CMAKE_CURRENT_SOURCE_DIR}/${EP_BASE_SUFFIX}) SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/") -SET(STAGED_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/deps) -SET(CMAKE_UTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/utils) -SET(INSTALL_INCLUDEDIR ${STAGED_INSTALL_PREFIX}/include) -SET(INSTALL_LIBDIR ${STAGED_INSTALL_PREFIX}/lib) -SET(INSTALL_LIBDIR_64 ${STAGED_INSTALL_PREFIX}/lib64) -SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${STAGED_INSTALL_PREFIX}) SET(BUILD_SUPPORT_DIR ${PROJECT_SOURCE_DIR}/build_support) + +SET(PLIB_INSTALL_DIR ${CMAKE_BINARY_DIR}/lib) +SET(LIB_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_SUFFIX}) +SET(LIB_INCLUDE_DIR ${LIB_INSTALL_PREFIX}/include) +SET(LIB_INSTALL_DIR ${LIB_INSTALL_PREFIX}/lib) +SET(LIB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${EP_BASE_SUFFIX}/Source) + # make sure we use the same compiler for all dependencies SET(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -121,11 +125,13 @@ SET(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}/third-party) SET(THIRD_PARTY_BUILD_TYPE ${CMAKE_BUILD_TYPE}) SET(EXTERNAL_PROJECT_LOG_ARGS LOG_DOWNLOAD 0 - LOG_UPDATE 1 + LOG_UPDATE 0 LOG_CONFIGURE 0 LOG_BUILD 0 - LOG_TEST 1 - LOG_INSTALL 0) + LOG_TEST 0 + LOG_INSTALL 0 + BUILD_ALWAYS 0 +) IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(LIB rt) @@ -145,12 +151,15 @@ ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") ENDIF() SET(LIB ${LIB} CACHE INTERNAL "libs which should be linked for executable target") -INCLUDE(FetchContent) +INCLUDE(ExternalProject) +INCLUDE(cmake/findTools.cmake) INCLUDE(cmake/openssl.cmake) +INCLUDE(cmake/lz4.cmake) +INCLUDE(cmake/zstd.cmake) INCLUDE(cmake/gflags.cmake) -INCLUDE(cmake/findTools.cmake) INCLUDE(cmake/snappy.cmake) +INCLUDE(cmake/zlib.cmake) INCLUDE(cmake/leveldb.cmake) INCLUDE(cmake/libevent.cmake) INCLUDE(cmake/llhttp.cmake) @@ -158,20 +167,20 @@ INCLUDE(cmake/fmt.cmake) INCLUDE(cmake/spdlog.cmake) INCLUDE(cmake/gtest.cmake) INCLUDE(cmake/rocksdb.cmake) -INCLUDE(cmake/zlib.cmake) INCLUDE(cmake/protobuf.cmake) INCLUDE(cmake/brpc.cmake) INCLUDE(cmake/braft.cmake) -ENABLE_TESTING() - SET(PROTO_OUTPUT_DIR "${CMAKE_BINARY_DIR}/generated_pb") FILE(MAKE_DIRECTORY "${PROTO_OUTPUT_DIR}") +#INCLUDE(cmake/protogen.cmake) + ADD_SUBDIRECTORY(src/pstd) ADD_SUBDIRECTORY(src/net) ADD_SUBDIRECTORY(src/praft) ADD_SUBDIRECTORY(src/storage) + ADD_SUBDIRECTORY(src) ############################################################################# diff --git a/build.sh b/build.sh index 402e4a56d..644a5df64 100755 --- a/build.sh +++ b/build.sh @@ -16,7 +16,7 @@ BUILD_TYPE=Release VERBOSE=0 CMAKE_FLAGS="" MAKE_FLAGS="" -PREFIX="build" +PREFIX="cmake-build" ARGS=`getopt -a -o h -l help,debug,verbose,prefix: -- "$@"` function show_help() { diff --git a/cmake/braft.cmake b/cmake/braft.cmake index 1f67b097d..e9acb0f08 100644 --- a/cmake/braft.cmake +++ b/cmake/braft.cmake @@ -5,12 +5,14 @@ INCLUDE(ExternalProject) -SET(BRAFT_SOURCES_DIR ${THIRD_PARTY_PATH}/braft) -SET(BRAFT_INSTALL_DIR ${THIRD_PARTY_PATH}/install/braft) -SET(BRAFT_INCLUDE_DIR "${BRAFT_INSTALL_DIR}/include" CACHE PATH "braft include directory." FORCE) -SET(BRAFT_LIBRARIES "${BRAFT_INSTALL_DIR}/lib/libbraft.a" CACHE FILEPATH "braft library." FORCE) +SET(BRAFT_SOURCES_DIR ${LIB_INSTALL_PREFIX}) +SET(BRAFT_INSTALL_DIR ${LIB_INSTALL_PREFIX}) +SET(BRAFT_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "brpc include directory." FORCE) +SET(BRAFT_LIBRARIES "${LIB_INSTALL_DIR}/libbraft.a" CACHE FILEPATH "brpc library." FORCE) -SET(prefix_path "${THIRD_PARTY_PATH}/install/brpc|${CMAKE_CURRENT_BINARY_DIR}/_deps/gflags-build|${THIRD_PARTY_PATH}/install/protobuf|${THIRD_PARTY_PATH}/install/zlib|${THIRD_PARTY_PATH}/install/leveldb") +IF (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + SET(BRAFT_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-U,__Z13GetStackTracePPvii") +ENDIF () ExternalProject_Add( extern_braft @@ -19,30 +21,31 @@ ExternalProject_Add( GIT_REPOSITORY "https://github.com/pikiwidb/braft.git" GIT_TAG master GIT_SHALLOW true - PREFIX ${BRAFT_SOURCES_DIR} - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_INSTALL_PREFIX=${BRAFT_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR=${BRAFT_INSTALL_DIR}/lib + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DCMAKE_CXX_FLAGS=${BRAFT_CXX_FLAGS} + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DBRPC_LIB=${BRPC_LIBRARIES} + -DBRPC_INCLUDE_PATH=${BRPC_INCLUDE_DIR} -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} - -DCMAKE_PREFIX_PATH=${prefix_path} -DBRPC_WITH_GLOG=OFF - -DOPENSSL_ROOT_DIR=${THIRD_PARTY_PATH}/install/openssl - ${EXTERNAL_OPTIONAL_ARGS} - LIST_SEPARATOR | - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${BRAFT_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR:PATH=${BRAFT_INSTALL_DIR}/lib - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} - BUILD_IN_SOURCE 1 - BUILD_COMMAND $(MAKE) -j ${CPU_CORE} braft-static - INSTALL_COMMAND mkdir -p ${BRAFT_INSTALL_DIR}/lib/ COMMAND cp ${BRAFT_SOURCES_DIR}/src/extern_braft/output/lib/libbraft.a ${BRAFT_LIBRARIES} COMMAND rm -rf ${BRAFT_INCLUDE_DIR} COMMAND cp -r ${BRAFT_SOURCES_DIR}/src/extern_braft/output/include ${BRAFT_INCLUDE_DIR} + -DCMAKE_FIND_LIBRARY_SUFFIXES=${LIB_INSTALL_PREFIX} + -DLEVELDB_LIB=${LEVELDB_LIBRARIES} + -DLEVELDB_INCLUDE_PATH=${LEVELDB_INCLUDE_DIR} + + -DGFLAGS_INCLUDE_PATH=${GFLAGS_INCLUDE_DIR} + -DGFLAGS_LIB=${GFLAGS_LIBRARIES} + + -DPROTOC_LIB=${PROTOC_LIBRARY} + -DPROTOBUF_LIBRARIES=${PROTOBUF_LIBRARY} + -DPROTOBUF_INCLUDE_DIRS=${PROTOBUF_INCLUDE_DIR} + -DPROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC} + -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + BUILD_COMMAND make -j${CPU_CORE} ) -ADD_DEPENDENCIES(extern_braft brpc) + +ADD_DEPENDENCIES(extern_braft brpc gflags) ADD_LIBRARY(braft STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET braft PROPERTY IMPORTED_LOCATION ${BRAFT_LIBRARIES}) -ADD_DEPENDENCIES(braft extern_braft) \ No newline at end of file +ADD_DEPENDENCIES(braft extern_braft) diff --git a/cmake/brpc.cmake b/cmake/brpc.cmake index 890f8432b..2580254a6 100644 --- a/cmake/brpc.cmake +++ b/cmake/brpc.cmake @@ -3,44 +3,46 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE(ExternalProject) +SET(BRPC_SOURCES_DIR ${LIB_INSTALL_PREFIX}) +SET(BRPC_INSTALL_DIR ${LIB_INSTALL_PREFIX}) +SET(BRPC_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "brpc include directory." FORCE) +SET(BRPC_LIBRARIES "${LIB_INSTALL_DIR}/libbrpc.a" CACHE FILEPATH "brpc library." FORCE) -SET(BRPC_SOURCES_DIR ${THIRD_PARTY_PATH}/brpc) -SET(BRPC_INSTALL_DIR ${THIRD_PARTY_PATH}/install/brpc) -SET(BRPC_INCLUDE_DIR "${BRPC_INSTALL_DIR}/include" CACHE PATH "brpc include directory." FORCE) -SET(BRPC_LIBRARIES "${BRPC_INSTALL_DIR}/lib/libbrpc.a" CACHE FILEPATH "brpc library." FORCE) +SET(CMAKE_FIND_LIBRARY_SUFFIXES ${LIB_INSTALL_PREFIX}) # Reference https://stackoverflow.com/questions/45414507/pass-a-list-of-prefix-paths-to-externalproject-add-in-cmake-args -SET(prefix_path "${CMAKE_CURRENT_BINARY_DIR}/_deps/gflags-build|${THIRD_PARTY_PATH}/install/protobuf|${THIRD_PARTY_PATH}/install/zlib|${THIRD_PARTY_PATH}/install/leveldb|${THIRD_PARTY_PATH}/install/openssl") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") +SET(CMAKE_CPP_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") # If minimal .a is need, you can set WITH_DEBUG_SYMBOLS=OFF -EXTERNALPROJECT_ADD( +ExternalProject_Add( extern_brpc ${EXTERNAL_PROJECT_LOG_ARGS} DEPENDS ssl crypto zlib protobuf leveldb gflags URL https://github.com/apache/brpc/archive/refs/tags/1.8.0.tar.gz URL_HASH SHA256=13ffb2f1f57c679379a20367c744b3e597614a793ec036cd7580aae90798019d - PREFIX ${BRPC_SOURCES_DIR} - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DCMAKE_CPP_FLAGS=${CMAKE_CPP_FLAGS} -DCMAKE_INSTALL_PREFIX=${BRPC_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR=${BRPC_INSTALL_DIR}/lib + -DCMAKE_FIND_LIBRARY_SUFFIXES=${LIB_INSTALL_PREFIX} + -DGFLAGS_INCLUDE_PATH=${GFLAGS_INCLUDE_DIR} + -DBUILD_SHARED_LIBS=FALSE + -DBUILD_BRPC_TOOLS=OFF + -DGFLAGS_LIBRARY=${GFLAGS_LIBRARIES} + + -DLEVELDB_LIB=${LEVELDB_LIBRARIES} + -DLEVELDB_INCLUDE_PATH=${LEVELDB_INCLUDE_DIR} + + -DPROTOC_LIB=${PROTOC_LIBRARY} + -DPROTOBUF_LIBRARIES=${PROTOBUF_LIBRARY} + -DPROTOBUF_INCLUDE_DIRS=${PROTOBUF_INCLUDE_DIR} + -DPROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC} + + -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR} -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} - -DCMAKE_PREFIX_PATH=${prefix_path} + -DPROJECT_BINARY_DIR=${LIB_INSTALL_PREFIX} -DWITH_GLOG=OFF -DDOWNLOAD_GTEST=OFF - ${EXTERNAL_OPTIONAL_ARGS} - LIST_SEPARATOR | - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${BRPC_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR:PATH=${BRPC_INSTALL_DIR}/lib - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} - BUILD_IN_SOURCE 1 - BUILD_COMMAND $(MAKE) -j ${CPU_CORE} brpc-static + BUILD_COMMAND make -j${CPU_CORE} ) ADD_DEPENDENCIES(extern_brpc ssl crypto zlib protobuf leveldb gflags) ADD_LIBRARY(brpc STATIC IMPORTED GLOBAL) diff --git a/cmake/fmt.cmake b/cmake/fmt.cmake index fd584943e..f76ef15a8 100644 --- a/cmake/fmt.cmake +++ b/cmake/fmt.cmake @@ -3,11 +3,30 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE_GUARD() -FetchContent_Declare(fmt +IF (${LIB_BUILD_TYPE} STREQUAL DEBUG) + SET(LIB_FMT libfmtd.a) +ELSE () + SET(LIB_FMT libfmt.a) +ENDIF () + +SET(FMT_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "fmt include directory." FORCE) +SET(FMT_LIBRARIES "${LIB_INSTALL_DIR}/${LIB_FMT}" CACHE FILEPATH "fmt library directory." FORCE) + +ExternalProject_Add( + extern_fmt URL https://github.com/fmtlib/fmt/archive/10.1.1.zip URL_HASH SHA256=3c2e73019178ad72b0614a3124f25de454b9ca3a1afe81d5447b8d3cbdb6d322 - ) + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DFMT_DOC=FALSE + -DFMT_TEST=FALSE + -DSHARED_LIBS=FALSE + BUILD_COMMAND make -j${CPU_CORE} +) + -FetchContent_MakeAvailable(fmt) +ADD_LIBRARY(fmt STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET fmt PROPERTY IMPORTED_LOCATION ${FMT_LIBRARIES}) +ADD_DEPENDENCIES(fmt extern_fmt) diff --git a/cmake/gflags.cmake b/cmake/gflags.cmake index fbd8cdb12..f1f8c8d8c 100644 --- a/cmake/gflags.cmake +++ b/cmake/gflags.cmake @@ -3,29 +3,37 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE_GUARD() - -SET(GFLAGS_BUILD_TYPE "Release") -SET(CMAKE_BUILD_TYPE ${GFLAGS_BUILD_TYPE}) - -FetchContent_Declare(gflags - URL https://github.com/gflags/gflags/archive/v2.2.2.zip - URL_HASH SHA256=19713a36c9f32b33df59d1c79b4958434cb005b5b47dc5400a7a4b078111d9b5 +IF (${LIB_BUILD_TYPE} STREQUAL DEBUG) + SET(LIB_GFLAGS libgflags_debug.a) +ELSE () + SET(LIB_GFLAGS libgflags.a) +ENDIF () + +SET(GFLAGS_ROOT ${LIB_INSTALL_PREFIX} CACHE PATH "gflags source directory." FORCE) +SET(GFLAGS_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "gflags include directory." FORCE) +SET(GFLAGS_LIBRARIES "${LIB_INSTALL_DIR}/${LIB_GFLAGS}" CACHE FILEPATH "gflags library." FORCE) +SET(GFLAGS_LIBRARY "${LIB_INSTALL_DIR}/${LIB_GFLAGS}" CACHE FILEPATH "gflags library." FORCE) + +SET(GFLAGS_INCLUDE_PATH "${LIB_INCLUDE_DIR}/gflags" CACHE PATH "gflags include directory." FORCE) + +ExternalProject_Add( + extern_gflags + URL https://github.com/gflags/gflags/archive/v2.2.2.zip + URL_HASH SHA256=19713a36c9f32b33df59d1c79b4958434cb005b5b47dc5400a7a4b078111d9b5 + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DBUILD_SHARED_LIBS=OFF + -DGFLAGS_BUILD_STATIC_LIBS=ON + -DGFLAGS_BUILD_SHARED_LIBS=OFF + -DGFLAGS_BUILD_gflags_LIB=ON + -DGFLAGS_BUILD_gflags_nothreads_LIB=ON + -DGFLAGS_NAMESPACE=gflags + -DGFLAGS_BUILD_TESTING=OFF + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + BUILD_COMMAND make -j${CPU_CORE} ) -SET(GFLAGS_BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE) -SET(GFLAGS_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) -SET(GFLAGS_BUILD_gflags_LIB ON CACHE BOOL "" FORCE) -SET(GFLAGS_BUILD_gflags_nothreads_LIB ON CACHE BOOL "" FORCE) -SET(GFLAGS_BUILD_TESTING OFF CACHE BOOL "" FORCE) -FETCHCONTENT_MAKEAVAILABLE(gflags) - -FIND_PACKAGE(Threads REQUIRED) - -TARGET_LINK_LIBRARIES(gflags_static Threads::Threads) - -SET(GFLAGS_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/_deps/gflags-build/include CACHE PATH "" FORCE) -SET(GFLAGS_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/_deps/gflags-build/libgflags.a CACHE PATH "" FORCE) -SET(GFLAGS_LIB ${CMAKE_CURRENT_BINARY_DIR}/_deps/gflags-build/libgflags.a CACHE PATH "" FORCE) - -SET(CMAKE_BUILD_TYPE ${THIRD_PARTY_BUILD_TYPE}) \ No newline at end of file +ADD_LIBRARY(gflags STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARIES}) +ADD_DEPENDENCIES(gflags extern_gflags) diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake index 0c6140910..3b27ea1bb 100644 --- a/cmake/gtest.cmake +++ b/cmake/gtest.cmake @@ -3,11 +3,23 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -FETCHCONTENT_DECLARE( - gtest +SET(GTEST_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "gtest include directory." FORCE) +SET(GTEST_LIBRARIES "${LIB_INSTALL_DIR}/libgtest.a" CACHE FILEPATH "gtest lib directory." FORCE) +SET(GTEST_MAIN_LIBRARIES "${LIB_INSTALL_DIR}/libgtest_main.a" CACHE FILEPATH "gtest main include directory." FORCE) +SET(GMOCK_LIBRARIES "${LIB_INSTALL_DIR}/libgmock.a" CACHE FILEPATH "gmock directory." FORCE) + +ExternalProject_Add( + extern_gtest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0 + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ) -SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FETCHCONTENT_MAKEAVAILABLE(gtest) +ADD_DEPENDENCIES(extern_gtest snappy gflags zlib) +ADD_LIBRARY(gtest STATIC IMPORTED GLOBAL) +ADD_LIBRARY(gtest_main STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET gtest PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARIES}) +SET_PROPERTY(TARGET gtest_main PROPERTY IMPORTED_LOCATION ${GTEST_MAIN_LIBRARIES}) +ADD_DEPENDENCIES(gtest extern_gtest) diff --git a/cmake/leveldb.cmake b/cmake/leveldb.cmake index 701cd9d26..fa8c2963a 100644 --- a/cmake/leveldb.cmake +++ b/cmake/leveldb.cmake @@ -3,14 +3,9 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE(ExternalProject) - -SET(LEVELDB_SOURCES_DIR ${THIRD_PARTY_PATH}/leveldb) -SET(LEVELDB_INSTALL_DIR ${THIRD_PARTY_PATH}/install/leveldb) -SET(LEVELDB_INCLUDE_DIR "${LEVELDB_INSTALL_DIR}/include" CACHE PATH "leveldb include directory." FORCE) -SET(LEVELDB_LIBRARIES "${LEVELDB_INSTALL_DIR}/lib/libleveldb.a" CACHE FILEPATH "leveldb library." FORCE) - -SET(prefix_path "${THIRD_PARTY_PATH}/install/snappy") +SET(LEVELDB_INCLUDE_DIR "${LIB_INCLUDE_DIR}/leveldb" CACHE PATH "leveldb include directory." FORCE) +SET(LEVELDB_LIBRARIES "${LIB_INSTALL_DIR}/libleveldb.a" CACHE FILEPATH "leveldb include directory." FORCE) +SET(LEVELDB_INSTALL_LIBDIR "${LIB_INSTALL_PREFIX}/lib") ExternalProject_Add( extern_leveldb @@ -18,31 +13,16 @@ ExternalProject_Add( DEPENDS snappy GIT_REPOSITORY "https://github.com/google/leveldb.git" GIT_TAG "1.23" - PREFIX ${LEVELDB_SOURCES_DIR} - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} - -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} - -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE} - -DCMAKE_INSTALL_PREFIX=${LEVELDB_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR=${LEVELDB_INSTALL_DIR}/lib + CMAKE_ARGS + -DCMAKE_INSTALL_LIBDIR=${LEVELDB_INSTALL_LIBDIR} + -DCMAKE_INSTALL_INCLUDEDIR=${LEVELDB_INCLUDE_DIR} -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLEVELDB_BUILD_TESTS=OFF -DLEVELDB_BUILD_BENCHMARKS=OFF -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} - -DCMAKE_PREFIX_PATH=${prefix_path} - ${EXTERNAL_OPTIONAL_ARGS} - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${LEVELDB_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR:PATH=${LEVELDB_INSTALL_DIR}/lib - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} + BUILD_COMMAND make -j${CPU_CORE} ) -ADD_DEPENDENCIES(extern_leveldb snappy) ADD_LIBRARY(leveldb STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET leveldb PROPERTY IMPORTED_LOCATION ${LEVELDB_LIBRARIES}) -ADD_DEPENDENCIES(leveldb extern_leveldb) \ No newline at end of file +ADD_DEPENDENCIES(leveldb extern_leveldb) diff --git a/cmake/libevent.cmake b/cmake/libevent.cmake index beaf76a62..d63b4043c 100644 --- a/cmake/libevent.cmake +++ b/cmake/libevent.cmake @@ -4,6 +4,8 @@ # of patent rights can be found in the PATENTS file in the same directory. # libevent +INCLUDE(FetchContent) + FETCHCONTENT_DECLARE( libevent GIT_REPOSITORY https://github.com/libevent/libevent.git diff --git a/cmake/llhttp.cmake b/cmake/llhttp.cmake index a2a455625..288ecc52c 100644 --- a/cmake/llhttp.cmake +++ b/cmake/llhttp.cmake @@ -4,22 +4,19 @@ # of patent rights can be found in the PATENTS file in the same directory. # nodejs/llhttp -FETCHCONTENT_DECLARE( - llhttp +SET(LLHTTP_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "llhttp include directory." FORCE) +SET(LLHTTP_LIBRARIES "${LIB_INSTALL_DIR}/libllhttp.a" CACHE FILEPATH "llhttp library." FORCE) +ExternalProject_Add( + extern_llhttp + ${EXTERNAL_PROJECT_LOG_ARGS} URL https://github.com/nodejs/llhttp/archive/refs/tags/release/v6.0.5.tar.gz URL_HASH MD5=7ec6829c56642cce27e3d8e06504ddca - DOWNLOAD_NO_PROGRESS 1 - UPDATE_COMMAND "" - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 - BUILD_ALWAYS 1 CMAKE_ARGS - -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX} + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} - -DBUILD_STATIC_LIBS=ON - -DBUILD_SHARED_LIBS=OFF - BUILD_COMMAND make -j${CPU_CORE} ) -FETCHCONTENT_MAKEAVAILABLE(llhttp) \ No newline at end of file +ADD_DEPENDENCIES(extern_llhttp snappy gflags zlib) +ADD_LIBRARY(llhttp STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET llhttp PROPERTY IMPORTED_LOCATION ${LLHTTP_LIBRARIES}) +ADD_DEPENDENCIES(llhttp extern_llhttp) diff --git a/cmake/lz4.cmake b/cmake/lz4.cmake new file mode 100644 index 000000000..cdb8f3515 --- /dev/null +++ b/cmake/lz4.cmake @@ -0,0 +1,26 @@ +# Copyright (c) 2023-present, Qihoo, Inc. All rights reserved. +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +SET(LZ4_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "lz4 include directory." FORCE) +SET(LZ4_LIBRARIES "${LIB_INSTALL_DIR}/liblz4.a" CACHE FILEPATH "lz4 include directory." FORCE) + +ExternalProject_Add( + extern_lz4 + URL https://github.com/lz4/lz4/archive/refs/tags/v1.9.4.tar.gz + URL_HASH MD5=e9286adb64040071c5e23498bf753261 + ${EXTERNAL_PROJECT_LOG_ARGS} + SOURCE_SUBDIR build/cmake + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DBUILD_TESTING=OFF + -DBUILD_STATIC_LIBS=ON + -DBUILD_SHARED_LIBS=OFF + BUILD_COMMAND make -j${CPU_CORE} +) + +ADD_LIBRARY(lz4 STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET lz4 PROPERTY IMPORTED_LOCATION ${LZ4_LIBRARIES}) +ADD_DEPENDENCIES(lz4 extern_lz4) diff --git a/cmake/openssl.cmake b/cmake/openssl.cmake index 12d437263..e99ffebc7 100644 --- a/cmake/openssl.cmake +++ b/cmake/openssl.cmake @@ -3,29 +3,27 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE(ExternalProject) - -SET(OPENSSL_SOURCE_DIR ${THIRD_PARTY_PATH}/openssl) -SET(OPENSSL_INSTALL_DIR ${THIRD_PARTY_PATH}/install/openssl) -SET(OPENSSL_INCLUDE_DIR ${OPENSSL_INSTALL_DIR}/include) -SET(OPENSSL_CONFIGURE_COMMAND ${OPENSSL_SOURCE_DIR}/config) +SET(OPENSSL_SOURCE_DIR ${LIB_INSTALL_PREFIX}) +SET(OPENSSL_INSTALL_DIR "${LIB_INSTALL_PREFIX}") +SET(OPENSSL_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "Openssl include directory." FORCE) FILE(MAKE_DIRECTORY ${OPENSSL_INCLUDE_DIR}) ExternalProject_Add( OpenSSL - SOURCE_DIR ${OPENSSL_SOURCE_DIR} + # SOURCE_DIR ${OPENSSL_SOURCE_DIR} URL https://github.com/openssl/openssl/archive/refs/tags/openssl-3.2.1.tar.gz URL_HASH SHA256=75cc6803ffac92625c06ea3c677fb32ef20d15a1b41ecc8dddbc6b9d6a2da84c USES_TERMINAL_DOWNLOAD TRUE CONFIGURE_COMMAND - ${OPENSSL_CONFIGURE_COMMAND} + /config --prefix=${OPENSSL_INSTALL_DIR} --openssldir=${OPENSSL_INSTALL_DIR} --libdir=${OPENSSL_INSTALL_DIR}/lib - BUILD_COMMAND make + no-docs + BUILD_COMMAND make -j${CPU_CORE} TEST_COMMAND "" - INSTALL_COMMAND make install + INSTALL_COMMAND make install_sw INSTALL_DIR ${OPENSSL_INSTALL_DIR} ) @@ -35,6 +33,7 @@ SET_PROPERTY(TARGET ssl PROPERTY IMPORTED_LOCATION ${OPENSSL_INSTALL_DIR}/${OPEN SET_PROPERTY(TARGET ssl PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR}) ADD_DEPENDENCIES(ssl OpenSSL) SET(OPENSSL_SSL_LIBRARY ${OPENSSL_INSTALL_DIR}/${OPENSSL_LIB}/libssl.a) +list(APPEND LIBS ssl) ADD_LIBRARY(crypto STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET crypto PROPERTY IMPORTED_LOCATION ${OPENSSL_INSTALL_DIR}/${OPENSSL_LIB}/libcrypto.a) @@ -42,5 +41,4 @@ SET_PROPERTY(TARGET crypto PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCL ADD_DEPENDENCIES(crypto OpenSSL) SET(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_INSTALL_DIR}/${OPENSSL_LIB}/libcrypto.a) -SET(OPENSSL_INCLUDE_DIR ${THIRD_PARTY_PATH}/install/openssl/include) -SET(OPENSSL_ROOT_DIR ${THIRD_PARTY_PATH}/install/openssl/bin/openssl) \ No newline at end of file +SET(OPENSSL_INCLUDE_DIR ${LIB_INCLUDE_DIR}) diff --git a/cmake/protobuf.cmake b/cmake/protobuf.cmake index 2754a7fc5..54d0faea8 100644 --- a/cmake/protobuf.cmake +++ b/cmake/protobuf.cmake @@ -3,167 +3,42 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE(ExternalProject) # Always invoke `FIND_PACKAGE(Protobuf)` for importing function protobuf_generate_cpp -FIND_PACKAGE(Protobuf QUIET) -MACRO(UNSET_VAR VAR_NAME) - UNSET(${VAR_NAME} CACHE) - UNSET(${VAR_NAME}) -ENDMACRO() -UNSET_VAR(PROTOBUF_INCLUDE_DIR) -UNSET_VAR(PROTOBUF_FOUND) -UNSET_VAR(PROTOBUF_PROTOC_EXECUTABLE) -UNSET_VAR(PROTOBUF_PROTOC_LIBRARY) -UNSET_VAR(PROTOBUF_LITE_LIBRARY) -UNSET_VAR(PROTOBUF_LIBRARY) -UNSET_VAR(PROTOBUF_INCLUDE_DIR) -UNSET_VAR(Protobuf_PROTOC_EXECUTABLE) - -# Print and set the protobuf library information, -# finish this cmake process and exit from this file. -MACRO(PROMPT_PROTOBUF_LIB) - SET(protobuf_DEPS ${ARGN}) - - MESSAGE(STATUS "Protobuf protoc executable: ${PROTOBUF_PROTOC_EXECUTABLE}") - MESSAGE(STATUS "Protobuf-lite library: ${PROTOBUF_LITE_LIBRARY}") - MESSAGE(STATUS "Protobuf library: ${PROTOBUF_LIBRARY}") - MESSAGE(STATUS "Protoc library: ${PROTOBUF_PROTOC_LIBRARY}") - MESSAGE(STATUS "Protobuf version: ${PROTOBUF_VERSION}") - INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) - - # Assuming that all the protobuf libraries are of the same type. - IF (${PROTOBUF_LIBRARY} MATCHES ${CMAKE_STATIC_LIBRARY_SUFFIX}) - SET(protobuf_LIBTYPE STATIC) - ELSEIF (${PROTOBUF_LIBRARY} MATCHES "${CMAKE_SHARED_LIBRARY_SUFFIX}$") - SET(protobuf_LIBTYPE SHARED) - ELSE () - MESSAGE(FATAL_ERROR "Unknown library type: ${PROTOBUF_LIBRARY}") - ENDIF () - - ADD_LIBRARY(protobuf ${protobuf_LIBTYPE} IMPORTED GLOBAL) - SET_PROPERTY(TARGET protobuf PROPERTY IMPORTED_LOCATION ${PROTOBUF_LIBRARY}) - - ADD_LIBRARY(protobuf_lite ${protobuf_LIBTYPE} IMPORTED GLOBAL) - SET_PROPERTY(TARGET protobuf_lite PROPERTY IMPORTED_LOCATION ${PROTOBUF_LITE_LIBRARY}) - - ADD_LIBRARY(libprotoc ${protobuf_LIBTYPE} IMPORTED GLOBAL) - SET_PROPERTY(TARGET libprotoc PROPERTY IMPORTED_LOCATION ${PROTOC_LIBRARY}) - - ADD_EXECUTABLE(protoc IMPORTED GLOBAL) - SET_PROPERTY(TARGET protoc PROPERTY IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE}) - SET(Protobuf_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE}) - - FOREACH (dep ${protobuf_DEPS}) - ADD_DEPENDENCIES(protobuf ${dep}) - ADD_DEPENDENCIES(protobuf_lite ${dep}) - ADD_DEPENDENCIES(libprotoc ${dep}) - ADD_DEPENDENCIES(protoc ${dep}) - ENDFOREACH () - - RETURN() -ENDMACRO() - -MACRO(SET_PROTOBUF_VERSION) - EXEC_PROGRAM(${PROTOBUF_PROTOC_EXECUTABLE} ARGS --version OUTPUT_VARIABLE PROTOBUF_VERSION) - STRING(REGEX MATCH "[0-9]+.[0-9]+" PROTOBUF_VERSION "${PROTOBUF_VERSION}") -ENDMACRO() - -SET(PROTOBUF_ROOT "" CACHE PATH "Folder contains protobuf") - -IF (NOT "${PROTOBUF_ROOT}" STREQUAL "") - MESSAGE("found system protobuf") - - FIND_PATH(PROTOBUF_INCLUDE_DIR google/protobuf/message.h PATHS ${PROTOBUF_ROOT}/include NO_DEFAULT_PATH) - FIND_LIBRARY(PROTOBUF_LIBRARY protobuf libprotobuf.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH) - FIND_LIBRARY(PROTOBUF_LITE_LIBRARY protobuf-lite libprotobuf-lite.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH) - FIND_LIBRARY(PROTOBUF_PROTOC_LIBRARY protoc libprotoc.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH) - FIND_PROGRAM(PROTOBUF_PROTOC_EXECUTABLE protoc PATHS ${PROTOBUF_ROOT}/bin NO_DEFAULT_PATH) - IF (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOBUF_LITE_LIBRARY AND PROTOBUF_PROTOC_LIBRARY AND PROTOBUF_PROTOC_EXECUTABLE) - MESSAGE(STATUS "Using custom protobuf library in ${PROTOBUF_ROOT}.") - SET(PROTOBUF_FOUND TRUE) - SET_PROTOBUF_VERSION() - PROMPT_PROTOBUF_LIB() - ELSE () - MESSAGE(WARNING "Cannot find protobuf library in ${PROTOBUF_ROOT}") - ENDIF () +IF (${LIB_BUILD_TYPE} STREQUAL DEBUG) + SET(LIB_PROTOBUF "libprotobufd.a") + SET(LIB_PROTOC "libprotocd.a") +ELSE () + SET(LIB_PROTOBUF "libprotobuf.a") + SET(LIB_PROTOC "libprotoc.a") ENDIF () -FUNCTION(build_protobuf TARGET_NAME) - STRING(REPLACE "extern_" "" TARGET_DIR_NAME "${TARGET_NAME}") - SET(PROTOBUF_SOURCES_DIR ${THIRD_PARTY_PATH}/${TARGET_DIR_NAME}) - SET(PROTOBUF_INSTALL_DIR ${THIRD_PARTY_PATH}/install/${TARGET_DIR_NAME}) - - SET(${TARGET_NAME}_INCLUDE_DIR "${PROTOBUF_INSTALL_DIR}/include" PARENT_SCOPE) - SET(PROTOBUF_INCLUDE_DIR "${PROTOBUF_INSTALL_DIR}/include" PARENT_SCOPE) - SET(${TARGET_NAME}_LITE_LIBRARY - "${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite${CMAKE_STATIC_LIBRARY_SUFFIX}" - PARENT_SCOPE) - SET(${TARGET_NAME}_LIBRARY - "${PROTOBUF_INSTALL_DIR}/lib/libprotobuf${CMAKE_STATIC_LIBRARY_SUFFIX}" - PARENT_SCOPE) - SET(${TARGET_NAME}_PROTOC_LIBRARY - "${PROTOBUF_INSTALL_DIR}/lib/libprotoc${CMAKE_STATIC_LIBRARY_SUFFIX}" - PARENT_SCOPE) - SET(${TARGET_NAME}_PROTOC_EXECUTABLE - "${PROTOBUF_INSTALL_DIR}/bin/protoc${CMAKE_EXECUTABLE_SUFFIX}" - PARENT_SCOPE) - - set(prefix_path "${THIRD_PARTY_PATH}/install/zlib") - - # Make sure zlib's two headers are in your /Path/to/install/include path, - # and delete libz.so which we don't need - IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") - FILE(WRITE ${PROTOBUF_SOURCES_DIR}/src/config.sh - "rm -f ${THIRD_PARTY_PATH}/install/zlib/lib/*.dylib && mkdir -p ${THIRD_PARTY_PATH}/install/protobuf/include && cp ${THIRD_PARTY_PATH}/install/zlib/include/* ${THIRD_PARTY_PATH}/install/protobuf/include/ && ${CMAKE_COMMAND} ${PROTOBUF_SOURCES_DIR}/src/${TARGET_NAME}/cmake -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}' -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} -DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}' -DCMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' -DCMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}' -DCMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}' -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_SKIP_RPATH=ON -Dprotobuf_WITH_ZLIB=ON -DZLIB_INCLUDE_DIR=${THIRD_PARTY_PATH}/install/zlib/include -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${prefix_path} ${EXTERNAL_OPTIONAL_ARGS}" - ) - ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux") - FILE(WRITE ${PROTOBUF_SOURCES_DIR}/src/config.sh - "rm -f ${THIRD_PARTY_PATH}/install/zlib/lib/libz.so* && mkdir -p ${THIRD_PARTY_PATH}/install/protobuf/include && cp ${THIRD_PARTY_PATH}/install/zlib/include/* ${THIRD_PARTY_PATH}/install/protobuf/include/ && ${CMAKE_COMMAND} ${PROTOBUF_SOURCES_DIR}/src/${TARGET_NAME}/cmake -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}' -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} -DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}' -DCMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' -DCMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}' -DCMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}' -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_SKIP_RPATH=ON -Dprotobuf_WITH_ZLIB=ON -DZLIB_INCLUDE_DIR=${THIRD_PARTY_PATH}/install/zlib/include -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR} -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=${prefix_path} ${EXTERNAL_OPTIONAL_ARGS}" - ) - ELSE () - MESSAGE(FATAL_ERROR "only support linux or macOS") - ENDIF () - - ExternalProject_Add( - ${TARGET_NAME} - ${EXTERNAL_PROJECT_LOG_ARGS} - PREFIX ${PROTOBUF_SOURCES_DIR} - UPDATE_COMMAND "" - DEPENDS zlib - URL "https://github.com/protocolbuffers/protobuf/archive/v3.18.0.tar.gz" - URL_HASH SHA256=14e8042b5da37652c92ef6a2759e7d2979d295f60afd7767825e3de68c856c54 - CONFIGURE_COMMAND mv ../config.sh . COMMAND sh config.sh - CMAKE_CACHE_ARGS - -DCMAKE_INSTALL_PREFIX:PATH=${PROTOBUF_INSTALL_DIR} - -DCMAKE_BUILD_TYPE:STRING=Release - -DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - ${OPTIONAL_CACHE_ARGS} - ) - -ENDFUNCTION() - -SET(PROTOBUF_VERSION 3.18.0) - -IF (NOT PROTOBUF_FOUND) - MESSAGE("build protobuf") - - build_protobuf(extern_protobuf) - - SET(PROTOBUF_INCLUDE_DIR ${extern_protobuf_INCLUDE_DIR} - CACHE PATH "protobuf include directory." FORCE) - SET(PROTOBUF_LITE_LIBRARY ${extern_protobuf_LITE_LIBRARY} - CACHE FILEPATH "protobuf lite library." FORCE) - SET(PROTOBUF_LIBRARY ${extern_protobuf_LIBRARY} - CACHE FILEPATH "protobuf library." FORCE) - SET(PROTOBUF_LIBRARIES ${extern_protobuf_LIBRARY} - CACHE FILEPATH "protobuf library." FORCE) - SET(PROTOBUF_PROTOC_LIBRARY ${extern_protobuf_PROTOC_LIBRARY} - CACHE FILEPATH "protoc library." FORCE) - - SET(PROTOBUF_PROTOC_EXECUTABLE ${extern_protobuf_PROTOC_EXECUTABLE} - CACHE FILEPATH "protobuf executable." FORCE) - PROMPT_PROTOBUF_LIB(extern_protobuf zlib) -ENDIF (NOT PROTOBUF_FOUND) - +SET(PROTOBUF_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "protobuf include directory." FORCE) +SET(PROTOBUF_LIBRARY "${LIB_INSTALL_DIR}/${LIB_PROTOBUF}" CACHE FILEPATH "protobuf install directory." FORCE) +SET(PROTOC_LIBRARY "${LIB_INSTALL_DIR}/${LIB_PROTOC}" CACHE FILEPATH "protoc install directory." FORCE) +SET(PROTOBUF_PROTOC "${LIB_INSTALL_PREFIX}/bin/protoc") + +ExternalProject_Add( + extern_protobuf + DOWNLOAD_NO_PROGRESS 1 + UPDATE_COMMAND "" + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + SOURCE_SUBDIR cmake + DEPENDS zlib + URL "https://github.com/protocolbuffers/protobuf/archive/v3.18.0.tar.gz" + URL_HASH SHA256=14e8042b5da37652c92ef6a2759e7d2979d295f60afd7767825e3de68c856c54 + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DBUILD_SHARED_LIBS=OFF + -Dprotobuf_BUILD_TESTS=OFF + -Dprotobuf_BUILD_LIBPROTOC=ON + BUILD_COMMAND make -j${CPU_CORE} +) + +ADD_LIBRARY(protobuf STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET protobuf PROPERTY IMPORTED_LOCATION ${PROTOBUF_LIBRARY}) +ADD_DEPENDENCIES(protobuf extern_protobuf) diff --git a/cmake/rocksdb.cmake b/cmake/rocksdb.cmake index 47cda8075..05212875b 100644 --- a/cmake/rocksdb.cmake +++ b/cmake/rocksdb.cmake @@ -3,29 +3,46 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE_GUARD() +SET(ROCKSDB_SOURCES_DIR "${LIB_SOURCE_DIR}/extern_rocksdb" CACHE PATH "Path to RocksDB sources") +SET(ROCKSDB_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "rocksdb include directory." FORCE) +SET(ROCKSDB_LIBRARIES "${LIB_INSTALL_DIR}/librocksdb.a" CACHE FILEPATH "rocksdb include directory." FORCE) -FETCHCONTENT_DECLARE( - rocksdb +ExternalProject_Add( + extern_rocksdb + ${EXTERNAL_PROJECT_LOG_ARGS} GIT_REPOSITORY https://github.com/facebook/rocksdb.git GIT_TAG v8.3.3 + DEPENDS + gflags + snappy + zlib + lz4 + zstd + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DWITH_BENCHMARK=OFF + -DWITH_BENCHMARK_TOOLS=OFF + -DWITH_TOOLS=OFF + -DWITH_CORE_TOOLS=OFF + -DWITH_TESTS=OFF + -DWITH_TRACE_TOOLS=OFF + -DWITH_EXAMPLES=OFF + -DROCKSDB_BUILD_SHARED=OFF + -DWITH_JEMALLOC=${JEMALLOC_ON} + -DFAIL_ON_WARNINGS=OFF + -DWITH_LIBURING=OFF + -DWITH_TESTS=OFF + -DWITH_LZ4=ON + -DWITH_SNAPPY=ON + -DWITH_ZLIB=ON + -DWITH_ZSTD=ON + -DWITH_GFLAGS=ON + -DUSE_RTTI=ON + BUILD_COMMAND make -j${CPU_CORE} ) -SET(BUILD_TYPE OFF CACHE BOOL "" FORCE) -SET(WITH_TESTS OFF CACHE BOOL "" FORCE) -SET(WITH_BENCHMARK OFF CACHE BOOL "" FORCE) -SET(WITH_BENCHMARK_TOOLS OFF CACHE BOOL "" FORCE) -SET(WITH_TOOLS OFF CACHE BOOL "" FORCE) -SET(WITH_CORE_TOOLS OFF CACHE BOOL "" FORCE) -SET(WITH_TRACE_TOOLS OFF CACHE BOOL "" FORCE) -SET(WITH_EXAMPLES OFF CACHE BOOL "" FORCE) -SET(ROCKSDB_BUILD_SHARED OFF CACHE BOOL "" FORCE) -SET(WITH_LIBURING OFF CACHE BOOL "" FORCE) -SET(WITH_LZ4 OFF CACHE BOOL "" FORCE) -SET(WITH_SNAPPY OFF CACHE BOOL "" FORCE) -SET(WITH_ZLIB ON CACHE BOOL "" FORCE) -SET(WITH_ZSTD OFF CACHE BOOL "" FORCE) -SET(WITH_GFLAGS OFF CACHE BOOL "" FORCE) -SET(USE_RTTI ON CACHE BOOL "" FORCE) - -FetchContent_MakeAvailable(rocksdb) +ADD_DEPENDENCIES(extern_rocksdb snappy gflags zlib lz4) +ADD_LIBRARY(rocksdb STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET rocksdb PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES}) +ADD_DEPENDENCIES(rocksdb extern_rocksdb) diff --git a/cmake/snappy.cmake b/cmake/snappy.cmake index caf7153f7..a39193612 100644 --- a/cmake/snappy.cmake +++ b/cmake/snappy.cmake @@ -3,45 +3,24 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE(ExternalProject) - -SET(SNAPPY_SOURCES_DIR ${THIRD_PARTY_PATH}/snappy) -SET(SNAPPY_INSTALL_DIR ${THIRD_PARTY_PATH}/install/snappy) -SET(SNAPPY_INCLUDE_DIR "${SNAPPY_INSTALL_DIR}/include" CACHE PATH "snappy include directory." FORCE) -SET(SNAPPY_LIBRARIES "${SNAPPY_INSTALL_DIR}/lib/libsnappy.a" CACHE FILEPATH "snappy library." FORCE) - -SET(prefix_path "${CMAKE_CURRENT_BINARY_DIR}/_deps/gflags-build") +SET(Snappy_SOURCES_DIR ${LIB_INSTALL_PREFIX}) +SET(Snappy_INCLUDE_DIRS "${LIB_INCLUDE_DIR}" CACHE PATH "Snappy include directory." FORCE) +SET(Snappy_LIBRARIES "${LIB_INSTALL_DIR}/libsnappy.a" CACHE FILEPATH "Snappy install directory." FORCE) ExternalProject_Add( extern_snappy ${EXTERNAL_PROJECT_LOG_ARGS} - DEPENDS gflags GIT_REPOSITORY "https://github.com/google/snappy.git" GIT_TAG "1.2.1" - PREFIX ${SNAPPY_SOURCES_DIR} - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} - -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} - -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE} - -DCMAKE_INSTALL_PREFIX=${SNAPPY_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR=${SNAPPY_INSTALL_DIR}/lib - -DCMAKE_POSITION_INDEPENDENT_CODE=ON + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} -DSNAPPY_BUILD_TESTS=OFF - -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} - -DCMAKE_PREFIX_PATH=${prefix_path} - ${EXTERNAL_OPTIONAL_ARGS} - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SNAPPY_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR:PATH=${SNAPPY_INSTALL_DIR}/lib - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} + -DSNAPPY_BUILD_BENCHMARKS=OFF + -DBUILD_STATIC_LIBS=ON + -DBUILD_SHARED_LIBS=OFF ) -ADD_DEPENDENCIES(extern_snappy gflags) ADD_LIBRARY(snappy STATIC IMPORTED GLOBAL) -SET_PROPERTY(TARGET snappy PROPERTY IMPORTED_LOCATION ${SNAPPY_LIBRARIES}) -ADD_DEPENDENCIES(snappy extern_snappy) \ No newline at end of file +SET_PROPERTY(TARGET snappy PROPERTY IMPORTED_LOCATION ${Snappy_LIBRARIES}) +ADD_DEPENDENCIES(snappy extern_snappy) diff --git a/cmake/spdlog.cmake b/cmake/spdlog.cmake index e04a1f050..9b986a76b 100644 --- a/cmake/spdlog.cmake +++ b/cmake/spdlog.cmake @@ -3,13 +3,31 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE_GUARD() +IF (BUILD_TYPE STREQUAL DEBUG) + SET(SPDLOG_LIB "libspdlogd.a") +ELSE () + SET(SPDLOG_LIB "libspdlog.a") +ENDIF () -FetchContent_Declare(spdlog +SET(SPDLOG_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "spdlog include directory." FORCE) +SET(SPDLOG_LIBRARIES "${LIB_INSTALL_DIR}/${SPDLOG_LIB}" CACHE FILEPATH "spdlog library directory." FORCE) + +ADD_DEFINITIONS(-DSPDLOG_FMT_EXTERNAL) + +ExternalProject_Add( + extern_spdlog + ${EXTERNAL_PROJECT_LOG_ARGS} URL https://github.com/gabime/spdlog/archive/v1.12.0.zip URL_HASH SHA256=6174BF8885287422A6C6A0312EB8A30E8D22BCFCEE7C48A6D02D1835D7769232 - ) + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DSPDLOG_BUILD_EXAMPLE=OFF + -DSPDLOG_FMT_EXTERNAL=ON + BUILD_COMMAND make -j${CPU_CORE} +) -SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/spdlog" CACHE STRING "" FORCE) -SET(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(spdlog) +ADD_DEPENDENCIES(extern_spdlog fmt) +ADD_LIBRARY(spdlog STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET spdlog PROPERTY IMPORTED_LOCATION ${SPDLOG_LIBRARIES}) +ADD_DEPENDENCIES(spdlog extern_spdlog) diff --git a/cmake/zlib.cmake b/cmake/zlib.cmake index 79274ae69..5d0551073 100644 --- a/cmake/zlib.cmake +++ b/cmake/zlib.cmake @@ -3,40 +3,21 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -INCLUDE(ExternalProject) - -SET(ZLIB_SOURCES_DIR ${THIRD_PARTY_PATH}/zlib) -SET(ZLIB_INSTALL_DIR ${THIRD_PARTY_PATH}/install/zlib) -# SET(ZLIB_ROOT ${ZLIB_INSTALL_DIR} CACHE FILEPATH "zlib root directory." FORCE) -# SET(ZLIB_INCLUDE_DIR "${ZLIB_INSTALL_DIR}/include" CACHE PATH "zlib include directory." FORCE) +SET(ZLIB_SOURCES_DIR ${LIB_INSTALL_PREFIX}) +SET(ZLIB_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "zlib include directory." FORCE) +SET(ZLIB_LIBRARIES "${LIB_INSTALL_DIR}/libz.a" CACHE FILEPATH "zlib library." FORCE) ExternalProject_Add( extern_zlib ${EXTERNAL_PROJECT_LOG_ARGS} GIT_REPOSITORY "https://github.com/madler/zlib.git" GIT_TAG "v1.2.8" - GIT_SHALLOW true - PREFIX ${ZLIB_SOURCES_DIR} - UPDATE_COMMAND "" - CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_INSTALL_PREFIX=${ZLIB_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR=${ZLIB_INSTALL_DIR}/lib - -DBUILD_SHARED_LIBS=OFF + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_MACOSX_RPATH=ON - -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} - ${EXTERNAL_OPTIONAL_ARGS} - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${ZLIB_INSTALL_DIR} - -DCMAKE_INSTALL_LIBDIR:PATH=${ZLIB_INSTALL_DIR}/lib - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} ) -SET(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/libz.a" CACHE FILEPATH "zlib library." FORCE) - ADD_LIBRARY(zlib STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET zlib PROPERTY IMPORTED_LOCATION ${ZLIB_LIBRARIES}) ADD_DEPENDENCIES(zlib extern_zlib) \ No newline at end of file diff --git a/cmake/zstd.cmake b/cmake/zstd.cmake new file mode 100644 index 000000000..4b87de4e3 --- /dev/null +++ b/cmake/zstd.cmake @@ -0,0 +1,26 @@ +# Copyright (c) 2023-present, Qihoo, Inc. All rights reserved. +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +SET(zstd_INCLUDE_DIRS "${LIB_INCLUDE_DIR}" CACHE PATH "zstd include directory." FORCE) +SET(zstd_LIBRARIES "${LIB_INSTALL_DIR}/libzstd.a" CACHE FILEPATH "zstd include directory." FORCE) + +ExternalProject_Add( + extern_zstd + URL https://github.com/facebook/zstd/releases/download/v1.5.4/zstd-1.5.4.tar.gz + URL_HASH MD5=2352b1f9ccc7446641046bb3d440c3ed + ${EXTERNAL_PROJECT_LOG_ARGS} + SOURCE_SUBDIR build/cmake + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE} + -DBUILD_TESTING=OFF + -DZSTD_BUILD_STATIC=ON + -DZSTD_BUILD_SHARED=OFF + BUILD_COMMAND make -j${CPU_CORE} +) + +ADD_LIBRARY(zstd STATIC IMPORTED GLOBAL) +SET_PROPERTY(TARGET zstd PROPERTY IMPORTED_LOCATION ${zstd_LIBRARIES}) +ADD_DEPENDENCIES(zstd extern_zstd) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc032067a..c559983f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ AUX_SOURCE_DIRECTORY(. PIKIWIDB_SRC) ADD_EXECUTABLE(pikiwidb ${PIKIWIDB_SRC}) -IF(CMAKE_BUILD_TYPE STREQUAL "Release") +IF (CMAKE_BUILD_TYPE STREQUAL "Release") # get current date and time and git commit id EXECUTE_PROCESS(COMMAND date "+%Y-%m-%d_%H:%M:%S" OUTPUT_VARIABLE BUILD_TIMESTAMP OUTPUT_STRIP_TRAILING_WHITESPACE) EXECUTE_PROCESS(COMMAND git rev-parse HEAD OUTPUT_VARIABLE GIT_COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -16,7 +16,7 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Release") MESSAGE(STATUS "Git commit id: ${GIT_COMMIT_ID}") TARGET_COMPILE_DEFINITIONS(pikiwidb PRIVATE KPIKIWIDB_BUILD_DATE="${BUILD_TIMESTAMP}" KPIKIWIDB_GIT_COMMIT_ID="${GIT_COMMIT_ID}") -ENDIF() +ENDIF () SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) @@ -29,8 +29,47 @@ TARGET_INCLUDE_DIRECTORIES(pikiwidb PRIVATE ${rocksdb_SOURCE_DIR}/include PRIVATE ${BRAFT_INCLUDE_DIR} PRIVATE ${BRPC_INCLUDE_DIR} - ) + PRIVATE ${LIBEVENT_INCLUDE_DIRS} +) -TARGET_LINK_LIBRARIES(pikiwidb net; dl; fmt; storage; rocksdb; pstd braft brpc ssl crypto zlib protobuf leveldb gflags z praft praft_pb "${LIB}") +ADD_DEPENDENCIES(pikiwidb + gflags + gtest + fmt + snappy + zlib + rocksdb + protobuf + pstd + braft + brpc + storage +) -SET_TARGET_PROPERTIES(pikiwidb PROPERTIES LINKER_LANGUAGE CXX) \ No newline at end of file +TARGET_LINK_LIBRARIES(pikiwidb + net + dl + fmt + rocksdb + snappy + lz4 + zstd + storage + gflags + spdlog + pstd + braft + brpc + ssl + crypto + zlib + protobuf + leveldb + z + praft + praft_pb + binlog_pb + "${LIB}" +) + +SET_TARGET_PROPERTIES(pikiwidb PROPERTIES LINKER_LANGUAGE CXX) diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt index 8aceed319..a02905859 100644 --- a/src/net/CMakeLists.txt +++ b/src/net/CMakeLists.txt @@ -6,12 +6,20 @@ AUX_SOURCE_DIRECTORY(. NET_SRC) AUX_SOURCE_DIRECTORY(./lzf NET_SRC) LIST(FILTER NET_SRC EXCLUDE REGEX ".*_test.cc") -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) ADD_LIBRARY(net ${NET_SRC}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/pstd) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/net) -TARGET_LINK_LIBRARIES(net; pstd event_extra event_core llhttp::llhttp) +message(STATUS "LIBEVENT_INCLUDE_DIRS: ${LIBEVENT_INCLUDE_DIRS}") +TARGET_INCLUDE_DIRECTORIES(net + PRIVATE ${LIB_INCLUDE_DIR} + PUBLIC ${LIBEVENT_INCLUDE_DIRS} +) + +TARGET_LINK_LIBRARIES(net; pstd event_extra event_core llhttp) SET_TARGET_PROPERTIES(net PROPERTIES LINKER_LANGUAGE CXX) + +ADD_DEPENDENCIES(net pstd) diff --git a/src/praft/CMakeLists.txt b/src/praft/CMakeLists.txt index 45cf62f8c..0e3390359 100644 --- a/src/praft/CMakeLists.txt +++ b/src/praft/CMakeLists.txt @@ -5,28 +5,34 @@ ADD_CUSTOM_COMMAND( OUTPUT "${PROTO_OUTPUT_DIR}/binlog.pb.cc" - DEPENDS extern_protobuf - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + DEPENDS protobuf + COMMAND ${PROTOBUF_PROTOC} ARGS -I ${CMAKE_CURRENT_SOURCE_DIR} --cpp_out ${PROTO_OUTPUT_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/binlog.proto ) ADD_LIBRARY(binlog_pb STATIC "${PROTO_OUTPUT_DIR}/binlog.pb.cc") +SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) +TARGET_INCLUDE_DIRECTORIES(binlog_pb PRIVATE ${PROTOBUF_INCLUDE_DIR}) ADD_CUSTOM_COMMAND( OUTPUT "${PROTO_OUTPUT_DIR}/praft.pb.cc" - DEPENDS extern_protobuf - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + DEPENDS protobuf + COMMAND ${PROTOBUF_PROTOC} ARGS -I ${CMAKE_CURRENT_SOURCE_DIR} --cpp_out ${PROTO_OUTPUT_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/praft.proto ) + ADD_LIBRARY(praft_pb STATIC "${PROTO_OUTPUT_DIR}/praft.pb.cc") +TARGET_INCLUDE_DIRECTORIES(praft_pb PRIVATE ${PROTOBUF_INCLUDE_DIR}) FILE(GLOB PRAFT_SRC - "${CMAKE_CURRENT_SOURCE_DIR}/*.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/*.cc" ) -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) + +SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) + ADD_LIBRARY(praft ${PRAFT_SRC}) TARGET_INCLUDE_DIRECTORIES(praft @@ -37,10 +43,11 @@ TARGET_INCLUDE_DIRECTORIES(praft PRIVATE ${PROTO_OUTPUT_DIR} ) -IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") +IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(PRAFT_LIB ${PRAFT_LIB} rt) -ENDIF() +ENDIF () +SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) +ADD_DEPENDENCIES(praft protobuf praft_pb binlog_pb) TARGET_LINK_LIBRARIES(praft net; dl; fmt; storage; pstd braft brpc ssl crypto zlib protobuf leveldb gflags rocksdb z ${PRAFT_LIB}) - SET_TARGET_PROPERTIES(praft PROPERTIES LINKER_LANGUAGE CXX) diff --git a/src/pstd/CMakeLists.txt b/src/pstd/CMakeLists.txt index 002b84aa8..fb7a41dd8 100644 --- a/src/pstd/CMakeLists.txt +++ b/src/pstd/CMakeLists.txt @@ -4,16 +4,16 @@ # of patent rights can be found in the PATENTS file in the same directory. AUX_SOURCE_DIRECTORY(. STD_SRC) -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) ADD_LIBRARY(pstd ${STD_SRC}) ADD_SUBDIRECTORY(tests) TARGET_INCLUDE_DIRECTORIES(pstd - PRIVATE ${rocksdb_SOURCE_DIR}/include - PRIVATE ${GLOG_INCLUDE_DIR} + PRIVATE ${ROCKSDB_SOURCES_DIR}/include + PRIVATE ${LIB_INCLUDE_DIR} ) TARGET_LINK_LIBRARIES(pstd; spdlog pthread) - SET_TARGET_PROPERTIES(pstd PROPERTIES LINKER_LANGUAGE CXX) +ADD_DEPENDENCIES(pstd rocksdb spdlog) diff --git a/src/pstd/tests/CMakeLists.txt b/src/pstd/tests/CMakeLists.txt index 0320de8a5..e8a50d86b 100644 --- a/src/pstd/tests/CMakeLists.txt +++ b/src/pstd/tests/CMakeLists.txt @@ -20,6 +20,7 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE}) add_executable(${pstd_test_name} ${pstd_test_source}) target_include_directories(${pstd_test_name} PUBLIC ${PROJECT_SOURCE_DIR}/src + PRIVATE ${GTEST_INCLUDE_DIR} ) add_dependencies(${pstd_test_name} pstd gtest) diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index 48773729d..7f727674a 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -7,33 +7,49 @@ FILE(GLOB STORAGE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/storage/*.h" - ) -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) +) +SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) ADD_LIBRARY(storage ${STORAGE_SRC}) TARGET_INCLUDE_DIRECTORIES(storage PUBLIC ${CMAKE_SOURCE_DIR}/src - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${rocksdb_SOURCE_DIR}/ - PRIVATE ${rocksdb_SOURCE_DIR}/include + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${ROCKSDB_SOURCES_DIR} + PRIVATE ${ROCKSDB_SOURCES_DIR}/include PRIVATE ${PROTO_OUTPUT_DIR} + PRIVATE ${PROTOBUF_INCLUDE_DIR} + PRIVATE ${SPDLOG_INCLUDE_DIR} ) -TARGET_LINK_LIBRARIES (storage - pstd - braft - brpc - ssl - crypto - zlib - leveldb - gflags - rocksdb - binlog_pb - protobuf +TARGET_LINK_LIBRARIES(storage + pstd + braft + brpc + ssl + crypto + zlib + leveldb + gflags + rocksdb + protobuf + spdlog ) SET_TARGET_PROPERTIES(storage PROPERTIES LINKER_LANGUAGE CXX) ADD_SUBDIRECTORY(tests) + +ADD_DEPENDENCIES(storage + pstd + braft + brpc + ssl + crypto + zlib + leveldb + gflags + rocksdb + protobuf + spdlog +) diff --git a/src/storage/tests/CMakeLists.txt b/src/storage/tests/CMakeLists.txt index 2c8f258f5..e4366b0eb 100644 --- a/src/storage/tests/CMakeLists.txt +++ b/src/storage/tests/CMakeLists.txt @@ -8,23 +8,33 @@ INCLUDE(GoogleTest) FILE(GLOB_RECURSE TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*test.cc") FOREACH (TEST_SOURCE ${TEST_SOURCES}) - GET_FILENAME_COMPONENT(TEST_FILENAME ${TEST_SOURCE} NAME) - STRING(REPLACE ".cc" "" TEST_NAME ${TEST_FILENAME}) + GET_FILENAME_COMPONENT(TEST_FILENAME ${TEST_SOURCE} NAME) + STRING(REPLACE ".cc" "" TEST_NAME ${TEST_FILENAME}) - ADD_EXECUTABLE(${TEST_NAME} ${TEST_SOURCE}) + ADD_EXECUTABLE(${TEST_NAME} ${TEST_SOURCE}) - TARGET_INCLUDE_DIRECTORIES(${TEST_NAME} - PUBLIC storage - PRIVATE ${rocksdb_SOURCE_DIR} - PRIVATE ${rocksdb_SOURCE_DIR}/include - PRIVATE ${BRAFT_INCLUDE_DIR} - PRIVATE ${BRPC_INCLUDE_DIR} - ) - TARGET_LINK_LIBRARIES(${TEST_NAME} - PUBLIC storage - PRIVATE gtest - PRIVATE gtest_main - PRIVATE fmt - ${LIB} - ) -ENDFOREACH() + TARGET_INCLUDE_DIRECTORIES(${TEST_NAME} + PUBLIC storage + PRIVATE ${ROCKSDB_SOURCES_DIR} + PRIVATE ${ROCKSDB_SOURCES_DIR}/include + PRIVATE ${BRAFT_INCLUDE_DIR} + PRIVATE ${BRPC_INCLUDE_DIR} + PRIVATE ${PROTOBUF_INCLUDE_DIR} + PRIVATE ${PROTO_OUTPUT_DIR} + PRIVATE ${GTEST_INCLUDE_DIR} + ) + + TARGET_LINK_LIBRARIES(${TEST_NAME} + PUBLIC storage + PRIVATE gtest + PRIVATE gtest_main + PRIVATE fmt + PRIVATE spdlog + PRIVATE pstd + PRIVATE rocksdb + PRIVATE snappy + PRIVATE lz4 + PRIVATE zstd + PRIVATE binlog_pb + ) +ENDFOREACH ()