CMake 3.28: Project using C++20 modules fails to build when using Ninja (/MultiConfig) generator on Windows
The attached sample project uses C++20 presets on Windows. I am using the latest Visual Studio 2022 Preview to build the project. The project has a few CMake presets Ninja, Ninja-MultiConfig and Visual Studio 17 2022 If I use the built-in CMake 3.27 + Ninja generator or a Visual 2022 the project builds. If I use an external CMake 3.28 + Ninja the project fails to build. Visual Studio Code + the respective extensions yield the same result.
The output when "Ninja (MSVC)" CMake presets is selected:
>------ Rebuild All started: Project: RToolBoxTest, Configuration: default.ninja.msvc ------
[1/1] Cleaning all built files...
Cleaning... 0 files.
[1/11] Scanning X:\GitHub\RToolBoxTest\RToolBox\modules\RToolBox.cppm for CXX dependencies
RToolBox.cppm
[2/11] Scanning X:\GitHub\RToolBoxTest\RToolBox\modules\System\Window.cppm for CXX dependencies
Window.cppm
[3/11] Building RC object examples\SimpleGameMain\CMakeFiles\SimpleGameMain.dir\__\Resources\Windows\SampleGame.rc.res
[4/11] Generating CXX dyndep file CMakeFiles\RToolBox.dir\CXX.dd
[5/11] Building CXX object examples\SimpleGameMain\CMakeFiles\SimpleGameMain.dir\src\main.cpp.obj
FAILED: examples/SimpleGameMain/CMakeFiles/SimpleGameMain.dir/src/main.cpp.obj
"C:\PROGRA~1\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.39.33218\bin\Hostx64\x64\cl.exe" /nologo /TP -DNOATOM -DNOCLIPBOARD -DNOCOMM -DNOCTLMGR -DNODEFERWINDOWPOS -DNODRAWTEXT -DNOGDICAPMASKS -DNOHELP -DNOICONS -DNOKANJI -DNOKERNEL -DNOKEYSTATES -DNOMCX -DNOMEMMGR -DNOMENUS -DNOMETAFILE -DNOMINMAX -DNONLS -DNOOPENFILE -DNOPROFILER -DNORASTEROPS -DNOSCROLL -DNOSERVICE -DNOSOUND -DNOSYSCOMMANDS -DNOSYSMETRICS -DNOTEXTMETRIC -DNOWH -DNOWINOFFSETS -DOEMRESOURCE -DSTRICT -DUNICODE -DWIN32_LEAN_AND_MEAN -D_UNICODE -IX:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\.. /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /JMC /showIncludes /Foexamples\SimpleGameMain\CMakeFiles\SimpleGameMain.dir\src\main.cpp.obj /Fdexamples\SimpleGameMain\CMakeFiles\SimpleGameMain.dir\ /FS -c X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(6): error C2230: could not find module 'rmm.RToolBox'
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(10): error C3083: 'rmm': the symbol to the left of a '::' must be a type
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(10): error C2039: 'rtoolbox': is not a member of '`global namespace''
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(10): error C2878: 'rtoolbox': a namespace or class of this name does not exist
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(17): error C2653: 'rt': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(17): error C2065: 'Window': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(17): error C2146: syntax error: missing ';' before identifier 'window'
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(17): error C2065: 'window': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(17): error C2653: 'rt': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(17): error C2065: 'Description': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(19): error C2065: 'window': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(21): error C2065: 'window': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\examples\SimpleGameMain\src\main.cpp(22): error C2065: 'window': undeclared identifier
[6/11] Building CXX object CMakeFiles\RToolBox.dir\modules\System\Platforms\Window_Windows.cpp.obj
FAILED: CMakeFiles/RToolBox.dir/modules/System/Platforms/Window_Windows.cpp.obj
"C:\PROGRA~1\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.39.33218\bin\Hostx64\x64\cl.exe" /nologo /TP -DNOATOM -DNOCLIPBOARD -DNOCOMM -DNOCTLMGR -DNODEFERWINDOWPOS -DNODRAWTEXT -DNOGDICAPMASKS -DNOHELP -DNOICONS -DNOKANJI -DNOKERNEL -DNOKEYSTATES -DNOMCX -DNOMEMMGR -DNOMENUS -DNOMETAFILE -DNOMINMAX -DNONLS -DNOOPENFILE -DNOPROFILER -DNORASTEROPS -DNOSCROLL -DNOSERVICE -DNOSOUND -DNOSYSCOMMANDS -DNOSYSMETRICS -DNOTEXTMETRIC -DNOWH -DNOWINOFFSETS -DOEMRESOURCE -DSTRICT -DUNICODE -DWIN32_LEAN_AND_MEAN -D_UNICODE /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /JMC /showIncludes /FoCMakeFiles\RToolBox.dir\modules\System\Platforms\Window_Windows.cpp.obj /FdCMakeFiles\RToolBox.dir\RToolBox.pdb /FS -c X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(10): error C2230: could not find module 'rmm.RToolBox'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(15): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(18): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(18): error C2061: syntax error: identifier 'Description'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(29): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(29): error C2061: syntax error: identifier 'ResourceID'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(42): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(42): error C3646: 'description': unknown override specifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(42): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(45): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(46): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(45): error C7550: 'rmm::rtoolbox::Implementation::{ctor}': the qualified name in this context names a constructor, not a type
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(46): error C2065: 'Description': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(46): error C2065: 'description': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(47): error C2062: type 'void' unexpected
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(48): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(49): error C2059: syntax error: '{'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(49): error C2143: syntax error: missing ';' before '{'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(49): error C2447: '{': missing function header (old-style formal list?)
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(66): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(75): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(81): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(88): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(112): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(118): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(118): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(118): error C2761: 'void rmm::rtoolbox::Implementation::SetIcon(void) noexcept const': redeclaration of member is not allowed
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(118): error C2065: 'ResourceID': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(118): error C2146: syntax error: missing ')' before identifier 'icon'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(119): error C2143: syntax error: missing ';' before '{'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(119): error C2447: '{': missing function header (old-style formal list?)
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(127): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(154): error C3536: 'titleStr': cannot be used before it is initialized
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(161): error C2660: 'CreateWindowExW': function does not take 10 arguments
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winuser.h(4437): note: see declaration of 'CreateWindowExW'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(161): note: while trying to match the argument list '(int, long, int, int, int, int, nullptr, nullptr, HMODULE, nullptr)'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window_Windows.cpp(179): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(4): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(4): error C2653: 'Window': is not a class or namespace name
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(4): error C2065: 'Description': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(4): error C2062: type 'void' unexpected
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(5): error C2065: 'data': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(6): error C2059: syntax error: '{'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(6): error C2143: syntax error: missing ';' before '{'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(6): error C2447: '{': missing function header (old-style formal list?)
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(9): error C2825: 'rmm::rtoolbox::Window': must be a class or namespace when followed by '::'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(9): error C2510: 'Window': left of '::' must be a class/struct/union
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(9): warning C4508: 'rmm::rtoolbox::{dtor}': function should return a value; 'void' return type assumed
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(12): error C2825: 'rmm::rtoolbox::Window': must be a class or namespace when followed by '::'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(12): error C2510: 'Window': left of '::' must be a class/struct/union
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(12): error C2270: 'Hide': modifiers not allowed on nonmember functions
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(18): error C2825: 'rmm::rtoolbox::Window': must be a class or namespace when followed by '::'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(18): error C2510: 'Window': left of '::' must be a class/struct/union
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(18): error C2270: 'Show': modifiers not allowed on nonmember functions
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(24): error C2825: 'rmm::rtoolbox::Window': must be a class or namespace when followed by '::'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(24): error C2510: 'Window': left of '::' must be a class/struct/union
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(24): error C2270: 'Run': modifiers not allowed on nonmember functions
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(30): error C2825: 'rmm::rtoolbox::Window': must be a class or namespace when followed by '::'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(30): error C2510: 'Window': left of '::' must be a class/struct/union
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(30): error C2270: 'GetHandle': modifiers not allowed on nonmember functions
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(36): error C2825: 'rmm::rtoolbox::Window': must be a class or namespace when followed by '::'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(36): error C2510: 'Window': left of '::' must be a class/struct/union
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(36): error C2182: 'SetIcon': this use of 'void' is not valid
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(36): error C2065: 'ResourceID': undeclared identifier
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(36): error C2146: syntax error: missing ')' before identifier 'icon'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(37): error C2143: syntax error: missing ';' before '{'
X:\GitHub\RToolBoxTest\RToolBox\modules\System\Platforms\Window.inc(37): error C2447: '{': missing function header (old-style formal list?)
[7/11] Building CXX object CMakeFiles\RToolBox.dir\modules\System\Window.cppm.obj
Window.cppm
[8/11] Building CXX object libraries\RTMain\CMakeFiles\RToolBox-main.dir\src\RTMain.cpp.obj
ninja: build stopped: subcommand failed.
Rebuild All failed.
This is the output when using CMake presets "MSBuild (MSVC)"
>------ Rebuild All started: Project: RToolBoxTest, Configuration: default.msbuild.msvc ------
MSBuild version 17.9.0-preview-23551-05+34ae4f308 for .NET Framework
MSBuild version 17.9.0-preview-23551-05+34ae4f308 for .NET Framework
1>Checking Build System
Building Custom Rule X:/GitHub/RToolBoxTest/RToolBox/CMakeLists.txt
Scanning sources for module dependencies...
RToolBox.cppm
Window.cppm
Compiling...
Window.cppm
RToolBox.cppm
Window_Windows.cpp
RToolBox.vcxproj -> X:\GitHub\RToolBoxTest\build\default.msbuild.msvc\Debug\RToolBox.lib
Building Custom Rule X:/GitHub/RToolBoxTest/RToolBox/libraries/RTMain/CMakeLists.txt
RTMain.cpp
RToolBox-main.vcxproj -> X:\GitHub\RToolBoxTest\build\default.msbuild.msvc\libraries\RTMain\RToolBox-main.dir\Debug\RToolBox-main.lib
Building Custom Rule X:/GitHub/RToolBoxTest/RToolBox/examples/SimpleGameMain/CMakeLists.txt
main.cpp
SimpleGameMain.vcxproj -> X:\GitHub\RToolBoxTest\build\default.msbuild.msvc\examples\SimpleGameMain\Debug\SimpleGameMain.exe
Building Custom Rule X:/GitHub/RToolBoxTest/RToolBox/CMakeLists.txt
Rebuild All succeeded.
Edited by Zingam