I am considering switching a cross platform project from separate build management systems in Visual C++, XCode and makefiles to CMake.
One essential feature I need is to add automatically all files in a directory to a target. While this is easy to do with make, it is not easily doable with Visual C++ and XCode (correct me if I am wrong). Is it possible to do it in directly in CMake? How?
As of CMake 3.1+ the developers strongly discourage users from using
file(GLOBorfile(GLOB_RECURSEto collect lists of source files.See the documentation here.
There are two goods answers ([1], [2]) here on SO detailing the reasons to manually list source files.
It is possible. E.g. with
file(GLOB:Note that this requires manual re-running of
cmakeif a source file is added or removed, since the generated build system does not know when to ask CMake to regenerate, and doing it at every build would increase the build time.As of CMake 3.12, you can pass the
CONFIGURE_DEPENDSflag tofile(GLOBto automatically check and reset the file lists any time the build is invoked. You would write:This at least lets you avoid manually re-running CMake every time a file is added.