From bad950136dcdfd431ef9ccdb8331b19d5213493b Mon Sep 17 00:00:00 2001 From: Adonis Ling Date: Thu, 27 Oct 2022 15:18:28 +0800 Subject: [PATCH] [chore](build) Pass the compile flag -Wno-unused-but-set-variable on demand (#13716) There are some issues with the compile flag `-Wno-unused-but-set-variable` for clang. 1. `-Wno-unused-but-set-variable` should be set when building source by clang-15 on Linux. (#13000 #13016) 2. On macOS Monterey, Apple Clang 13 may treat it as a unknown warning option and the compilation process may interrupt. This PR introduces a better way to make this compile flag more portable. 1. Test whether the compiler recognizes this flag. 2. Add this flag if the compiler recognizes it. --- be/src/geo/CMakeLists.txt | 8 ++++++-- be/src/util/simd/vstring_function.h | 1 + thirdparty/build-thirdparty.sh | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/be/src/geo/CMakeLists.txt b/be/src/geo/CMakeLists.txt index d802a2bedb..0caa937a8d 100644 --- a/be/src/geo/CMakeLists.txt +++ b/be/src/geo/CMakeLists.txt @@ -29,8 +29,12 @@ add_library(Geo STATIC ${GENSRC_DIR}/geo/wkt_lex.l.cpp ${GENSRC_DIR}/geo/wkt_yacc.y.cpp ) -if (COMPILER_GCC OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "14.0.0") - target_compile_options(Geo PRIVATE -Wno-unused-but-set-variable) + +include(CheckCXXCompilerFlag) +set(WARNING_OPTION "-Wno-unused-but-set-variable") +check_cxx_compiler_flag(${WARNING_OPTION} HAS_WARNING_OPTION) +if (HAS_WARNING_OPTION) + target_compile_options(Geo PRIVATE ${WARNING_OPTION}) endif() add_custom_command( diff --git a/be/src/util/simd/vstring_function.h b/be/src/util/simd/vstring_function.h index 0e8c3d075e..f17768cf89 100644 --- a/be/src/util/simd/vstring_function.h +++ b/be/src/util/simd/vstring_function.h @@ -19,6 +19,7 @@ #include +#include #include #ifdef __aarch64__ diff --git a/thirdparty/build-thirdparty.sh b/thirdparty/build-thirdparty.sh index e404757a2b..a45c5af2dd 100755 --- a/thirdparty/build-thirdparty.sh +++ b/thirdparty/build-thirdparty.sh @@ -146,8 +146,8 @@ elif [[ "${CC}" == *clang ]]; then warning_option_ignored='-Wno-option-ignored' boost_toolset='clang' libhdfs_cxx17='-std=c++1z' - clang_version="$("${CC}" -dumpversion)" - if [[ "${clang_version}" < '14.0.0' ]]; then + + if "${CC}" -xc++ "${warning_unused_but_set_variable}" /dev/null 2>&1 | grep 'unknown warning option'; then warning_unused_but_set_variable='' fi fi