C++20 demands a lot more from the ecosystem than ever before. With C++20 Modules on the horizon the compiler needs to work closely with project systems in order to provide rich information for build dependency gathering and making iterative builds faster for inner-loop development. The compiler and project teams have acknowledged the new relationship and collaborated together to bring a new switch to the compiler toolset which can provide useful information to the build system: /sourceDependencies.

Source Dependency Reporting

The new switch for the compiler toolset enables the compiler to generate a source-level dependency report for any given translation unit it compiles. This report is output as a JSON file and you can produce it like this:

$ cl /Yupch.pch /FIpch.h /std:c++latest /experimental:module /module:reference m=m.ifc /headerUnit other.h=other.h.ifc /sourceDependencies main.json main.cpp

Notice the use of /sourceDependencies main.json.

Given the following program:

// main.cpp
#include "header.h"
import m;
import "other.h";

int main() { }

#announcement #c++ #buildsystem #dependency #programming-c #cplusplus

Introducing source dependency reporting with MSVC in Visual Studio 2019
1.55 GEEK