66# - Interface target providing compiler-specific options needed to build
77# Thrust's tests, examples, etc.
88#
9+ # thrust.compiler_interface_cpp11
10+ # thrust.compiler_interface_cpp14
11+ # thrust.compiler_interface_cpp17
12+ # - Interface targets providing compiler-specific options that should only be
13+ # applied to certain dialects of C++.
14+ #
915# thrust.promote_cudafe_warnings
1016# - Interface target that adds warning promotion for NVCC cudafe invocations.
1117# - Only exists to work around github issue #1174 on tbb.cuda configurations.
1218# - May be combined with thrust.compiler_interface when #1174 is fully resolved.
19+ #
20+ # thrust.silence_unreachable_code_warnings
21+ # - Interface target that silences unreachable code warnings.
22+ # - Used to selectively disable such warnings in unit tests caused by
23+ # unconditionally thrown exceptions.
1324
1425function (thrust_build_compiler_targets )
1526 set (cxx_compile_definitions)
1627 set (cxx_compile_options)
1728
1829 thrust_update_system_found_flags ()
1930
20- if (THRUST_TBB_FOUND)
21- # There's a ton of these in the TBB backend, even though the code is correct.
22- # TODO: silence these warnings in code instead
23- append_option_if_available ("-Wno-unused-parameter" cxx_compile_options )
24- endif ()
25-
2631 if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
27- # TODO Enable /Wall instead of W3
28- append_option_if_available ("/W3" cxx_compile_options )
32+ append_option_if_available ("/W4" cxx_compile_options )
33+
34+ # Treat all warnings as errors. This is only supported on Release builds,
35+ # as `nv_exec_check_disable` doesn't seem to work with MSVC debug iterators
36+ # and spurious warnings are emitted.
37+ # See NVIDIA/thrust#1273, NVBug 3129879.
38+ if (CMAKE_BUILD_TYPE STREQUAL "Release" )
39+ append_option_if_available ("/WX" cxx_compile_options )
40+ endif ()
2941
30- # Treat all warnings as errors:
31- append_option_if_available ("/WX" cxx_compile_options )
42+ # Suppress overly-pedantic/unavoidable warnings brought in with /W4:
43+ # C4324: structure was padded due to alignment specifier
44+ append_option_if_available ("/wd4324" cxx_compile_options )
45+ # C4505: unreferenced local function has been removed
46+ # The CUDA `host_runtime.h` header emits this for
47+ # `__cudaUnregisterBinaryUtil`.
48+ append_option_if_available ("/wd4505" cxx_compile_options )
49+ # C4706: assignment within conditional expression
50+ # MSVC doesn't provide an opt-out for this warning when the assignment is
51+ # intentional. Clang will warn for these, but suppresses the warning when
52+ # double-parentheses are used around the assignment. We'll let Clang catch
53+ # unintentional assignments and suppress all such warnings on MSVC.
54+ append_option_if_available ("/wd4706" cxx_compile_options )
3255
3356 # Disabled loss-of-data conversion warnings.
3457 # TODO Re-enable.
3558 append_option_if_available ("/wd4244" cxx_compile_options )
36- append_option_if_available ("/wd4267" cxx_compile_options )
37-
38- # Suppress numeric conversion-to-bool warnings.
39- # TODO Re-enable.
40- append_option_if_available ("/wd4800" cxx_compile_options )
4159
4260 # Disable warning about applying unary operator- to unsigned type.
61+ # TODO Re-enable.
4362 append_option_if_available ("/wd4146" cxx_compile_options )
4463
4564 # MSVC STL assumes that `allocator_traits`'s allocator will use raw pointers,
@@ -64,48 +83,29 @@ function(thrust_build_compiler_targets)
6483 append_option_if_available ("-Winit-self" cxx_compile_options )
6584 append_option_if_available ("-Woverloaded-virtual" cxx_compile_options )
6685 append_option_if_available ("-Wcast-qual" cxx_compile_options )
67- append_option_if_available ("-Wno-cast-align" cxx_compile_options )
68- append_option_if_available ("-Wno-long-long" cxx_compile_options )
69- append_option_if_available ("-Wno-variadic-macros" cxx_compile_options )
86+ append_option_if_available ("-Wpointer-arith" cxx_compile_options )
87+ append_option_if_available ("-Wunused-local-typedef" cxx_compile_options )
88+ append_option_if_available ("-Wvla" cxx_compile_options )
89+
90+ # Disable GNU extensions (flag is clang only)
91+ append_option_if_available ("-Wgnu" cxx_compile_options )
92+ # Calling a variadic macro with zero args is a GNU extension until C++20,
93+ # but the THRUST_PP_ARITY macro is used with zero args. Need to see if this
94+ # is a real problem worth fixing.
95+ append_option_if_available ("-Wno-gnu-zero-variadic-macro-arguments" cxx_compile_options )
96+
97+ # This complains about functions in CUDA system headers when used with nvcc.
7098 append_option_if_available ("-Wno-unused-function" cxx_compile_options )
71- append_option_if_available ("-Wno-unused-variable" cxx_compile_options )
7299 endif ()
73100
74101 if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
75- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5)
76- # In GCC 4.4, the CUDA backend's kernel launch templates cause
77- # impossible-to-decipher "'<anonymous>' is used uninitialized in this
78- # function" warnings, so we disable uninitialized variable warnings.
79- append_option_if_available ("-Wno-uninitialized" cxx_compile_options )
80- endif ()
81-
82- if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.5)
83- # This isn't available until GCC 4.3, and misfires on TMP code until
84- # GCC 4.5.
85- append_option_if_available ("-Wlogical-op" cxx_compile_options )
86- endif ()
87-
88102 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3)
89103 # GCC 7.3 complains about name mangling changes due to `noexcept`
90104 # becoming part of the type system; we don't care.
91105 append_option_if_available ("-Wno-noexcept-type" cxx_compile_options )
92106 endif ()
93107 endif ()
94108
95- if (("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID} " ) OR
96- ("XL" STREQUAL "${CMAKE_CXX_COMPILER_ID} " ))
97- # xlC and Clang warn about unused parameters in uninstantiated templates.
98- # This causes xlC to choke on the OMP backend, which is mostly #ifdef'd out
99- # (and thus has unused parameters) when you aren't using it.
100- append_option_if_available ("-Wno-unused-parameters" cxx_compile_options )
101- endif ()
102-
103- if ("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
104- # -Wunneeded-internal-declaration misfires in the unit test framework
105- # on older versions of Clang.
106- append_option_if_available ("-Wno-unneeded-internal-declaration" cxx_compile_options )
107- endif ()
108-
109109 if ("Intel" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
110110 # Disable warning that inlining is inhibited by compiler thresholds.
111111 append_option_if_available ("-diag-disable=11074" cxx_compile_options )
@@ -172,4 +172,23 @@ function(thrust_build_compiler_targets)
172172 )
173173 endif ()
174174
175+ # These targets are used for dialect-specific options:
176+ add_library (thrust.compiler_interface_cpp11 INTERFACE )
177+ add_library (thrust.compiler_interface_cpp14 INTERFACE )
178+ add_library (thrust.compiler_interface_cpp17 INTERFACE )
179+
180+ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
181+ # C4127: conditional expression is constant
182+ # Disable this MSVC warning for C++11/C++14. In C++17, we can use
183+ # THRUST_IF_CONSTEXPR to address these warnings.
184+ target_compile_options (thrust.compiler_interface_cpp11 INTERFACE
185+ $<$<COMPILE_LANGUAGE :CXX >:/wd4127 >
186+ $<$<AND :$<COMPILE_LANGUAGE :CUDA >,$<CUDA_COMPILER_ID :NVIDIA >>:-Xcompiler =/wd4127 >
187+ )
188+ target_compile_options (thrust.compiler_interface_cpp14 INTERFACE
189+ $<$<COMPILE_LANGUAGE :CXX >:/wd4127 >
190+ $<$<AND :$<COMPILE_LANGUAGE :CUDA >,$<CUDA_COMPILER_ID :NVIDIA >>:-Xcompiler =/wd4127 >
191+ )
192+ endif ()
193+
175194endfunction ()
0 commit comments