-
Notifications
You must be signed in to change notification settings - Fork 447
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
[VL] Add find and build glog/gflags #3638
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
include_guard(GLOBAL) | ||
|
||
set(GLUTEN_GFLAGS_BUILD_SHA256_CHECKSUM | ||
34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf) | ||
string(CONCAT GLUTEN_GFLAGS_SOURCE_URL | ||
"https://github.com/gflags/gflags/archive/refs/tags/" | ||
"v${GLUTEN_GFLAGS_VERSION}.tar.gz") | ||
|
||
message(STATUS "Building gflags from source") | ||
FetchContent_Declare( | ||
gflags | ||
URL ${GLUTEN_GFLAGS_SOURCE_URL} | ||
URL_HASH SHA256=${GLUTEN_GFLAGS_BUILD_SHA256_CHECKSUM}) | ||
|
||
set(GFLAGS_BUILD_STATIC_LIBS ON) | ||
set(GFLAGS_BUILD_SHARED_LIBS ON) | ||
set(GFLAGS_BUILD_gflags_LIB ON) | ||
# glog relies on the old `google` namespace | ||
set(GFLAGS_NAMESPACE "google;gflags") | ||
|
||
FetchContent_MakeAvailable(gflags) | ||
|
||
# the flag has to be added to each target we build so adjust to settings choosen | ||
# above | ||
target_compile_options(gflags_static PRIVATE -Wno-cast-function-type) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
include_guard(GLOBAL) | ||
|
||
set(GLUTEN_GLOG_BUILD_SHA256_CHECKSUM | ||
8a83bf982f37bb70825df71a9709fa90ea9f4447fb3c099e1d720a439d88bad6) | ||
set(GLUTEN_GLOG_SOURCE_URL | ||
"https://github.com/google/glog/archive/refs/tags/v${GLUTEN_GLOG_VERSION}.tar.gz" | ||
) | ||
|
||
message(STATUS "Building glog from source") | ||
FetchContent_Declare( | ||
glog | ||
URL ${GLUTEN_GLOG_SOURCE_URL} | ||
URL_HASH SHA256=${GLUTEN_GLOG_BUILD_SHA256_CHECKSUM} | ||
PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/glog/glog-no-export.patch | ||
&& git apply ${CMAKE_CURRENT_LIST_DIR}/glog/glog-config.patch) | ||
|
||
set(BUILD_SHARED_LIBS OFF) | ||
set(WITH_UNWIND OFF) | ||
set(BUILD_TESTING OFF) | ||
FetchContent_MakeAvailable(glog) | ||
unset(BUILD_TESTING) | ||
unset(BUILD_SHARED_LIBS) | ||
|
||
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/glog) | ||
set(GLOG_INCLUDE_DIR ${glog_BINARY_DIR}) | ||
string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPERCASE_BUILD_TYPE) | ||
if(UPPERCASE_BUILD_TYPE MATCHES "DEBUG") | ||
set(GLOG_LIBRARY "${glog_BINARY_DIR}/libglogd.a") | ||
else() | ||
set(GLOG_LIBRARY "${glog_BINARY_DIR}/libglog.a") | ||
endif() | ||
|
||
# These headers are missing from the include dir but adding the src dir causes | ||
# issues with folly so we just copy it to the include dir | ||
file(COPY ${glog_SOURCE_DIR}/src/glog/platform.h | ||
DESTINATION ${glog_BINARY_DIR}/glog) | ||
file(COPY ${glog_SOURCE_DIR}/src/glog/log_severity.h | ||
DESTINATION ${glog_BINARY_DIR}/glog) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,81 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# - Try to find Glog | ||
# Once done, this will define | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# GLOG_FOUND - system has Glog | ||
# GLOG_INCLUDE_DIRS - the Glog include directories | ||
# GLOG_LIBRARIES - link these to use Glog | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set(GLUTEN_GLOG_MINIMUM_VERSION 0.4.0) | ||
set(GLUTEN_GLOG_VERSION 0.6.0) | ||
|
||
if(NOT BUILD_GLOG) | ||
include(FindPackageHandleStandardArgs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious could we just find first, then check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit tricky here. We cannot make sure user has both glog and gflags installed. If glog is found but gflags is missing, it fails. The option is for ignoring system glog then directly build glog and gflags from source. https://github.com/oap-project/gluten/pull/3638/files#diff-9df362ebf18ceb320fa6423ff9140fd2bd75906d57d92ca018febfc3a93864a9R66 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'm fine with it. |
||
include(SelectLibraryConfigurations) | ||
|
||
find_library(GLOG_LIBRARY_RELEASE glog | ||
PATHS ${GLOG_LIBRARYDIR}) | ||
find_library(GLOG_LIBRARY_DEBUG glogd | ||
PATHS ${GLOG_LIBRARYDIR}) | ||
|
||
find_path(GLOG_INCLUDE_DIR glog/logging.h | ||
PATHS ${GLOG_INCLUDEDIR}) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
include(SelectLibraryConfigurations) | ||
select_library_configurations(GLOG) | ||
|
||
find_library(GLOG_LIBRARY_RELEASE glog | ||
PATHS ${GLOG_LIBRARYDIR}) | ||
find_library(GLOG_LIBRARY_DEBUG glogd | ||
PATHS ${GLOG_LIBRARYDIR}) | ||
find_package_handle_standard_args(glog DEFAULT_MSG | ||
GLOG_LIBRARY | ||
GLOG_INCLUDE_DIR) | ||
|
||
find_path(GLOG_INCLUDE_DIR glog/logging.h | ||
PATHS ${GLOG_INCLUDEDIR}) | ||
mark_as_advanced( | ||
GLOG_LIBRARY | ||
GLOG_INCLUDE_DIR) | ||
endif() | ||
|
||
select_library_configurations(GLOG) | ||
if(NOT glog_FOUND) | ||
include(BuildGlog) | ||
endif() | ||
|
||
find_package_handle_standard_args(glog DEFAULT_MSG | ||
GLOG_LIBRARY | ||
GLOG_INCLUDE_DIR) | ||
get_filename_component(libglog_ext ${GLOG_LIBRARY} EXT) | ||
if(libglog_ext STREQUAL ".a") | ||
set(libglog_type STATIC) | ||
set(libgflags_component static) | ||
else() | ||
set(libglog_type SHARED) | ||
set(libgflags_component shared) | ||
endif() | ||
|
||
mark_as_advanced( | ||
GLOG_LIBRARY | ||
GLOG_INCLUDE_DIR) | ||
# glog::glog may already exist. Use google::glog to avoid conflicts. | ||
add_library(google::glog ${libglog_type} IMPORTED) | ||
set_target_properties(google::glog PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIR}") | ||
set_target_properties(google::glog PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${GLOG_LIBRARY}") | ||
|
||
set(GLOG_LIBRARIES ${GLOG_LIBRARY}) | ||
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) | ||
set(GLUTEN_GFLAGS_VERSION 2.2.2) | ||
find_package(gflags ${GLUTEN_GFLAGS_VERSION} CONFIG COMPONENTS ${libgflags_component}) | ||
|
||
if(NOT gflags_FOUND AND glog_FOUND) | ||
message(FATAL_ERROR "Glog found but Gflags not found. Set BUILD_GLOG=ON and reload cmake.") | ||
endif() | ||
|
||
if (NOT TARGET glog::glog) | ||
add_library(glog::glog UNKNOWN IMPORTED) | ||
set_target_properties(glog::glog PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIRS}") | ||
set_target_properties(glog::glog PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${GLOG_LIBRARIES}") | ||
if(gflags_FOUND) | ||
if(NOT TARGET gflags::gflags_${libgflags_component} AND NOT TARGET gflags_${libgflags_component}) | ||
message(FATAL_ERROR "Found Gflags but missing component gflags_${libgflags_component}") | ||
endif() | ||
if(TARGET gflags::gflags_${libgflags_component}) | ||
set_target_properties(google::glog PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES gflags::gflags_${libgflags_component}) | ||
else() | ||
set_target_properties(google::glog PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES gflags_${libgflags_component}) | ||
endif() | ||
else() | ||
include(BuildGflags) | ||
set_target_properties(google::glog PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES gflags_static) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--- a/glog-config.cmake.in | ||
+++ b/glog-config.cmake.in | ||
@@ -10,4 +10,3 @@ include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake) | ||
@gflags_DEPENDENCY@ | ||
@Unwind_DEPENDENCY@ | ||
|
||
-include (${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -1025,7 +1025,7 @@ write_basic_package_version_file ( | ||
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake | ||
COMPATIBILITY SameMajorVersion) | ||
|
||
-export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) | ||
+# export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) | ||
export (PACKAGE glog) | ||
|
||
get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE) | ||
@@ -1076,5 +1076,5 @@ install (DIRECTORY ${_glog_BINARY_CMake_DATADIR} | ||
FILES_MATCHING PATTERN "*.cmake" | ||
) | ||
|
||
-install (EXPORT glog-targets NAMESPACE glog:: DESTINATION | ||
- ${_glog_CMake_INSTALLDIR}) | ||
+# install (EXPORT glog-targets NAMESPACE glog:: DESTINATION | ||
+# ${_glog_CMake_INSTALLDIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use below pattern to allow user specify deps URL? same for glog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this patch first, I will refine these deps download URL in follow up patch.