MS Visual C++ 2015 Update 1 implements the Modules proposal .
Here is an example of how it works:
Sources:
// c.ixx | // b.ixx | // a.cpp
module GM; | import GM; | import FM;
export void g() {} | module FM; | int main() { f(); }
| export void f() { g(); } |
Build commands:
set CL=/EHsc /experimental:module # Default flags for cl.exe
cl.exe /c c.ixx # Produces c.obj, GM.ifc
cl.exe /c b.ixx # Depends on GM.ifc, produces b.obj, FM.ifc
cl.exe /c a.cpp # Depends on FM.ifc, produces a.obj
link.exe a.obj b.obj c.obj # Produces a.exe
Dependency graph:
c.ixx → GM.ifc → b.ixx → FM.ifc → a.cpp
↘ ↓ ↙
c.obj b.obj a.obj
↘ ↓ ↙
a.exe
Each module has one file.ixx
with its exports.
This file will be compiled into ModuleName.ifc
and file.obj
.
If a file imports module M
, a M.ifc
file must be present.
By default cl.exe searches .ifc
files in current directory, but it's possible to specify explicit names or search path:
cl.exe /c a.cpp
-- or --
cl.exe /c a.cpp /module:reference FM.ifc
-- or --
cl.exe /c a.cpp /module:search ./
So, the question is: How to use the VC++ implementation of modules in CMake ?
It's not necessary to use the MSBuild backend, Ninja is fine too.
I don't believe anyone has done any build system work for C++ modules at this time. It's likely we (Microsoft) will do MSBuild support first, but CMake is definitely a possibility.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.