0

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.

4
  • Please, show (add to the question post) the exact error message you got. Also show your code (CMake) until that message arise. (As far as I understand, the error is related to the project() call with CUDA language, so you need to provide only lines of your code which preceede that call). Commented Oct 3 at 18:24
  • I was hoping that there is some knowledge, simple flag or something that I simply don't know. Otherwise I will make a copy of the project and reduce the cmake code to minimal example. Commented Oct 3 at 18:28
  • 1
    The simplest project which could reproduce a CMake problem during the compiler-checking phase consists of 2 lines: cmake_minimum_required() and project() 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. Commented Oct 3 at 18:33
  • @Tsyvarev Updated. And as you pointed out it does reveal some interesting element. Commented Oct 3 at 19:54

1 Answer 1

1

As I found out the problem actually lies in spdlog library that incorrectly sets the flag.

There is an issue already filed few months ago: https://github.com/gabime/spdlog/issues/3425

A walkaround - as stated in the issue:

Without modifying the original installed cmake files from spdlog, one can modify the flags after importing the package in cmake:

get_target_property(spdlogflags spdlog::spdlog_header_only INTERFACE_COMPILE_OPTIONS)
string(REPLACE "/Zc:__cplusplus" "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/Zc:__cplusplus>$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CXX_COMPILER_ID:MSVC>>:-Xcompiler=/Zc:__cplusplus>" newspdlogflags ${spdlogflags})
set_target_properties(spdlog::spdlog_header_only PROPERTIES INTERFACE_COMPILE_OPTIONS ${newspdlogflags})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.