-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VL] Add find and build glog/gflags to cmake (#3638)
- Loading branch information
Showing
9 changed files
with
220 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters