mercredi 19 avril 2023

CMake failing to tell MSVC to use C++11?

I'm using CMake to generate the build system of a library of mine. I have some example programs, while I build with the language standard set to C++11:

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Now, for a Windows build, I (or rather GitHub) is using MSVC 16 on Windows 10. For this program:

add_executable(bandwidthtest modified_cuda_samples/bandwidthtest/bandwidthtest.cpp)

I get this compilation command generated by CMake (I think it's CMake 3.26.3; lines broken for readability):

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\CL.exe
/c /I"D:\a\cuda-api-wrappers\cuda-api-wrappers\src"
/I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\include" /nologo /W4 
/WX- /diagnostics:column /O2 /Ob2 /D _MBCS /D WIN32 /D _WINDOWS /D NDEBUG 
/D _CRT_SECURE_NO_DEPRECATE /D _CRT_SECURE_NO_WARNINGS 
/D _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING /D "CMAKE_INTDIR=\"Release\"" 
/Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"bandwidthtest.dir\Release\\" /Fd"bandwidthtest.dir\Release\vc142.pdb" /external:W0 
/Gd /TP /errorReport:queue  
/external:I "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include" /Zc:__cplusplus 
"D:\a\cuda-api-wrappers\cuda-api-wrappers\examples\modified_cuda_samples\bandwidthtest\bandwidthtest.cpp"

So, this doesn't have an /std option. It does have /Zc:__cplusplus, but I added that one myself (I think CMake should have added it as well, but that's a known open issue).

Why does CMake not add /std:c++11?

Aucun commentaire:

Enregistrer un commentaire