Skip to content

Commit 4feae05

Browse files
authored
Remove some try_compile CMake checks for compiler flags (#92953)
This patch remove 36 checks for compiler flags that are done via invoking the compiler across LLVM, Clang, and LLDB. It's was made possible by raising the bar for supported compilers that has been happening over the years since the checks were added. This is going to improve CMake configuration times. This topic was highlighted in https://discourse.llvm.org/t/cmake-compiler-flag-checks-are-really-slow-ideas-to-speed-them-up/78882.
1 parent 32c3561 commit 4feae05

File tree

6 files changed

+89
-121
lines changed

6 files changed

+89
-121
lines changed

clang/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,7 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
349349
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
350350
endif ()
351351

352-
check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
353-
if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
354-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
355-
endif()
352+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
356353
endif ()
357354

358355
# Determine HOST_LINK_VERSION on Darwin.

clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ project(exec C)
22

33
cmake_minimum_required(VERSION 3.20.0)
44

5-
include(CheckCCompilerFlag)
6-
check_c_compiler_flag("-std=c99" C99_SUPPORTED)
7-
if (C99_SUPPORTED)
8-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
9-
endif()
5+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
106

117
include(CheckFunctionExists)
128
include(CheckSymbolExists)

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,18 @@ include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
187187
# form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
188188

189189
# Disable GCC warnings
190-
check_cxx_compiler_flag("-Wdeprecated-declarations" CXX_SUPPORTS_DEPRECATED_DECLARATIONS)
191-
append_if(CXX_SUPPORTS_DEPRECATED_DECLARATIONS "-Wno-deprecated-declarations" CMAKE_CXX_FLAGS)
192-
193-
check_cxx_compiler_flag("-Wunknown-pragmas" CXX_SUPPORTS_UNKNOWN_PRAGMAS)
194-
append_if(CXX_SUPPORTS_UNKNOWN_PRAGMAS "-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
195-
196-
check_cxx_compiler_flag("-Wstrict-aliasing" CXX_SUPPORTS_STRICT_ALIASING)
197-
append_if(CXX_SUPPORTS_STRICT_ALIASING "-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
190+
append("-Wno-deprecated-declarations" CMAKE_CXX_FLAGS)
191+
append("-Wno-unknown-pragmas" CMAKE_CXX_FLAGS)
192+
append("-Wno-strict-aliasing" CMAKE_CXX_FLAGS)
198193

199194
check_cxx_compiler_flag("-Wstringop-truncation" CXX_SUPPORTS_STRINGOP_TRUNCATION)
200195
append_if(CXX_SUPPORTS_STRINGOP_TRUNCATION "-Wno-stringop-truncation" CMAKE_CXX_FLAGS)
201196

202197
# Disable Clang warnings
203-
check_cxx_compiler_flag("-Wdeprecated-register" CXX_SUPPORTS_DEPRECATED_REGISTER)
204-
append_if(CXX_SUPPORTS_DEPRECATED_REGISTER "-Wno-deprecated-register" CMAKE_CXX_FLAGS)
205-
206-
check_cxx_compiler_flag("-Wvla-extension" CXX_SUPPORTS_VLA_EXTENSION)
207-
append_if(CXX_SUPPORTS_VLA_EXTENSION "-Wno-vla-extension" CMAKE_CXX_FLAGS)
198+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
199+
append("-Wno-deprecated-register" CMAKE_CXX_FLAGS)
200+
append("-Wno-vla-extension" CMAKE_CXX_FLAGS)
201+
endif()
208202

209203
# Disable MSVC warnings
210204
if( MSVC )

llvm/cmake/config-ix.cmake

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,18 @@ if( LLVM_ENABLE_PIC )
415415
set(ENABLE_PIC 1)
416416
else()
417417
set(ENABLE_PIC 0)
418-
check_cxx_compiler_flag("-fno-pie" SUPPORTS_NO_PIE_FLAG)
419-
if(SUPPORTS_NO_PIE_FLAG)
420-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
421-
endif()
418+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
422419
endif()
423420

424-
check_cxx_compiler_flag("-Wvariadic-macros" SUPPORTS_VARIADIC_MACROS_FLAG)
425-
check_cxx_compiler_flag("-Wgnu-zero-variadic-macro-arguments"
426-
SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
421+
set(SUPPORTS_VARIADIC_MACROS_FLAG 0)
422+
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
423+
set(SUPPORTS_VARIADIC_MACROS_FLAG 1)
424+
endif()
425+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
426+
set(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG 1)
427+
else()
428+
set(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG 0)
429+
endif()
427430

428431
set(USE_NO_MAYBE_UNINITIALIZED 0)
429432
set(USE_NO_UNINITIALIZED 0)
@@ -433,11 +436,9 @@ set(USE_NO_UNINITIALIZED 0)
433436
if (CMAKE_COMPILER_IS_GNUCXX)
434437
# Disable all -Wuninitialized warning for old GCC versions.
435438
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0)
436-
check_cxx_compiler_flag("-Wuninitialized" HAS_UNINITIALIZED)
437-
set(USE_NO_UNINITIALIZED ${HAS_UNINITIALIZED})
439+
set(USE_NO_UNINITIALIZED 1)
438440
else()
439-
check_cxx_compiler_flag("-Wmaybe-uninitialized" HAS_MAYBE_UNINITIALIZED)
440-
set(USE_NO_MAYBE_UNINITIALIZED ${HAS_MAYBE_UNINITIALIZED})
441+
set(USE_NO_MAYBE_UNINITIALIZED 1)
441442
endif()
442443
endif()
443444

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
260260

261261
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
262262
include(CheckLinkerFlag)
263-
# Linkers that support Darwin allow a setting to internalize all symbol exports,
263+
# Linkers that support Darwin allow a setting to internalize all symbol exports,
264264
# aiding in reducing binary size and often is applicable for executables.
265265
check_linker_flag(C "-Wl,-no_exported_symbols" LLVM_LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS)
266-
267-
if (NOT LLVM_USE_LINKER)
266+
267+
if (NOT LLVM_USE_LINKER)
268268
# Apple's linker complains about duplicate libraries, which CMake likes to do
269269
# to support ELF platforms. To silence that warning, we can use
270270
# -no_warn_duplicate_libraries, but only in versions of the linker that
@@ -273,8 +273,8 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
273273
else()
274274
set(LLVM_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES OFF CACHE INTERNAL "")
275275
endif()
276-
277-
else()
276+
277+
else()
278278
set(LLVM_LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS OFF CACHE INTERNAL "")
279279
endif()
280280
endif()
@@ -1038,7 +1038,7 @@ macro(add_llvm_executable name)
10381038
add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
10391039
endif(LLVM_EXPORTED_SYMBOL_FILE)
10401040

1041-
if (DEFINED LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES AND
1041+
if (DEFINED LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES AND
10421042
NOT LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES)
10431043
if(LLVM_LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS)
10441044
set_property(TARGET ${name} APPEND_STRING PROPERTY
@@ -1641,7 +1641,7 @@ function(add_unittest test_suite test_name)
16411641

16421642
if (SUPPORTS_VARIADIC_MACROS_FLAG)
16431643
list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
1644-
endif ()
1644+
endif()
16451645
# Some parts of gtest rely on this GNU extension, don't warn on it.
16461646
if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
16471647
list(APPEND LLVM_COMPILE_FLAGS "-Wno-gnu-zero-variadic-macro-arguments")

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 61 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ if( LLVM_ENABLE_PIC )
425425
# GCC for MIPS can miscompile LLVM due to PR37701.
426426
if(CMAKE_COMPILER_IS_GNUCXX AND LLVM_NATIVE_ARCH STREQUAL "Mips" AND
427427
NOT Uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
428-
add_flag_or_print_warning("-fno-shrink-wrap" FNO_SHRINK_WRAP)
428+
append("-fno-shrink-wrap" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
429429
endif()
430430
# gcc with -O3 -fPIC generates TLS sequences that violate the spec on
431431
# Solaris/sparcv9, causing executables created with the system linker
@@ -635,18 +635,16 @@ if( MSVC )
635635
# This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag()
636636
# because cl.exe does not emit an error on flags it doesn't understand,
637637
# letting check_cxx_compiler_flag() claim it understands all flags.
638-
check_cxx_compiler_flag("/Brepro" SUPPORTS_BREPRO)
639-
if (SUPPORTS_BREPRO)
640-
# Check if /INCREMENTAL is passed to the linker and complain that it
641-
# won't work with /Brepro.
642-
has_msvc_incremental_no_flag("${CMAKE_EXE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_EXE_LINKER_FLAGS}" NO_INCR_EXE)
643-
has_msvc_incremental_no_flag("${CMAKE_MODULE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_MODULE_LINKER_FLAGS}" NO_INCR_MODULE)
644-
has_msvc_incremental_no_flag("${CMAKE_SHARED_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_SHARED_LINKER_FLAGS}" NO_INCR_SHARED)
645-
if (NO_INCR_EXE AND NO_INCR_MODULE AND NO_INCR_SHARED)
646-
append("/Brepro" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
647-
else()
648-
message(WARNING "/Brepro not compatible with /INCREMENTAL linking - builds will be non-deterministic")
649-
endif()
638+
639+
# Check if /INCREMENTAL is passed to the linker and complain that it
640+
# won't work with /Brepro.
641+
has_msvc_incremental_no_flag("${CMAKE_EXE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_EXE_LINKER_FLAGS}" NO_INCR_EXE)
642+
has_msvc_incremental_no_flag("${CMAKE_MODULE_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_MODULE_LINKER_FLAGS}" NO_INCR_MODULE)
643+
has_msvc_incremental_no_flag("${CMAKE_SHARED_LINKER_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${CMAKE_SHARED_LINKER_FLAGS}" NO_INCR_SHARED)
644+
if (NO_INCR_EXE AND NO_INCR_MODULE AND NO_INCR_SHARED)
645+
append("/Brepro" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
646+
else()
647+
message(WARNING "/Brepro not compatible with /INCREMENTAL linking - builds will be non-deterministic")
650648
endif()
651649
endif()
652650
# By default MSVC has a 2^16 limit on the number of sections in an object file,
@@ -667,19 +665,22 @@ endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
667665

668666
# Specific default warnings-as-errors for compilers accepting GCC-compatible warning flags:
669667
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
670-
add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME)
671-
add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW)
668+
append("-Werror=date-time" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
672669
endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
673670

674-
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
671+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
672+
append("-Werror=unguarded-availability-new" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
673+
endif()
674+
675+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GCC")
675676
# LLVM data structures like llvm::User and llvm::MDNode rely on
676677
# the value of object storage persisting beyond the lifetime of the
677678
# object (#24952). This is not standard compliant and causes a runtime
678679
# crash if LLVM is built with GCC and LTO enabled (#57740). Until
679680
# these bugs are fixed, we need to disable dead store eliminations
680681
# based on object lifetime.
681-
add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
682-
endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
682+
append("-fno-lifetime-dse" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
683+
endif ()
683684

684685
# Modules enablement for GCC-compatible compilers:
685686
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
@@ -697,22 +698,7 @@ if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
697698
(uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")))
698699
set(module_flags "${module_flags} -gmodules")
699700
endif()
700-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${module_flags}")
701-
702-
# Check that we can build code with modules enabled, and that repeatedly
703-
# including <cassert> still manages to respect NDEBUG properly.
704-
CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG
705-
#include <cassert>
706-
#define NDEBUG
707-
#include <cassert>
708-
int main() { assert(this code is not compiled); }"
709-
CXX_SUPPORTS_MODULES)
710-
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
711-
if (CXX_SUPPORTS_MODULES)
712-
append("${module_flags}" CMAKE_CXX_FLAGS)
713-
else()
714-
message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler")
715-
endif()
701+
append("${module_flags}" CMAKE_CXX_FLAGS)
716702
endif( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
717703

718704
if (MSVC)
@@ -814,13 +800,10 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
814800
# Turn off missing field initializer warnings for gcc to avoid noise from
815801
# false positives with empty {}. Turn them on otherwise (they're off by
816802
# default for clang).
817-
check_cxx_compiler_flag("-Wmissing-field-initializers" CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
818-
if (CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG)
819-
if (CMAKE_COMPILER_IS_GNUCXX)
820-
append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
821-
else()
822-
append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
823-
endif()
803+
if (CMAKE_COMPILER_IS_GNUCXX)
804+
append("-Wno-missing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
805+
else()
806+
append("-Wmissing-field-initializers" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
824807
endif()
825808

826809
if (LLVM_ENABLE_PEDANTIC AND LLVM_COMPILER_IS_GCC_COMPATIBLE)
@@ -833,8 +816,10 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
833816
add_flag_if_supported("-Wc++98-compat-extra-semi" CXX98_COMPAT_EXTRA_SEMI_FLAG)
834817
endif()
835818

836-
add_flag_if_supported("-Wimplicit-fallthrough" IMPLICIT_FALLTHROUGH_FLAG)
837-
add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG)
819+
append("-Wimplicit-fallthrough" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
820+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
821+
append("-Wcovered-switch-default" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
822+
endif()
838823
append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
839824
append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
840825

@@ -845,38 +830,30 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
845830

846831
# Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
847832
# LLVM's ADT classes.
848-
check_cxx_compiler_flag("-Wclass-memaccess" CXX_SUPPORTS_CLASS_MEMACCESS_FLAG)
849-
append_if(CXX_SUPPORTS_CLASS_MEMACCESS_FLAG "-Wno-class-memaccess" CMAKE_CXX_FLAGS)
833+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
834+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1)
835+
append("-Wno-class-memaccess" CMAKE_CXX_FLAGS)
836+
endif()
837+
endif()
850838

851839
# Disable -Wredundant-move and -Wpessimizing-move on GCC>=9. GCC wants to
852-
# remove std::move in code like "A foo(ConvertibleToA a) {
853-
# return std::move(a); }", but this code does not compile (or uses the copy
840+
# remove std::move in code like
841+
# "A foo(ConvertibleToA a) { return std::move(a); }",
842+
# but this code does not compile (or uses the copy
854843
# constructor instead) on clang<=3.8. Clang also has a -Wredundant-move and
855844
# -Wpessimizing-move, but they only fire when the types match exactly, so we
856845
# can keep them here.
857846
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
858-
check_cxx_compiler_flag("-Wredundant-move" CXX_SUPPORTS_REDUNDANT_MOVE_FLAG)
859-
append_if(CXX_SUPPORTS_REDUNDANT_MOVE_FLAG "-Wno-redundant-move" CMAKE_CXX_FLAGS)
860-
check_cxx_compiler_flag("-Wpessimizing-move" CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG)
861-
append_if(CXX_SUPPORTS_PESSIMIZING_MOVE_FLAG "-Wno-pessimizing-move" CMAKE_CXX_FLAGS)
847+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.1)
848+
append("-Wno-redundant-move" CMAKE_CXX_FLAGS)
849+
append("-Wno-pessimizing-move" CMAKE_CXX_FLAGS)
850+
endif()
862851
endif()
863852

864853
# The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not useful.
865-
check_cxx_compiler_flag("-Wnoexcept-type" CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG)
866-
append_if(CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG "-Wno-noexcept-type" CMAKE_CXX_FLAGS)
867-
868-
# Check if -Wnon-virtual-dtor warns for a class marked final, when it has a
869-
# friend declaration. If it does, don't add -Wnon-virtual-dtor. The case is
870-
# considered unhelpful (https://gcc.gnu.org/PR102168).
871-
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
872-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=non-virtual-dtor")
873-
CHECK_CXX_SOURCE_COMPILES("class f {};
874-
class base {friend f; public: virtual void anchor();protected: ~base();};
875-
int main() { return 0; }"
876-
CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR)
877-
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
878-
append_if(CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
854+
append("-Wno-noexcept-type" CMAKE_CXX_FLAGS)
879855

856+
append("-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
880857
append("-Wdelete-non-virtual-dtor" CMAKE_CXX_FLAGS)
881858

882859
# Enable -Wsuggest-override if it's available, and only if it doesn't
@@ -906,14 +883,15 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
906883
endif()
907884

908885
# Enable -Wstring-conversion to catch misuse of string literals.
909-
add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
886+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
887+
append("-Wstring-conversion" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
888+
endif()
910889

911890
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
912891
# Disable the misleading indentation warning with GCC; GCC can
913892
# produce noisy notes about this getting disabled in large files.
914893
# See e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89549
915-
check_cxx_compiler_flag("-Wmisleading-indentation" CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG)
916-
append_if(CXX_SUPPORTS_MISLEADING_INDENTATION_FLAG "-Wno-misleading-indentation" CMAKE_CXX_FLAGS)
894+
append("-Wno-misleading-indentation" CMAKE_CXX_FLAGS)
917895
else()
918896
# Prevent bugs that can happen with llvm's brace style.
919897
add_flag_if_supported("-Wmisleading-indentation" MISLEADING_INDENTATION_FLAG)
@@ -931,14 +909,15 @@ macro(append_common_sanitizer_flags)
931909
if (NOT MSVC OR CLANG_CL)
932910
# Append -fno-omit-frame-pointer and turn on debug info to get better
933911
# stack traces.
934-
add_flag_if_supported("-fno-omit-frame-pointer" FNO_OMIT_FRAME_POINTER)
912+
append("-fno-omit-frame-pointer" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
935913
if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
936-
NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
937-
add_flag_if_supported("-gline-tables-only" GLINE_TABLES_ONLY)
914+
NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO" AND
915+
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
916+
append("-gline-tables-only" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
938917
endif()
939918
# Use -O1 even in debug mode, otherwise sanitizers slowdown is too large.
940919
if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND LLVM_OPTIMIZE_SANITIZED_BUILDS)
941-
add_flag_if_supported("-O1" O1)
920+
append("-O1" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
942921
endif()
943922
else()
944923
# Always ask the linker to produce symbols with asan.
@@ -1112,15 +1091,12 @@ endif()
11121091
if(NOT CYGWIN AND NOT MSVC)
11131092
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND
11141093
NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
1115-
check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS)
1116-
if (C_SUPPORTS_FNO_FUNCTION_SECTIONS)
1117-
# Don't add -ffunction-sections if it can't be disabled with -fno-function-sections.
1118-
# Doing so will break sanitizers.
1119-
add_flag_if_supported("-ffunction-sections" FFUNCTION_SECTIONS)
1120-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
1094+
if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
11211095
append("-qfuncsect" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1096+
else()
1097+
append("-ffunction-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
11221098
endif()
1123-
add_flag_if_supported("-fdata-sections" FDATA_SECTIONS)
1099+
append("-fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
11241100
endif()
11251101
elseif(MSVC)
11261102
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
@@ -1385,7 +1361,9 @@ if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
13851361
file(RELATIVE_PATH relative_root "${CMAKE_BINARY_DIR}" "${source_root}")
13861362
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
13871363
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1388-
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
1364+
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
1365+
append("-no-canonical-prefixes" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1366+
endif()
13891367
endif()
13901368

13911369
option(LLVM_USE_RELATIVE_PATHS_IN_FILES "Use relative paths in sources and debug info" OFF)
@@ -1400,7 +1378,9 @@ if(LLVM_USE_RELATIVE_PATHS_IN_FILES)
14001378
file(RELATIVE_PATH relative_root "${CMAKE_BINARY_DIR}" "${source_root}")
14011379
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
14021380
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1403-
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
1381+
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
1382+
append("-no-canonical-prefixes" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1383+
endif()
14041384
endif()
14051385

14061386
set(LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING

0 commit comments

Comments
 (0)