Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: support build glog/gflags from source #3778

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "cmake-modules"]
path = cmake-modules
url = https://github.com/bilke/cmake-modules.git
[submodule "glog"]
path = contrib/glog
url = https://github.com/google/glog
[submodule "gflags"]
path = contrib/gflags
url = https://github.com/gflags/gflags
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

find_library(GLOG_LIBRARY glog)
find_library(GFLAGS_LIBRARY gflags)
find_library(UNWIND_LIBRARY unwind)
find_library(LEVELDB_LIBRARY leveldb)
find_library(Z_LIBRARY z)
Expand All @@ -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})
Expand Down
10 changes: 9 additions & 1 deletion contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function(add_contrib cmake_folder)

file(GLOB contrib_files "${base_folder}/*")
if (NOT contrib_files)
message(FATAL_ERROR "submodule ${base_folder} is missing or empty.")
message(STATUS "submodule contrib/${base_folder} is missing or empty, update submodule manully ...")
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${CMAKE_SOURCE_DIR}/contrib/${base_folder}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endforeach()

Expand All @@ -26,3 +30,7 @@ endfunction()

add_contrib(simdjson)

if (BUILD_SHARED_LIBS)
add_contrib(gflags-cmake gflags)
add_contrib(glog-cmake glog)
endif()
1 change: 1 addition & 0 deletions contrib/gflags
Submodule gflags added at e171aa
12 changes: 12 additions & 0 deletions contrib/gflags-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions contrib/glog
Submodule glog added at b33e3b
10 changes: 10 additions & 0 deletions contrib/glog-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(WITH_GTEST OFF)
set(WITH_GFLAGS ON)
set(WITH_UNWIND ON)

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)
27 changes: 27 additions & 0 deletions contrib/glog-cmake/find-gflags.patch
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 0 additions & 3 deletions hybridse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

find_library(GLOG_LIBRARY glog)
find_library(GFLAGS_LIBRARY gflags)
find_library(UNWIND_LIBRARY unwind)
find_library(LEVELDB_LIBRARY leveldb)
find_library(Z_LIBRARY z)
Expand Down
2 changes: 1 addition & 1 deletion hybridse/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down
5 changes: 5 additions & 0 deletions src/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading