diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ae6d4dbab5b..2e44ddc5328 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -42,7 +42,6 @@ jobs: NPROC: 2 BUILD_SHARED_LIBS: ON TESTING_ENABLE_STRIP: ON - THIRD_PARTY_DIR: ${{ github.workspace }} steps: - uses: actions/checkout@v4 with: @@ -60,20 +59,6 @@ jobs: run: | sudo make install - - name: download glog - uses: actions/checkout@v4 - with: - repository: google/glog - ref: v0.6.0 - path: glog - - - name: install glog - working-directory: glog - run: | - cmake -S . -B build -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=${{ env.THIRD_PARTY_DIR }} -DCMAKE_BUILD_TYPE=RelWithDebInfo - cmake --build build - cmake --build build --target install - - name: coverage configure run: | make coverage-configure diff --git a/CMakeLists.txt b/CMakeLists.txt index 34b9e68756b..111e3df503b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,14 +121,11 @@ find_package(SWIG REQUIRED) include(UseSWIG) find_package(OpenSSL REQUIRED) -find_library(BRPC_LIBRARY brpc) set(Protobuf_USE_STATIC_LIBS ON) find_package(Protobuf 3.6 EXACT REQUIRED) message(STATUS "Found Protobuf Libraries: ${Protobuf_LIBRARIES}") -set(GLOG_LIBRARY glog::glog) -find_library(GFLAGS_LIBRARY gflags) find_library(UNWIND_LIBRARY unwind) find_library(LEVELDB_LIBRARY leveldb) find_library(Z_LIBRARY z) @@ -151,6 +148,26 @@ include(rapidjson) # contrib libs add_subdirectory(contrib EXCLUDE_FROM_ALL) +if (BUILD_SHARED_LIBS) + # For shared build, gflags/glog requires shared lib, + # in case runtime problem arrise from java, a common issue is #3407: + # > ERROR: something wrong with flag 'logtostderr' in file 'src/logging.cc'. One possibility: file 'src/logging.cc' is being linked both statically and dynamically into this executable. + set(GLOG_LIBRARY glog::glog) + get_target_property(gflags_real gflags::gflags ALIASED_TARGET) + message(STATUS "link with gflags library: ${gflags_real}") + set(GFLAGS_LIBRARY gflags::gflags) +else() + # 'CONFIG' is mandatory: pre-compiled thirdparty skip a Findgflags.cmake not work well + find_package(gflags REQUIRED COMPONENTS static CONFIG) + set(GFLAGS_LIBRARY ${gflags_LIBRARIES}) + + find_library(GLOG_LIBRARY NAMES libglog.a REQUIRED) +endif() + +find_library(BRPC_LIBRARY NAMES libbrpc.a REQUIRED) +message(STATUS "Found GFLAGS LIBRARY: ${GFLAGS_LIBRARY}") +message(STATUS "Found GLOG LIBRARY: ${GLOG_LIBRARY}") + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") set(OS_LIB ${CMAKE_THREAD_LIBS_INIT} rt) set(BRPC_LIBS ${BRPC_LIBRARY} ${Protobuf_LIBRARIES} ${GLOG_LIBRARY} ${GFLAGS_LIBRARY} ${UNWIND_LIBRARY} ${OPENSSL_LIBRARIES} ${LEVELDB_LIBRARY} ${Z_LIBRARY} ${SNAPPY_LIBRARY} dl pthread ${OS_LIB}) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index b9e23a4ba58..197a341ba87 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -20,9 +20,13 @@ function(add_contrib cmake_folder) endif() endforeach() - message(STATUS "Adding contrib module ${base_folders} (configuring with ${cmake_folder})") + message(STATUS "Adding contrib module ${base_folders} (configuring with ${cmake_folder}). to fix try run: git submodule update --init") add_subdirectory (${cmake_folder}) endfunction() add_contrib(simdjson) -add_contrib(glog-cmake glog) + +if (BUILD_SHARED_LIBS) + add_contrib(gflags-cmake gflags) + add_contrib(glog-cmake glog) +endif() diff --git a/contrib/gflags b/contrib/gflags index a738fdf9338..e171aa2d15e 160000 --- a/contrib/gflags +++ b/contrib/gflags @@ -1 +1 @@ -Subproject commit a738fdf9338412f83ab3f26f31ac11ed3f3ec4bd +Subproject commit e171aa2d15ed9eb17054558e0b3a6a413bb01067 diff --git a/contrib/gflags-cmake/CMakeLists.txt b/contrib/gflags-cmake/CMakeLists.txt new file mode 100644 index 00000000000..201fe42bfb4 --- /dev/null +++ b/contrib/gflags-cmake/CMakeLists.txt @@ -0,0 +1,12 @@ +# parent project use gflags::gflags alias, so build either shared or static +if (BUILD_SHARED_LIBS) + set(GFLAGS_BUILD_SHARED_LIBS ON) + set(GFLAGS_BUILD_STATIC_LIBS OFF) +else() + set(GFLAGS_BUILD_SHARED_LIBS OFF) + set(GFLAGS_BUILD_STATIC_LIBS ON) +endif() + +set(GFLAGS_NAMESPACE google) + +add_subdirectory(${CMAKE_SOURCE_DIR}/contrib/gflags ${CMAKE_BINARY_DIR}/contrib/gflags) diff --git a/contrib/glog-cmake/CMakeLists.txt b/contrib/glog-cmake/CMakeLists.txt index 5588a8f3dbd..4c9e6abbd5f 100644 --- a/contrib/glog-cmake/CMakeLists.txt +++ b/contrib/glog-cmake/CMakeLists.txt @@ -1,10 +1,10 @@ set(WITH_GTEST OFF) +set(WITH_GFLAGS ON) +set(WITH_UNWIND ON) -if (BUILD_SHARED_LIBS) - # visibility issue building shared glog against static gflags - # so explicitly skip the gflags dependency - set(WITH_GFLAGS OFF) - set(WITH_UNWIND OFF) -endif() +execute_process( + COMMAND patch -p 1 -N -i ${CMAKE_SOURCE_DIR}/contrib/glog-cmake/find-gflags.patch + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/contrib/glog +) add_subdirectory(${CMAKE_SOURCE_DIR}/contrib/glog ${CMAKE_BINARY_DIR}/contrib/glog) diff --git a/contrib/glog-cmake/find-gflags.patch b/contrib/glog-cmake/find-gflags.patch new file mode 100644 index 00000000000..e9674c55089 --- /dev/null +++ b/contrib/glog-cmake/find-gflags.patch @@ -0,0 +1,27 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 846b444..50c0c07 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -79,12 +79,16 @@ if (WITH_GMOCK AND TARGET GTest::gmock) + endif (WITH_GMOCK AND TARGET GTest::gmock) + + if (WITH_GFLAGS) +- find_package (gflags 2.2.2) +- +- if (gflags_FOUND) +- set (HAVE_LIB_GFLAGS 1) +- determine_gflags_namespace (gflags_NAMESPACE) +- endif (gflags_FOUND) ++ if (NOT TARGET gflags::gflags) ++ find_package (gflags 2.2.2) ++ ++ if (gflags_FOUND) ++ set (HAVE_LIB_GFLAGS 1) ++ determine_gflags_namespace (gflags_NAMESPACE) ++ endif (gflags_FOUND) ++ else() ++ set(gflags_NAMESPACE google) ++ endif() + endif (WITH_GFLAGS) + + find_package (Threads) diff --git a/hybridse/CMakeLists.txt b/hybridse/CMakeLists.txt index dca1ca52d0d..3e5e3b3c100 100644 --- a/hybridse/CMakeLists.txt +++ b/hybridse/CMakeLists.txt @@ -85,14 +85,11 @@ set(Boost_NO_BOOST_CMAKE ON) set(BOOST_ROOT "${CMAKE_PREFIX_PATH}") find_package(Boost COMPONENTS filesystem date_time regex REQUIRED) find_package(OpenSSL REQUIRED) -find_library(BRPC_LIBRARY brpc) set(Protobuf_USE_STATIC_LIBS ON) find_package(Protobuf 3.6 EXACT REQUIRED) message(STATUS "Found Protobuf Libraries: ${Protobuf_LIBRARIES}") -set(GLOG_LIBRARY glog::glog) -find_library(GFLAGS_LIBRARY gflags) find_library(UNWIND_LIBRARY unwind) find_library(LEVELDB_LIBRARY leveldb) find_library(Z_LIBRARY z) diff --git a/hybridse/src/CMakeLists.txt b/hybridse/src/CMakeLists.txt index 643a6dea739..80c5cc2a5a3 100644 --- a/hybridse/src/CMakeLists.txt +++ b/hybridse/src/CMakeLists.txt @@ -58,7 +58,7 @@ if (LLVM_EXT_ENABLE) add_definitions(-DLLVM_EXT_ENABLE) endif () -add_library(hybridse_flags STATIC ${CMAKE_CURRENT_SOURCE_DIR}/flags.cc) +add_library(hybridse_flags ${CMAKE_CURRENT_SOURCE_DIR}/flags.cc) target_link_libraries(hybridse_flags ${GFLAGS_LIBRARY}) # hybridse core library, enable BUILD_SHARED_LIBS to build shared lib diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5c5e642122..dfd9d589c9f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -122,7 +122,7 @@ set_property( PROPERTY ADDITIONAL_CLEAN_FILES ${PROTO_FILES} ) -add_library(openmldb_flags STATIC flags.cc) +add_library(openmldb_flags flags.cc) compile_lib(openmldb_codec codec "") compile_lib(openmldb_catalog catalog "") diff --git a/src/sdk/CMakeLists.txt b/src/sdk/CMakeLists.txt index 680066a2513..77fe59a58a2 100644 --- a/src/sdk/CMakeLists.txt +++ b/src/sdk/CMakeLists.txt @@ -231,6 +231,11 @@ if (APPLE) message(STATUS "skip c++ sdk build on macos") return() endif() +if (BUILD_SHARED_LIBS) + message(STATUS "skip c++ sdk when BUILD_SHARED_LIBS ON") + return() +endif() + add_library(openmldb_api STATIC openmldb_api.cc) target_include_directories ( diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index a210ad2545f..483d3f51128 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -138,10 +138,6 @@ if (BUILD_BUNDLED_GFLAGS) include(FetchGflags) endif() -if (BUILD_BUNDLED_LIBUNWIND) - include(FetchLibunwind) -endif() - if (BUILD_BUNDLED_GLOG) include(FetchGlog) endif() @@ -182,6 +178,10 @@ if (BUILD_BUNDLED_LEVELDB) include(FetchLeveldb) endif() +if (BUILD_BUNDLED_LIBUNWIND) + include(FetchLibunwind) +endif() + if (BUILD_BUNDLED_SQLITE3) include(FetchSqlite3) endif() diff --git a/third-party/cmake/FetchGlog.cmake b/third-party/cmake/FetchGlog.cmake index ffd73ecc88e..458d5052268 100644 --- a/third-party/cmake/FetchGlog.cmake +++ b/third-party/cmake/FetchGlog.cmake @@ -24,7 +24,8 @@ ExternalProject_Add( PREFIX ${DEPS_BUILD_DIR} DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/glog INSTALL_DIR ${DEPS_INSTALL_DIR} - DEPENDS gflags libunwind + DEPENDS gflags + BUILD_IN_SOURCE TRUE CONFIGURE_COMMAND ${CMAKE_COMMAND} -H -B -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_SHARED_LIBS=OFF -DCMAKE_PREFIX_PATH= -DCMAKE_INSTALL_PREFIX= BUILD_COMMAND ${CMAKE_COMMAND} --build -- ${MAKEOPTS} diff --git a/third-party/cmake/FetchLibunwind.cmake b/third-party/cmake/FetchLibunwind.cmake index 4779ab66aaf..f50b377bae2 100644 --- a/third-party/cmake/FetchLibunwind.cmake +++ b/third-party/cmake/FetchLibunwind.cmake @@ -33,6 +33,6 @@ ExternalProject_Add( INSTALL_DIR ${DEPS_INSTALL_DIR} BUILD_IN_SOURCE True PATCH_COMMAND ${LIBUNWIND_PATCH} - CONFIGURE_COMMAND bash -c "${CONFIGURE_OPTS} ./configure --prefix= --enable-shared=no --enable-minidebuginfo=no" + CONFIGURE_COMMAND bash -c "${CONFIGURE_OPTS} ./configure --prefix= --enable-shared=no" BUILD_COMMAND ${MAKE_EXE} ${MAKEOPTS} INSTALL_COMMAND ${MAKE_EXE} install)