Hello
I am trying to use “import std;” with C++ modules. I have enabled the experimental feature, and I have followed all the instructions. The feature is working if I open my project directory in Visual Studio, and I let Visual Studio run cmake for me.
The problem shows up if I run cmake
manually.
cmake
shows me it still uses Visual Studio:
C:\Users\Adrian\Projects\ODBC-Client>cmake -B buuild -S .
-- Building for: Visual Studio 17 2022
-- Setting build type to 'Debug'
-- Setting experimental support for CXX_IMPORT_STD
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.43.34810.0
-- The CXX compiler identification is MSVC 19.43.34810.0
But then the CMAKE_CXX_COMPILER_IMPORT_STD variable is all empty, indicating I do not have support for “import std;” for my C++ modules.
The difference when running under Visual Studio is that VS passes a rich command line to cmake
, including the direct path to the compiler (also it selects the Ninja generator):
1> CMake generation started for configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\Program Files\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="D:\UserStorage\Adrian\Projects\ODBC-Client\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\UserStorage\Adrian\Projects\ODBC-Client" 2>&1"
1> Working directory: D:\UserStorage\Adrian\Projects\ODBC-Client\out\build\x64-Debug
But really it should be the same compiler, so can cmake please populate the CMAKE_CXX_COMPILER_IMPORT_STD variable in both these cases ?
It’s just breaking my build and forcing me to open Visual Studio to be able to builld my project with cmake
…
I have the latest versions of cmake 4.0.1 and VS 17.13.6 2022