|
| 1 | +# |
| 2 | +# This file defines the `thrust_build_compiler_targets()` function, which |
| 3 | +# creates the following interface targets: |
| 4 | +# |
| 5 | +# thrust.compiler_interface |
| 6 | +# - Interface target providing compiler-specific options needed to build |
| 7 | +# Thrust's tests, examples, etc. |
| 8 | +# |
| 9 | +# thrust.promote_cudafe_warnings |
| 10 | +# - Interface target that adds warning promotion for NVCC cudafe invocations. |
| 11 | +# - Only exists to work around github issue #1174 on tbb.cuda configurations. |
| 12 | +# - May be combined with thrust.compiler_interface when #1174 is fully resolved. |
| 13 | + |
| 14 | +function(thrust_build_compiler_targets) |
| 15 | + set(cxx_compile_definitions) |
| 16 | + set(cxx_compile_options) |
| 17 | + |
| 18 | + thrust_update_system_found_flags() |
| 19 | + |
| 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 | + |
| 26 | + if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}") |
| 27 | + # TODO Enable /Wall |
| 28 | + append_option_if_available("/WX" cxx_compile_options) |
| 29 | + |
| 30 | + # Disabled loss-of-data conversion warnings. |
| 31 | + # TODO Re-enable. |
| 32 | + append_option_if_available("/wd4244" cxx_compile_options) |
| 33 | + append_option_if_available("/wd4267" cxx_compile_options) |
| 34 | + |
| 35 | + # Suppress numeric conversion-to-bool warnings. |
| 36 | + # TODO Re-enable. |
| 37 | + append_option_if_available("/wd4800" cxx_compile_options) |
| 38 | + |
| 39 | + # Disable warning about applying unary operator- to unsigned type. |
| 40 | + append_option_if_available("/wd4146" cxx_compile_options) |
| 41 | + |
| 42 | + # MSVC STL assumes that `allocator_traits`'s allocator will use raw pointers, |
| 43 | + # and the `__DECLSPEC_ALLOCATOR` macro causes issues with thrust's universal |
| 44 | + # allocators: |
| 45 | + # warning C4494: 'std::allocator_traits<_Alloc>::allocate' : |
| 46 | + # Ignoring __declspec(allocator) because the function return type is not |
| 47 | + # a pointer or reference |
| 48 | + # See https://github.com/microsoft/STL/issues/696 |
| 49 | + append_option_if_available("/wd4494" cxx_compile_options) |
| 50 | + |
| 51 | + # Some of the async tests require /bigobj to fit all their sections into the |
| 52 | + # object files: |
| 53 | + append_option_if_available("/bigobj" cxx_compile_options) |
| 54 | + |
| 55 | + # "Oh right, this is Visual Studio." |
| 56 | + list(APPEND cxx_compile_definitions "NOMINMAX") |
| 57 | + else() |
| 58 | + append_option_if_available("-Werror" cxx_compile_options) |
| 59 | + append_option_if_available("-Wall" cxx_compile_options) |
| 60 | + append_option_if_available("-Wextra" cxx_compile_options) |
| 61 | + append_option_if_available("-Winit-self" cxx_compile_options) |
| 62 | + append_option_if_available("-Woverloaded-virtual" cxx_compile_options) |
| 63 | + append_option_if_available("-Wcast-qual" cxx_compile_options) |
| 64 | + append_option_if_available("-Wno-cast-align" cxx_compile_options) |
| 65 | + append_option_if_available("-Wno-long-long" cxx_compile_options) |
| 66 | + append_option_if_available("-Wno-variadic-macros" cxx_compile_options) |
| 67 | + append_option_if_available("-Wno-unused-function" cxx_compile_options) |
| 68 | + append_option_if_available("-Wno-unused-variable" cxx_compile_options) |
| 69 | + endif() |
| 70 | + |
| 71 | + if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}") |
| 72 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5) |
| 73 | + # In GCC 4.4, the CUDA backend's kernel launch templates cause |
| 74 | + # impossible-to-decipher "'<anonymous>' is used uninitialized in this |
| 75 | + # function" warnings, so we disable uninitialized variable warnings. |
| 76 | + append_option_if_available("-Wno-uninitialized" cxx_compile_options) |
| 77 | + endif() |
| 78 | + |
| 79 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.5) |
| 80 | + # This isn't available until GCC 4.3, and misfires on TMP code until |
| 81 | + # GCC 4.5. |
| 82 | + append_option_if_available("-Wlogical-op" cxx_compile_options) |
| 83 | + endif() |
| 84 | + |
| 85 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3) |
| 86 | + # GCC 7.3 complains about name mangling changes due to `noexcept` |
| 87 | + # becoming part of the type system; we don't care. |
| 88 | + append_option_if_available("-Wno-noexcept-type" cxx_compile_options) |
| 89 | + endif() |
| 90 | + endif() |
| 91 | + |
| 92 | + if (("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}") OR |
| 93 | + ("XL" STREQUAL "${CMAKE_CXX_COMPILER_ID}")) |
| 94 | + # xlC and Clang warn about unused parameters in uninstantiated templates. |
| 95 | + # This causes xlC to choke on the OMP backend, which is mostly #ifdef'd out |
| 96 | + # (and thus has unused parameters) when you aren't using it. |
| 97 | + append_option_if_available("-Wno-unused-parameters" cxx_compile_options) |
| 98 | + endif() |
| 99 | + |
| 100 | + if ("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}") |
| 101 | + # -Wunneeded-internal-declaration misfires in the unit test framework |
| 102 | + # on older versions of Clang. |
| 103 | + append_option_if_available("-Wno-unneeded-internal-declaration" cxx_compile_options) |
| 104 | + endif() |
| 105 | + |
| 106 | + if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") |
| 107 | + # Today: |
| 108 | + # * NVCC accepts CUDA C++ in .cu files but not .cpp files. |
| 109 | + # * Feta accepts CUDA C++ in .cpp files but not .cu files. |
| 110 | + # TODO: This won't be necessary in the future. |
| 111 | + list(APPEND cxx_compile_options -cppsuffix=cu) |
| 112 | + endif() |
| 113 | + |
| 114 | + add_library(thrust.compiler_interface INTERFACE) |
| 115 | + |
| 116 | + foreach (cxx_option IN LISTS cxx_compile_options) |
| 117 | + target_compile_options(thrust.compiler_interface INTERFACE |
| 118 | + $<$<COMPILE_LANGUAGE:CXX>:${cxx_option}> |
| 119 | + # Only use -Xcompiler with NVCC, not Feta. |
| 120 | + # |
| 121 | + # CMake can't split genexs, so this can't be formatted better :( |
| 122 | + # This is: |
| 123 | + # if (using CUDA and CUDA_COMPILER is NVCC) add -Xcompiler=opt: |
| 124 | + $<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcompiler=${cxx_option}> |
| 125 | + ) |
| 126 | + endforeach() |
| 127 | + |
| 128 | + foreach (cxx_definition IN LISTS cxx_compile_definitions) |
| 129 | + # Add these for both CUDA and CXX targets: |
| 130 | + target_compile_definitions(thrust.compiler_interface INTERFACE |
| 131 | + ${cxx_definition} |
| 132 | + ) |
| 133 | + endforeach() |
| 134 | + |
| 135 | + # Display warning numbers from nvcc cudafe errors: |
| 136 | + target_compile_options(thrust.compiler_interface INTERFACE |
| 137 | + # If using CUDA w/ NVCC... |
| 138 | + $<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcudafe=--display_error_number> |
| 139 | + ) |
| 140 | + |
| 141 | + # This is kept separate for Github issue #1174. |
| 142 | + add_library(thrust.promote_cudafe_warnings INTERFACE) |
| 143 | + target_compile_options(thrust.promote_cudafe_warnings INTERFACE |
| 144 | + $<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:-Xcudafe=--promote_warnings> |
| 145 | + ) |
| 146 | +endfunction() |
0 commit comments