I am working on C++ project on Windows, using CUDA 12.0, cmake 3.31.6, vcpkg (updated to recent commit a62ce77).
During configuration CMake tries to launch nvcc with some small test program to get compiler information. It invokes it like this:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\bin\nvcc.exe" -D_WINDOWS "-Xcompiler= /GR /EHsc" --std=c++17 --expt-relaxed-constexpr --expt-extended-lambda -Xcudafe --display_error_number,--diag_suppress=[186,611,1388,1394,2809,20011,20012,20014,20054] -Xptxas -dlcm=ca --resource-usage -Xcompiler=/arch:AVX2 "-Xcompiler= -Zi -Ob0 -Od /RTC1" -std=c++17 -arch=native -Xcompiler=-MDd -D_ITERATOR_DEBUG_LEVEL=0 /Zc:__cplusplus --dryrun -forward-unknown-to-host-compiler C:\Users\Me\AppData\Local\Temp\compiler-file17533896127583160454.cu
To which it responds:
nvcc fatal : Don't know what to do with 'F:/Zc:__cplusplus'
The flag /Zc:__cplusplus should probably be preceeded by -Xcompiler. At the moment it treats it as a file name, and prepends disk F: to it. But I don't know how to fix it: Nowhere in my CMakeLists.txt I specify this flag, this must be added automatically by CMake, perhaps as a result of some other setting.
How do I make CMake pass the flag correctly into nvcc? Where in CMake is it controlled? I could append the correct flag to CMAKE_CUDA_FLAGS, but I also need to remove the parameter automatically added by CMake which is not present in that variable.
In order to try to diagnose the problem myself, I tried to print all cmake variables at the end of CMakeLists.txt:
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName} = ${${_variableName}}")
endforeach()
but no variable holds __cplusplus (except _corradeConfigure, which is irrelevant here)
I reduced the problem to minimal example, and it revealed to me that it is somehow related to spdlog::spdlog_header_only. (Thank you for making me do it). I will look into that direction now.
The minimal example looks like this:
CMakeLists.txt:
cmake_minimum_required (VERSION 3.18)
project(Foo LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 20)
find_package(spdlog CONFIG REQUIRED)
add_library(Foo
STATIC
empty.cu
)
target_link_libraries(Foo
PUBLIC
spdlog::spdlog_header_only
)
vcpkg.json
{
"name": "foo",
"version-string": "0.0.1",
"dependencies": [
"spdlog"
]
}
vcpkg-configuration.json
{
"default-registry": {
"kind": "git",
"repository": "https://github.com/Microsoft/vcpkg",
"baseline": "a62ce77d56ee07513b4b67de1ec2daeaebfae51a"
}
}
CMake is invoked by CLion with the command:
"C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2024.3.4/bin/ninja/win/x64/ninja.exe" -G Ninja -DCMAKE_TOOLCHAIN_FILE=F:\Libraries\vcpkg\scripts\buildsystems\vcpkg.cmake -S F:\Projects\MyProject -B F:\Projects\MyProject\cmake-build-debug
And the output is:
-- Running vcpkg install
Detecting compiler hash for triplet x64-windows...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe
The following packages are already installed:
* fmt:[email protected] -- git+https://github.com/Microsoft/vcpkg@c5dcb90bc1da6e7ba3d6e62e62a0b7df3192f51c
spdlog:[email protected] -- git+https://github.com/Microsoft/vcpkg@c2b47286b0759373acecdfaa3be4219711f6d059
* vcpkg-cmake:x64-windows@2024-04-23 -- git+https://github.com/Microsoft/vcpkg@e74aa1e8f93278a8e71372f1fa08c3df420eb840
* vcpkg-cmake-config:x64-windows@2024-05-23 -- git+https://github.com/Microsoft/vcpkg@97a63e4bc1a17422ffe4eff71da53b4b561a7841
The package spdlog provides CMake targets:
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(main PRIVATE spdlog::spdlog)
# Or use the header-only version
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(main PRIVATE spdlog::spdlog_header_only)
All requested installations completed successfully in: 224 us
-- Running vcpkg install - done
-- Configuring done (1.4s)
-- Generating done (0.0s)
-- Build files have been written to: F:/Projects/MyProject/cmake-build-debug
Cannot get compiler information:
Compiler exited with error code 1: "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\bin\nvcc.exe" -DFMT_SHARED -DSPDLOG_FMT_EXTERNAL -DSPDLOG_FWRITE_UNLOCKED -isystem=F:/Projects/MyProject/cmake-build-debug/vcpkg_installed/x64-windows/include -D_WINDOWS "-Xcompiler= /GR /EHsc" "-Xcompiler= -Zi -Ob0 -Od /RTC1" -std=c++20 --generate-code=arch=compute_52,code=[compute_52,sm_52] -Xcompiler=-MDd /Zc:__cplusplus --dryrun -forward-unknown-to-host-compiler C:\Users\me\AppData\Local\Temp\compiler-file17655800990905755916.cu
[Failed to reload]
Removing spdlog::spdlog_header_only or replacing it with spdlog::spdlog from target_link_libraries seems to solve the problem, but I do want to use the library that way.
project()call with CUDA language, so you need to provide only lines of your code which preceede that call).cmake_minimum_required()andproject()calls. If such simple project doesn't reproduce your problem, then there is something in your code which really matters. In that case we simply cannot help you without the code.