@@ -425,7 +425,7 @@ if( LLVM_ENABLE_PIC )
425
425
# GCC for MIPS can miscompile LLVM due to PR37701.
426
426
if (CMAKE_COMPILER_IS_GNUCXX AND LLVM_NATIVE_ARCH STREQUAL "Mips" AND
427
427
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 )
429
429
endif ()
430
430
# gcc with -O3 -fPIC generates TLS sequences that violate the spec on
431
431
# Solaris/sparcv9, causing executables created with the system linker
@@ -635,18 +635,16 @@ if( MSVC )
635
635
# This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag()
636
636
# because cl.exe does not emit an error on flags it doesn't understand,
637
637
# 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" )
650
648
endif ()
651
649
endif ()
652
650
# 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 )
667
665
668
666
# Specific default warnings-as-errors for compilers accepting GCC-compatible warning flags:
669
667
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 )
672
669
endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
673
670
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" )
675
676
# LLVM data structures like llvm::User and llvm::MDNode rely on
676
677
# the value of object storage persisting beyond the lifetime of the
677
678
# object (#24952). This is not standard compliant and causes a runtime
678
679
# crash if LLVM is built with GCC and LTO enabled (#57740). Until
679
680
# these bugs are fixed, we need to disable dead store eliminations
680
681
# 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 ()
683
684
684
685
# Modules enablement for GCC-compatible compilers:
685
686
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
@@ -697,22 +698,7 @@ if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
697
698
(uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO" )))
698
699
set (module_flags "${module_flags} -gmodules" )
699
700
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 )
716
702
endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
717
703
718
704
if (MSVC )
@@ -814,13 +800,10 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
814
800
# Turn off missing field initializer warnings for gcc to avoid noise from
815
801
# false positives with empty {}. Turn them on otherwise (they're off by
816
802
# 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 )
824
807
endif ()
825
808
826
809
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))
833
816
add_flag_if_supported("-Wc++98-compat-extra-semi" CXX98_COMPAT_EXTRA_SEMI_FLAG)
834
817
endif ()
835
818
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 ()
838
823
append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS )
839
824
append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS )
840
825
@@ -845,38 +830,30 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
845
830
846
831
# Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
847
832
# 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 ()
850
838
851
839
# 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
854
843
# constructor instead) on clang<=3.8. Clang also has a -Wredundant-move and
855
844
# -Wpessimizing-move, but they only fire when the types match exactly, so we
856
845
# can keep them here.
857
846
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 ( )
862
851
endif ()
863
852
864
853
# 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 )
879
855
856
+ append ("-Wnon-virtual-dtor" CMAKE_CXX_FLAGS )
880
857
append ("-Wdelete-non-virtual-dtor" CMAKE_CXX_FLAGS )
881
858
882
859
# 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))
906
883
endif ()
907
884
908
885
# 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 ()
910
889
911
890
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
912
891
# Disable the misleading indentation warning with GCC; GCC can
913
892
# produce noisy notes about this getting disabled in large files.
914
893
# 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 )
917
895
else ()
918
896
# Prevent bugs that can happen with llvm's brace style.
919
897
add_flag_if_supported("-Wmisleading-indentation" MISLEADING_INDENTATION_FLAG)
@@ -931,14 +909,15 @@ macro(append_common_sanitizer_flags)
931
909
if (NOT MSVC OR CLANG_CL)
932
910
# Append -fno-omit-frame-pointer and turn on debug info to get better
933
911
# 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 )
935
913
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 )
938
917
endif ()
939
918
# Use -O1 even in debug mode, otherwise sanitizers slowdown is too large.
940
919
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 )
942
921
endif ()
943
922
else ()
944
923
# Always ask the linker to produce symbols with asan.
@@ -1112,15 +1091,12 @@ endif()
1112
1091
if (NOT CYGWIN AND NOT MSVC )
1113
1092
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND
1114
1093
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" )
1121
1095
append ("-qfuncsect" CMAKE_C_FLAGS CMAKE_CXX_FLAGS )
1096
+ else ()
1097
+ append ("-ffunction-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS )
1122
1098
endif ()
1123
- add_flag_if_supported ("-fdata-sections" FDATA_SECTIONS )
1099
+ append ("-fdata-sections" CMAKE_C_FLAGS CMAKE_CXX_FLAGS )
1124
1100
endif ()
1125
1101
elseif (MSVC )
1126
1102
if ( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
@@ -1385,7 +1361,9 @@ if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
1385
1361
file (RELATIVE_PATH relative_root "${CMAKE_BINARY_DIR} " "${source_root} " )
1386
1362
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR} =${relative_root} " CMAKE_C_FLAGS CMAKE_CXX_FLAGS )
1387
1363
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 ()
1389
1367
endif ()
1390
1368
1391
1369
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)
1400
1378
file (RELATIVE_PATH relative_root "${CMAKE_BINARY_DIR} " "${source_root} " )
1401
1379
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR} =${relative_root} " CMAKE_C_FLAGS CMAKE_CXX_FLAGS )
1402
1380
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 ()
1404
1384
endif ()
1405
1385
1406
1386
set (LLVM_THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR} /../third-party CACHE STRING
0 commit comments