Option for assuming source files exit (or skipping missing source files) (-DCMAKE_IGNORE_MISSING)
As deterministic builds become more prevalent, Dockerfiles have quickly become commonplace for describing the build process for a container image.
For projects that use CMake, this becomes a bit of a burden as the generation of the build directory is dependent upon the source files in the COPY
directive of a Dockerfile. This is because CMake will error out with Cannot find source file: foo.c
if foo.c
is not actually there.
This means that every single change, large or small, results in a reconfiguration. Since Docker doesn't support mount volumes during boot, there's no way to cache a build directory via an externalized volume to speed up incremental building during development (though I would cede to the argument that that is the real issue that needs fixing).
Would it be possible to add a command line option or build argument for assuming source files exist at the time of configuration? Or, perhaps more apt, specifying a list of paths (or path bases, e.g. src/
) to assume are properly populated at the configuration time.
For example:
$ ls
3rdpty/ CMakeLists.txt Dockerfile src/
$ ls src/
bar.c
$ cat CMakeLists.txt
project (foo-bar)
add_executable (foo-bar src/foo.c src/bar.c)
$ mkdir build
$ cd build
build $ cmake ..
-- ...
CMake Error at CMakeLists.txt:11 (add_executable):
Cannot find source file:
src/foo.c
build $ cmake .. -DCMAKE_IGNORE_MISSING=src/foo.c # or...
build $ cmake .. -DCMAKE_IGNORE_MISSING=src/
-- ...
-- Generating done
-- Build files have been written to: /src/foo-bar/build
This would allow the Docker build to cache the configuration of the project as a single layer that only changes if the CMakeLists.txt
were to change.
Further, nested projects that employ the use of add_subdirectory()
would be able to cleverly craft a Dockerfile to do incremental building of dependencies in a way that makes sense for both production builds as well as local development/incremental builds.