@@ -200,6 +200,7 @@ ExternalProject_Add(gflags
200200 -DGFLAGS_NAMESPACE=gflags
201201 -DBUILD_STATIC_LIBS=ON
202202 -DBUILD_SHARED_LIBS=OFF
203+ -DREGISTER_INSTALL_PREFIX=OFF
203204 BUILD_COMMAND
204205 make -j${CPU_CORE}
205206)
@@ -273,10 +274,10 @@ ExternalProject_Add(glog
273274 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
274275 -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
275276 -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
276- -DWITH_GFLAGS=ON
277+ -DWITH_GFLAGS=OFF
277278 -DBUILD_TESTING=OFF
278279 -DBUILD_SHARED_LIBS=OFF
279- -DWITH_UNWIND=${LIBUNWIND_ON}
280+ -DWITH_UNWIND=OFF
280281 -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
281282 BUILD_COMMAND
282283 make -j${CPU_CORE}
@@ -457,9 +458,9 @@ set(LZ4_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
457458ExternalProject_Add(zlib
458459 DEPENDS
459460 URL
460- https://github.com/madler/zlib/releases/download/v1.2.13 /zlib-1.2.13 .tar.gz
461+ https://github.com/madler/zlib/releases/download/v1.3.1 /zlib-1.3.1 .tar.gz
461462 URL_HASH
462- MD5=9b8aa094c4e5765dabf4da391f00d15c
463+ MD5=9855b6d802d7fe5b7bd5b196a2271655
463464 DOWNLOAD_NO_PROGRESS
464465 1
465466 UPDATE_COMMAND
@@ -543,7 +544,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
543544 BUILD_ALWAYS
544545 1
545546 INSTALL_COMMAND
546- make install
547+ make -j1 install
547548 )
548549
549550 set (JEMALLOC_LIBRARY ${INSTALL_LIBDIR} /libjemalloc.a)
@@ -595,9 +596,155 @@ else()
595596endif ()
596597
597598set (PROTOBUF_INCLUDE_DIR ${INSTALL_INCLUDEDIR} )
598- set (PROTOBUF_LIBRARY ${INSTALL_LIBDIR} /${LIB_PROTOBUF} )
599+ if (${OS_VERSION} MATCHES "Rocky" OR ${OS_VERSION} MATCHES "CentOS" )
600+ set (PROTOBUF_LIBRARY ${INSTALL_LIBDIR_64} /${LIB_PROTOBUF} )
601+ else ()
602+ set (PROTOBUF_LIBRARY ${INSTALL_LIBDIR} /${LIB_PROTOBUF} )
603+ endif ()
599604set (PROTOBUF_PROTOC ${STAGED_INSTALL_PREFIX} /bin/protoc)
600605
606+ ExternalProject_Add(leveldb
607+ DEPENDS
608+ snappy
609+ URL
610+ https://github.com/google/leveldb/archive/refs/tags/1.23.tar.gz
611+ URL_HASH
612+ MD5=afbde776fb8760312009963f09a586c7
613+ DOWNLOAD_NO_PROGRESS
614+ 1
615+ UPDATE_COMMAND
616+ ""
617+ LOG_CONFIGURE
618+ 1
619+ LOG_BUILD
620+ 1
621+ LOG_INSTALL
622+ 1
623+ CMAKE_ARGS
624+ -DCMAKE_POLICY_VERSION_MINIMUM=3.5
625+ -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
626+ -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
627+ -DLEVELDB_BUILD_TESTS=OFF
628+ -DLEVELDB_BUILD_BENCHMARKS=OFF
629+ -DBUILD_SHARED_LIBS=OFF
630+ -DHAVE_SNAPPY=ON
631+ -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
632+ -DCMAKE_CXX_FLAGS=-I${INSTALL_INCLUDEDIR}
633+ -DCMAKE_EXE_LINKER_FLAGS=-L${INSTALL_LIBDIR} \ -L${INSTALL_LIBDIR_64}
634+ -DCMAKE_SHARED_LINKER_FLAGS=-L${INSTALL_LIBDIR} \ -L${INSTALL_LIBDIR_64}
635+ -DCMAKE_MODULE_LINKER_FLAGS=-L${INSTALL_LIBDIR} \ -L${INSTALL_LIBDIR_64}
636+ BUILD_ALWAYS
637+ 1
638+ BUILD_COMMAND
639+ make -j${CPU_CORE}
640+ )
641+
642+ if (${OS_VERSION} MATCHES "Rocky" OR ${OS_VERSION} MATCHES "CentOS" )
643+ set (LEVELDB_LIBRARY ${INSTALL_LIBDIR_64} /libleveldb.a)
644+ else ()
645+ set (LEVELDB_LIBRARY ${INSTALL_LIBDIR} /libleveldb.a)
646+ endif ()
647+ set (LEVELDB_INCLUDE_DIR ${INSTALL_INCLUDEDIR} )
648+
649+ ExternalProject_Add(brpc
650+ DEPENDS
651+ gflags
652+ protobuf
653+ leveldb
654+ glog
655+ snappy
656+ zlib
657+ URL
658+ https://github.com/apache/brpc/archive/refs/tags/1.6.0.tar.gz
659+ URL_HASH
660+ MD5=0d37cea25bd006e89806f461ef7e39ba
661+ DOWNLOAD_NO_PROGRESS
662+ 1
663+ UPDATE_COMMAND
664+ ""
665+ LOG_CONFIGURE
666+ 1
667+ LOG_BUILD
668+ 1
669+ LOG_INSTALL
670+ 1
671+ CMAKE_ARGS
672+ -DCMAKE_POLICY_VERSION_MINIMUM=3.5
673+ -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
674+ -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
675+ -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
676+ -DWITH_GLOG=ON
677+ -DWITH_SNAPPY=ON
678+ -DBUILD_SHARED_LIBS=OFF
679+ -DDOWNLOAD_GTEST=OFF
680+ BUILD_ALWAYS
681+ 1
682+ BUILD_COMMAND
683+ make -j${CPU_CORE}
684+ )
685+
686+ if (${OS_VERSION} MATCHES "Rocky" OR ${OS_VERSION} MATCHES "CentOS" )
687+ set (BRPC_LIBRARY ${INSTALL_LIBDIR_64} /libbrpc.a)
688+ else ()
689+ set (BRPC_LIBRARY ${INSTALL_LIBDIR} /libbrpc.a)
690+ endif ()
691+ set (BRPC_INCLUDE_DIR ${INSTALL_INCLUDEDIR} )
692+
693+ ExternalProject_Add(braft
694+ DEPENDS
695+ gflags
696+ protobuf
697+ leveldb
698+ brpc
699+ glog
700+ snappy
701+ zlib
702+ URL
703+ https://github.com/baidu/braft/archive/refs/tags/v1.1.2.tar.gz
704+ URL_HASH
705+ MD5=f1d0307cf45449bbec9b64ca81b5f808
706+ DOWNLOAD_NO_PROGRESS
707+ 1
708+ UPDATE_COMMAND
709+ ""
710+ LOG_CONFIGURE
711+ 1
712+ LOG_BUILD
713+ 1
714+ LOG_INSTALL
715+ 1
716+ CMAKE_ARGS
717+ -DCMAKE_POLICY_VERSION_MINIMUM=3.5
718+ -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}
719+ -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
720+ -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
721+ -DWITH_GLOG=ON
722+ -DBUILD_SHARED_LIBS=OFF
723+ -DBUILD_UNIT_TESTS=OFF
724+ -DDOWNLOAD_GTEST=OFF
725+ BUILD_ALWAYS
726+ 1
727+ BUILD_COMMAND
728+ make -j${CPU_CORE} braft-static
729+ INSTALL_COMMAND
730+ ${CMAKE_COMMAND} -E copy_directory <BINARY_DIR>/output /include /braft ${INSTALL_INCLUDEDIR} /braft
731+ COMMAND ${CMAKE_COMMAND} -E copy <BINARY_DIR>/output /lib/libbraft.a ${INSTALL_LIBDIR} /libbraft.a
732+ )
733+
734+ # For CentOS/Rocky, also copy to lib64
735+ if (${OS_VERSION} MATCHES "Rocky" OR ${OS_VERSION} MATCHES "CentOS" )
736+ ExternalProject_Add_Step(braft copy_to_lib64
737+ COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALL_LIBDIR_64}
738+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INSTALL_LIBDIR} /libbraft.a ${INSTALL_LIBDIR_64} /libbraft.a
739+ DEPENDEES install
740+ COMMENT "Copying braft to lib64 for CentOS/Rocky"
741+ )
742+ set (BRAFT_LIBRARY ${INSTALL_LIBDIR_64} /libbraft.a)
743+ else ()
744+ set (BRAFT_LIBRARY ${INSTALL_LIBDIR} /libbraft.a)
745+ endif ()
746+ set (BRAFT_INCLUDE_DIR ${INSTALL_INCLUDEDIR} )
747+
601748ExternalProject_Add(rocksdb
602749 DEPENDS
603750 gflags
@@ -750,8 +897,21 @@ endif()
750897set (ROCKSDB_INCLUDE_DIR ${INSTALL_INCLUDEDIR} )
751898set (ROCKSDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /${EP_BASE_SUFFIX} /Source /rocksdb)
752899
900+ # Generate protobuf files before compiling praft (which depends on them)
901+ set (PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR} /src/pika_inner_message.proto ${CMAKE_CURRENT_SOURCE_DIR} /src/rsync_service.proto)
902+ custom_protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES} )
903+ message ("pika PROTO_SRCS = ${PROTO_SRCS} " )
904+ message ("pika PROTO_HDRS = ${PROTO_HDRS} " )
905+
906+ # Create a custom target for generated proto files
907+ add_custom_target (pika_proto_gen
908+ DEPENDS ${PROTO_SRCS} ${PROTO_HDRS} protobuf
909+ COMMENT "Generating Pika protobuf files"
910+ )
911+
753912add_subdirectory (src/pstd)
754913add_subdirectory (src/net)
914+ add_subdirectory (src/praft) # praft 必须在 storage 之前,因为 storage 需要 binlog.pb.h
755915add_subdirectory (src/storage)
756916add_subdirectory (src/cache )
757917if (USE_PIKA_TOOLS)
@@ -794,10 +954,7 @@ set(PIKA_BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/pika_build_version.cc
794954message ("PIKA_BUILD_VERSION_CC : " ${PIKA_BUILD_VERSION_CC} )
795955configure_file (${CMAKE_CURRENT_SOURCE_DIR} /src/build_version.cc.in ${PIKA_BUILD_VERSION_CC} @ONLY)
796956
797- set (PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR} /src/pika_inner_message.proto ${CMAKE_CURRENT_SOURCE_DIR} /src/rsync_service.proto)
798- custom_protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES} )
799- message ("pika PROTO_SRCS = ${PROTO_SRCS} " )
800- message ("pika PROTO_HDRS = ${PROTO_HDRS} " )
957+ # PROTO_SRCS and PROTO_HDRS are already generated above
801958
802959add_executable (${PROJECT_NAME}
803960 ${DIR_SRCS}
@@ -821,6 +978,9 @@ add_dependencies(${PROJECT_NAME}
821978 zlib
822979 ${LIBGPERF_NAME}
823980 ${LIBJEMALLOC_NAME}
981+ leveldb
982+ brpc
983+ braft
824984 rocksdb
825985 protobuf
826986 pstd
@@ -839,10 +999,14 @@ target_include_directories(${PROJECT_NAME}
839999target_link_libraries (${PROJECT_NAME}
8401000 cache
8411001 storage
1002+ praft
8421003 net
8431004 pstd
8441005 ${GLOG_LIBRARY}
8451006 librocksdb.a
1007+ ${BRAFT_LIBRARY}
1008+ ${BRPC_LIBRARY}
1009+ ${LEVELDB_LIBRARY}
8461010 ${LIB_PROTOBUF}
8471011 ${LIB_GFLAGS}
8481012 ${LIB_FMT}
@@ -854,6 +1018,49 @@ target_link_libraries(${PROJECT_NAME}
8541018 ${LIBUNWIND_LIBRARY}
8551019 ${JEMALLOC_LIBRARY} )
8561020
1021+ # Add platform-specific libraries for brpc and braft
1022+ if (CMAKE_SYSTEM_NAME MATCHES "Darwin" )
1023+ # macOS frameworks
1024+ target_link_libraries (${PROJECT_NAME}
1025+ "-framework CoreFoundation"
1026+ "-framework CoreGraphics"
1027+ "-framework CoreData"
1028+ "-framework CoreText"
1029+ "-framework Security"
1030+ "-framework Foundation"
1031+ "-framework ApplicationServices"
1032+ "-framework SystemConfiguration"
1033+ "-framework AppKit"
1034+ "-Wl,-undefined,dynamic_lookup" # Allow undefined symbols (gperftools optional)
1035+ )
1036+ find_library (OPENSSL_CRYPTO_LIBRARY NAMES crypto libcrypto)
1037+ find_library (OPENSSL_SSL_LIBRARY NAMES ssl libssl)
1038+ if (OPENSSL_CRYPTO_LIBRARY)
1039+ target_link_libraries (${PROJECT_NAME} ${OPENSSL_CRYPTO_LIBRARY} )
1040+ endif ()
1041+ if (OPENSSL_SSL_LIBRARY)
1042+ target_link_libraries (${PROJECT_NAME} ${OPENSSL_SSL_LIBRARY} )
1043+ endif ()
1044+ elseif (CMAKE_SYSTEM_NAME MATCHES "Linux" )
1045+ # Linux system libraries for brpc and braft
1046+ target_link_libraries (${PROJECT_NAME}
1047+ rt # Real-time extensions
1048+ dl # Dynamic linking
1049+ )
1050+ # Find and link OpenSSL for Linux
1051+ find_package (OpenSSL)
1052+ if (OPENSSL_FOUND)
1053+ target_link_libraries (${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
1054+ else ()
1055+ # Fallback: try to find libraries directly
1056+ find_library (OPENSSL_CRYPTO_LIBRARY NAMES crypto libcrypto)
1057+ find_library (OPENSSL_SSL_LIBRARY NAMES ssl libssl)
1058+ if (OPENSSL_CRYPTO_LIBRARY AND OPENSSL_SSL_LIBRARY)
1059+ target_link_libraries (${PROJECT_NAME} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} )
1060+ endif ()
1061+ endif ()
1062+ endif ()
1063+
8571064option (USE_SSL "Enable SSL support" OFF )
8581065add_custom_target (
8591066 clang-tidy
0 commit comments