diff --git a/cpp/CMake/BuildGflags.cmake b/cpp/CMake/BuildGflags.cmake new file mode 100644 index 000000000000..f383fbbced77 --- /dev/null +++ b/cpp/CMake/BuildGflags.cmake @@ -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) diff --git a/cpp/CMake/BuildGlog.cmake b/cpp/CMake/BuildGlog.cmake new file mode 100644 index 000000000000..35742fb6e627 --- /dev/null +++ b/cpp/CMake/BuildGlog.cmake @@ -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) diff --git a/cpp/CMake/Findglog.cmake b/cpp/CMake/Findglog.cmake index 752647cb3357..b165fd80f3d7 100644 --- a/cpp/CMake/Findglog.cmake +++ b/cpp/CMake/Findglog.cmake @@ -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() diff --git a/cpp/CMake/glog/glog-config.patch b/cpp/CMake/glog/glog-config.patch new file mode 100644 index 000000000000..4851461fc83b --- /dev/null +++ b/cpp/CMake/glog/glog-config.patch @@ -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) diff --git a/cpp/CMake/glog/glog-no-export.patch b/cpp/CMake/glog/glog-no-export.patch new file mode 100644 index 000000000000..1ae4ce7cbd19 --- /dev/null +++ b/cpp/CMake/glog/glog-no-export.patch @@ -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}) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 99ca3867de9a..c2227fcc45b9 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -43,6 +43,7 @@ option(BUILD_EXAMPLES "Build Examples" OFF) option(BUILD_BENCHMARKS "Build Benchmarks" OFF) option(BUILD_PROTOBUF "Build Protobuf from Source" OFF) option(BUILD_JEMALLOC "Build Jemalloc from Source" OFF) +option(BUILD_GLOG "Build Glog from Source" OFF) option(USE_AVX512 "Build with AVX-512 optimizations" OFF) option(ENABLE_HBM "Enable HBM allocator" OFF) option(ENABLE_QAT "Enable QAT for de/compression" OFF) @@ -130,7 +131,6 @@ if(BUILD_TESTS) endif() include(GoogleTest) enable_testing() - find_package(glog REQUIRED) endif() function(ADD_TEST_CASE TEST_NAME) @@ -179,6 +179,7 @@ if(BUILD_TESTS OR BUILD_BENCHMARKS) if(NOT benchmark_FOUND) include(BuildGoogleBenchmark) endif() + find_package(glog REQUIRED) endif() if(ENABLE_QAT) diff --git a/cpp/velox/CMakeLists.txt b/cpp/velox/CMakeLists.txt index ece87e6b5675..3472a58f61bf 100644 --- a/cpp/velox/CMakeLists.txt +++ b/cpp/velox/CMakeLists.txt @@ -309,12 +309,6 @@ set_target_properties(velox PROPERTIES ## It is also applicable to other dependencies. find_package(Folly REQUIRED CONFIG) -if(ENABLE_GLUTEN_VCPKG) - find_package(gflags REQUIRED COMPONENTS static CONFIG) -else() - find_package(gflags REQUIRED COMPONENTS shared CONFIG) -endif() - target_include_directories(velox PUBLIC ${GTEST_INCLUDE_DIRS} ${PROTOBUF_INCLUDE}) diff --git a/cpp/velox/benchmarks/CMakeLists.txt b/cpp/velox/benchmarks/CMakeLists.txt index bc1782337754..5e6f222bd9f3 100644 --- a/cpp/velox/benchmarks/CMakeLists.txt +++ b/cpp/velox/benchmarks/CMakeLists.txt @@ -18,7 +18,7 @@ find_arrow_lib(${PARQUET_LIB_NAME}) set(VELOX_BENCHMARK_COMMON_SRCS common/FileReaderIterator.cc common/BenchmarkUtils.cc) add_library(velox_benchmark_common STATIC ${VELOX_BENCHMARK_COMMON_SRCS}) target_include_directories(velox_benchmark_common PUBLIC ${CMAKE_SOURCE_DIR}/velox ${CMAKE_SOURCE_DIR}/core) -target_link_libraries(velox_benchmark_common PUBLIC Arrow::parquet velox benchmark::benchmark gflags simdjson) +target_link_libraries(velox_benchmark_common PUBLIC Arrow::parquet velox benchmark::benchmark google::glog simdjson) function(add_velox_benchmark BM_EXEC BM_FILE) add_executable(${BM_EXEC} ${BM_FILE}) diff --git a/cpp/velox/tests/CMakeLists.txt b/cpp/velox/tests/CMakeLists.txt index 1bccc5d09f31..c2d412a56b0b 100644 --- a/cpp/velox/tests/CMakeLists.txt +++ b/cpp/velox/tests/CMakeLists.txt @@ -32,7 +32,7 @@ function(add_velox_test TEST_EXEC) endif() add_executable(${TEST_EXEC} ${SOURCES}) target_include_directories(${TEST_EXEC} PRIVATE ${CMAKE_SOURCE_DIR}/velox ${CMAKE_SOURCE_DIR}/src) - target_link_libraries(${TEST_EXEC} gflags velox GTest::gtest GTest::gtest_main glog::glog benchmark::benchmark simdjson) + target_link_libraries(${TEST_EXEC} velox GTest::gtest GTest::gtest_main google::glog benchmark::benchmark simdjson) gtest_discover_tests(${TEST_EXEC} DISCOVERY_MODE PRE_TEST) endfunction()