Skip to content

Commit cbf8e15

Browse files
committed
Add check that CXX and CUDA_HOST compiler match.
Similar to CCCL, we need these to match to ensure that our warning flag detection functions properly.
1 parent 78e7d66 commit cbf8e15

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cmake/NVBenchConfigTarget.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ function(nvbench_add_cxx_flag target_name type flag)
3333
endif()
3434
endfunction()
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+
3669
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wall")
3770
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wextra")
3871
nvbench_add_cxx_flag(nvbench.build_interface INTERFACE "-Wconversion")

0 commit comments

Comments
 (0)