From a4a51af5894b6b97c914a96d3a69e2b74e159d75 Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Thu, 28 Sep 2023 00:38:29 +0800 Subject: [PATCH] fix compile --- CMakeLists.txt | 7 +++---- example/http_c++/CMakeLists.txt | 34 ++++++++++++++++----------------- src/brpc/details/ssl_helper.cpp | 2 +- src/butil/iobuf.cpp | 4 +++- src/butil/ssl_compat.h | 2 +- test/CMakeLists.txt | 5 +---- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3fbaae860..5c06c9616b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,13 +128,13 @@ set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing macro(use_cxx11) if(CMAKE_VERSION VERSION_LESS "3.1.3") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() else() - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() endmacro(use_cxx11) @@ -241,7 +241,6 @@ if(WITH_BORINGSSL) list(APPEND DYNAMIC_LIB ${BORINGSSL_CRYPTO_LIBRARY}) else() list(APPEND DYNAMIC_LIB ${OPENSSL_CRYPTO_LIBRARY}) - if(WITH_MESALINK) list(APPEND DYNAMIC_LIB ${MESALINK_LIB}) else() diff --git a/example/http_c++/CMakeLists.txt b/example/http_c++/CMakeLists.txt index 4b56c80e78..34f3050fa8 100644 --- a/example/http_c++/CMakeLists.txt +++ b/example/http_c++/CMakeLists.txt @@ -39,11 +39,14 @@ find_library(THRIFT_LIB NAMES thrift) if (NOT THRIFT_LIB) set(THRIFT_LIB "") endif() +find_library(THRIFTNB_LIB NAMES thriftnb) +if (NOT THRIFTNB_LIB) + set(THRIFTNB_LIB "") +endif() -find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h PATHS /home/gperftools/src) -find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler PATHS /home/gperftools/build) +find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h) +find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler) include_directories(${GPERFTOOLS_INCLUDE_DIR}) -message("---- ${GPERFTOOLS_LIBRARIES}") find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h) if(LINK_SO) @@ -88,13 +91,13 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER") if(CMAKE_VERSION VERSION_LESS "3.1.3") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() else() - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() @@ -105,19 +108,13 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB)) endif() include_directories(${LEVELDB_INCLUDE_PATH}) -#if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") -# set(OPENSSL_ROOT_DIR -# "/usr/local/opt/openssl" # Homebrew installed OpenSSL -# ) -#endif() - -#find_package(OpenSSL) - - -set(OPENSSL_INCLUDE_DIR /home/boringssl/include) -find_library(OPENSSL_CRYPTO_LIBRARY NAMES libcrypto.a PATHS /home/boringssl/build/crypto) -find_library(OPENSSL_SSL_LIBRARY NAMES libssl.a PATHS /home/boringssl/build/ssl) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(OPENSSL_ROOT_DIR + "/usr/local/opt/openssl" # Homebrew installed OpenSSL + ) +endif() +find_package(OpenSSL) include_directories(${OPENSSL_INCLUDE_DIR}) @@ -129,6 +126,7 @@ set(DYNAMIC_LIB ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} ${THRIFT_LIB} + ${THRIFTNB_LIB} dl ) diff --git a/src/brpc/details/ssl_helper.cpp b/src/brpc/details/ssl_helper.cpp index 16e3ab67ce..a02752614c 100644 --- a/src/brpc/details/ssl_helper.cpp +++ b/src/brpc/details/ssl_helper.cpp @@ -592,7 +592,7 @@ SSL* CreateSSLSession(SSL_CTX* ctx, SocketId id, int fd, bool server_mode) { } void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { -#if OPENSSL_IS_BORINGSSL +#if defined(OPENSSL_IS_BORINGSSL) BIO *rbio = BIO_new(BIO_s_mem()); BIO *wbio = BIO_new(BIO_s_mem()); #else diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp index 06b1efbe67..e439526606 100644 --- a/src/butil/iobuf.cpp +++ b/src/butil/iobuf.cpp @@ -38,7 +38,9 @@ #include "butil/fd_guard.h" // butil::fd_guard #include "butil/iobuf.h" +#if defined (OPENSSL_IS_BORINGSSL) #include "butil/ssl_compat.h" // BIO_fd_non_fatal_error +#endif namespace butil { namespace iobuf { @@ -2153,7 +2155,7 @@ bool IOBufBytesIterator::forward_one_block(const void** data, size_t* size) { return true; } -} // namespace butil +} // namespace butil void* fast_memcpy(void *__restrict dest, const void *__restrict src, size_t n) { return butil::iobuf::cp(dest, src, n); diff --git a/src/butil/ssl_compat.h b/src/butil/ssl_compat.h index ce361a20b5..a42c0b4ee2 100644 --- a/src/butil/ssl_compat.h +++ b/src/butil/ssl_compat.h @@ -519,7 +519,7 @@ BRPC_INLINE int EVP_PKEY_base_id(const EVP_PKEY *pkey) { #endif /* OPENSSL_VERSION_NUMBER < 0x0090801fL || OPENSSL_IS_BORINGSSL */ #if defined(OPENSSL_IS_BORINGSSL) -[[maybe_unused]] static int BIO_fd_non_fatal_error(int err) { +BRPC_INLINE int BIO_fd_non_fatal_error(int err) { if ( #ifdef EWOULDBLOCK err == EWOULDBLOCK || diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 149541df9c..9720a0fabe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,10 +15,7 @@ # specific language governing permissions and limitations # under the License. -find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h PATHS /home/gperftools/src) -find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler PATHS /home/gperftools/build) -include_directories(${GPERFTOOLS_INCLUDE_DIR}) - +find_package(Gperftools) include_directories(${GPERFTOOLS_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})