@@ -33,13 +33,46 @@ function(nvbench_add_cxx_flag target_name type flag)
3333 endif ()
3434endfunction ()
3535
36+ # We test to see if C++ compiler options exist using try-compiles in the CXX lang, and then reuse those flags as
37+ # -Xcompiler flags for CUDA targets. This requires that the CXX compiler and CUDA_HOST compilers are the same when
38+ # using nvcc.
39+ if (NVBench_TOPLEVEL_PROJECT AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" )
40+ set (cuda_host_matches_cxx_compiler FALSE )
41+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.31)
42+ set (host_info "${CMAKE_CUDA_HOST_COMPILER} (${CMAKE_CUDA_HOST_COMPILER_ID} ${CMAKE_CUDA_HOST_COMPILER_VERSION} )" )
43+ set (cxx_info "${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} )" )
44+ if (CMAKE_CUDA_HOST_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID AND
45+ CMAKE_CUDA_HOST_COMPILER_VERSION VERSION_EQUAL CMAKE_CXX_COMPILER_VERSION)
46+ set (cuda_host_matches_cxx_compiler TRUE )
47+ endif ()
48+ else () # CMake < 3.31 doesn't have the CMAKE_CUDA_HOST_COMPILER_ID/VERSION variables
49+ set (host_info "${CMAKE_CUDA_HOST_COMPILER} " )
50+ set (cxx_info "${CMAKE_CXX_COMPILER} " )
51+ if (CMAKE_CUDA_HOST_COMPILER STREQUAL CMAKE_CXX_COMPILER)
52+ set (cuda_host_matches_cxx_compiler TRUE )
53+ endif ()
54+ endif ()
55+
56+ if (NOT cuda_host_matches_cxx_compiler)
57+ message (FATAL_ERROR
58+ "NVBench developer builds require that CMAKE_CUDA_HOST_COMPILER matches "
59+ "CMAKE_CXX_COMPILER when using nvcc:\n "
60+ "CMAKE_CUDA_COMPILER: ${CMAKE_CUDA_COMPILER} \n "
61+ "CMAKE_CUDA_HOST_COMPILER: ${host_info} \n "
62+ "CMAKE_CXX_COMPILER: ${cxx_info} \n "
63+ "Rerun cmake with \" -DCMAKE_CUDA_HOST_COMPILER=${CMAKE_CXX_COMPILER} \" .\n "
64+ "Alternatively, configure the CUDAHOSTCXX and CXX environment variables to match.\n "
65+ )
66+ endif ()
67+ endif ()
68+
3669nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wall" )
3770nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wextra" )
3871nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wconversion" )
3972nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Woverloaded-virtual" )
4073nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wcast-qual" )
4174nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wpointer-arith" )
42- nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wunused-local-typedef " )
75+ nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wunused-local-typedefs " )
4376nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wunused-parameter" )
4477nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wvla" )
4578nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wgnu" )
0 commit comments