Yes, absolutely!
The concept of using file modification dates for incremental builds is fundamental to how virtually all modern build systems (including those generated by CMake) operate, and it works perfectly fine on Windows.
Here's why:
-
File Systems and Timestamps: All common Windows file systems (like NTFS, which is the standard) record several timestamps for each file and directory, including:
- Creation Time: When the file was first created.
- Last Access Time: When the file was last opened or read.
- Last Write Time (Modification Time): When the file's content was last changed.
-
How Build Tools Use Them:
- When you run
cmake --build build, the underlying build tool (e.g., Ninja, MSBuild, or GNU Make if you installed it) will query these timestamps from the operating system.
- For example, when compiling
main.cpp into main.obj:
- It will compare the
Last Write Time of main.cpp with the Last Write Time of main.obj.
- If
main.cpp is newer than main.obj (meaning main.cpp has been modified since main.obj was last successfully created), then main.cpp will be recompiled.
- It also tracks dependencies: if
main.cpp includes myheader.h, and myheader.h changes, the build tool will know that main.cpp (and any other source files including that header) need to be recompiled, even if main.cpp itself hasn't changed.
In essence: Windows provides the necessary file system functionality, and the build tools (like Ninja or MSBuild, which cmake --build invokes) are designed to utilize these timestamps to determine what needs to be rebuilt.
So, if you remove the RD /S /Q build line from your script, you will indeed get fast, incremental builds on Windows, recompiling only the files that have genuinely changed or whose dependencies have changed.