[cmake-developers] Listing source-tree files encountered (was: Wrapping functions in CMake)

Brad King brad.king at kitware.com
Wed Jul 15 09:10:57 EDT 2015


On 07/09/2015 01:35 PM, Clifford Yapp wrote:
> 1.  First, we need to maintain a list of all files in the source
> repository that are known to the build system.  To do this we maintain
> a global list of files, define a custom CMAKEFILES command to allow us
> to manually specify miscellaneous files as "known", and override all
> of the primary target creating commands to add their files to the list
> (for example, add_executable is passed a list of source files, and all
> of those files are automatically added to the "known files" list by
> the function override of add_executable.)  This list is used for both
> our "make-clean-in-src-dir" feature and our distcheck build target
> (which does a number of verification steps using the version control
> system, the build system and the files-on-filesystem information to
> make sure the build logic is current.)

These days it is the job of version control tools to know what files
are part of the source and what files are not.  Commands like "git clean"
are then responsible for cleaning out a source tree, not the build system.

CMake is mainly designed for out-of-source builds where nothing in the
source tree is touched at all.  This makes distclean unnecessary.
We support in-source builds for end-user convenience when installing
a project from a source tarball, but in general development should
always be done with out-of-source builds to keep the source pristine.

> 1.  Have CMake internally maintain a list (or maybe per-command lists
> for more flexibility) of all files with paths relative to the root
> source directory that have been "observed" by add_executable,
> add_library, add_custom_target, add_subdirectory, and configure_file
> that can be accessed via CMake variables

Many of the source file locations are not actually determined until
generate time, so a configuration-time list is not possible to
implement reliably in general.  Maintaining the list would force
source file locations to be finalized too early.

-Brad


More information about the cmake-developers mailing list