From 2f71a096c1a0f75a0bcdd6e42a8986bb68af58bf Mon Sep 17 00:00:00 2001 From: yangchuan Date: Thu, 9 Nov 2023 10:12:40 +0800 Subject: [PATCH] fix --- cpp/CMake/BuildGTest.cmake | 4 +-- cpp/CMake/BuildGflags.cmake | 2 ++ cpp/CMake/BuildGlog.cmake | 2 ++ cpp/CMake/BuildGoogleBenchmark.cmake | 6 ++-- cpp/CMake/ResolveDependency.cmake | 44 ++++++++++++++++++++++++++++ cpp/CMake/Simdjson.cmake | 27 ----------------- cpp/CMakeLists.txt | 2 ++ 7 files changed, 53 insertions(+), 34 deletions(-) create mode 100755 cpp/CMake/ResolveDependency.cmake diff --git a/cpp/CMake/BuildGTest.cmake b/cpp/CMake/BuildGTest.cmake index 96b4657ae986..7318b7bd7081 100644 --- a/cpp/CMake/BuildGTest.cmake +++ b/cpp/CMake/BuildGTest.cmake @@ -8,9 +8,7 @@ set(GLUTEN_GTEST_SOURCE_URL "https://github.com/google/googletest/archive/refs/tags/v${GLUTEN_GTEST_VERSION}.tar.gz" ) -if(DEFINED ENV{GLUTEN_GTEST_SOURCE_URL}) - set(GLUTEN_GTEST_SOURCE_URL "$ENV{GLUTEN_GTEST_SOURCE_URL}") -endif() +resolve_dependency_url(GTEST) message(STATUS "Building gtest from source") FetchContent_Declare( diff --git a/cpp/CMake/BuildGflags.cmake b/cpp/CMake/BuildGflags.cmake index f383fbbced77..4cb201115835 100644 --- a/cpp/CMake/BuildGflags.cmake +++ b/cpp/CMake/BuildGflags.cmake @@ -22,6 +22,8 @@ string(CONCAT GLUTEN_GFLAGS_SOURCE_URL "https://github.com/gflags/gflags/archive/refs/tags/" "v${GLUTEN_GFLAGS_VERSION}.tar.gz") +resolve_dependency_url(GFLAGS) + message(STATUS "Building gflags from source") FetchContent_Declare( gflags diff --git a/cpp/CMake/BuildGlog.cmake b/cpp/CMake/BuildGlog.cmake index 35742fb6e627..cf405225c313 100644 --- a/cpp/CMake/BuildGlog.cmake +++ b/cpp/CMake/BuildGlog.cmake @@ -19,6 +19,8 @@ set(GLUTEN_GLOG_SOURCE_URL "https://github.com/google/glog/archive/refs/tags/v${GLUTEN_GLOG_VERSION}.tar.gz" ) +resolve_dependency_url(GLOG) + message(STATUS "Building glog from source") FetchContent_Declare( glog diff --git a/cpp/CMake/BuildGoogleBenchmark.cmake b/cpp/CMake/BuildGoogleBenchmark.cmake index 3a5af880a00a..8efbb58eab74 100644 --- a/cpp/CMake/BuildGoogleBenchmark.cmake +++ b/cpp/CMake/BuildGoogleBenchmark.cmake @@ -24,9 +24,7 @@ set(GLUTEN_GBENCHMARK_SOURCE_URL "https://github.com/ursa-labs/thirdparty/releases/download/latest/gbenchmark-${GLUTEN_GBENCHMARK_BUILD_VERSION}.tar.gz") set(GLUTEN_GBENCHMARK_BUILD_SHA256_CHECKSUM "1f71c72ce08d2c1310011ea6436b31e39ccab8c2db94186d26657d41747c85d6") -if(DEFINED ENV{GLUTEN_GBENCHMARK_SOURCE_URL}) - set(GLUTEN_GBENCHMARK_SOURCE_URL "$ENV{GLUTEN_GBENCHMARK_SOURCE_URL}") -endif() +resolve_dependency_url(GBENCHMARK) set(GBENCHMARK_CMAKE_ARGS "-fPIC -w") @@ -34,7 +32,7 @@ message(STATUS "Building google benchmark from source") FetchContent_Declare( gbenchmark URL ${GLUTEN_GBENCHMARK_SOURCE_URL} - URL_HASH "SHA256=${GLUTEN_GBENCHMARK_BUILD_SHA256_CHECKSUM}" + URL_HASH "${GLUTEN_GBENCHMARK_BUILD_SHA256_CHECKSUM}" ) if (NOT gbenchmark_POPULATED) diff --git a/cpp/CMake/ResolveDependency.cmake b/cpp/CMake/ResolveDependency.cmake new file mode 100755 index 000000000000..2f44af607ccd --- /dev/null +++ b/cpp/CMake/ResolveDependency.cmake @@ -0,0 +1,44 @@ +# 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. + +function(set_with_default var_name envvar_name default) + if(DEFINED ENV{${envvar_name}}) + set(${var_name} + $ENV{${envvar_name}} + PARENT_SCOPE) + else() + set(${var_name} + ${default} + PARENT_SCOPE) + endif() +endfunction() + +macro(resolve_dependency_url dependency_name) + # Prepend prefix for default checksum. + string(PREPEND GLUTEN_${dependency_name}_BUILD_SHA256_CHECKSUM "SHA256=") + + set_with_default( + GLUTEN_${dependency_name}_SOURCE_URL GLUTEN_${dependency_name}_URL + ${GLUTEN_${dependency_name}_SOURCE_URL}) + if(DEFINED ENV{GLUTEN_${dependency_name}_URL}) + set_with_default(GLUTEN_${dependency_name}_BUILD_SHA256_CHECKSUM + GLUTEN_${dependency_name}_SHA256 "") + if(DEFINED ENV{GLUTEN_${dependency_name}_SHA256}) + string(PREPEND GLUTEN_${dependency_name}_BUILD_SHA256_CHECKSUM "SHA256=") + endif() + endif() +endmacro() diff --git a/cpp/CMake/Simdjson.cmake b/cpp/CMake/Simdjson.cmake index 414bd9a7ecb3..f78090e7eed2 100755 --- a/cpp/CMake/Simdjson.cmake +++ b/cpp/CMake/Simdjson.cmake @@ -17,33 +17,6 @@ include_guard(GLOBAL) include(FetchContent) -function(set_with_default var_name envvar_name default) - if(DEFINED ENV{${envvar_name}}) - set(${var_name} - $ENV{${envvar_name}} - PARENT_SCOPE) - else() - set(${var_name} - ${default} - PARENT_SCOPE) - endif() -endfunction() - -macro(resolve_dependency_url dependency_name) - # Prepend prefix for default checksum. - string(PREPEND GLUTEN_${dependency_name}_BUILD_SHA256_CHECKSUM "SHA256=") - - set_with_default( - GLUTEN_${dependency_name}_SOURCE_URL GLUTEN_${dependency_name}_URL - ${GLUTEN_${dependency_name}_SOURCE_URL}) - if(DEFINED ENV{GLUTEN_${dependency_name}_URL}) - set_with_default(GLUTEN_${dependency_name}_BUILD_SHA256_CHECKSUM - GLUTEN_${dependency_name}_SHA256 "") - if(DEFINED ENV{GLUTEN_${dependency_name}_SHA256}) - string(PREPEND GLUTEN_${dependency_name}_BUILD_SHA256_CHECKSUM "SHA256=") - endif() - endif() -endmacro() set(GLUTEN_SIMDJSON_VERSION 3.1.5) set(GLUTEN_SIMDJSON_BUILD_SHA256_CHECKSUM diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 2db5d10605e8..e4f66c86f8fa 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -66,6 +66,8 @@ else() set(ARROW_HOME ${VELOX_HOME}/_build/release/third_party/arrow_ep) endif() +include(ResolveDependency) + # # Compiler flags #