[cmake-developers] Feature suggestion: auto-create missing files

Petr Kmoch petr.kmoch at gmail.com
Tue Apr 11 12:16:16 EDT 2017


Thanks for the quick response, Brad.

On 11 April 2017 at 17:52, Brad King <brad.king at kitware.com> wrote:

> On 04/11/2017 11:41 AM, Petr Kmoch wrote:
> > Currently, adding a new source file to a CMake-controlled project
> > means doing two things: creating the file on disk, and adding it
> > to the relevant CMakeList add_library() or add_executable() call.
>
> I view this as a matching pair with an implicit sanity check.
>

I sometimes have very deep directory hierarchies (files are 3+ directory
levels below the CMakeLists.txt), with interface header, implementation
header, and implementation source in three different paths down that
hierarchy. Adding one class means adding three very similar lines of CMake
code, and then having to navigate three separate directory paths for adding
the files.


>
> > switch from current behaviour of "error out if source file is not found"
> > to "create empty source file if it's not found."
>
> So a typo in the `CMakeLists.txt` file leads to silent creation of a
> source file instead of an error message?
>

That's why I would make it strictly opt-in. We could even get rid of the
initialisation variable and keep it under full control of the project.


>
> That said, I can see how the proposed feature might be useful when
> iteratively developing in an IDE.  Add the file to `CMakeLists.txt`,
> reconfigure, and open the new (now existing) file to edit in the IDE.
>

Yes, I'm coming from an IDE background (VS, to be precise). It would be
quite helpful there. I've bounced the idea with other people in my team,
and they agreed it would be useful.


>
> > Is this something that would be acceptable into CMake? Any comments?
>
> I'd like to hear more opinions from others before considering it
> upstream.  It feels like a pretty personal workflow right now, and
> can be implemented in CMake code already (perhaps with the `SOURCES`
> target property to avoid separate lists).
>
> If this were to be done I'd first like to see a policy introduced to
> get rid of the magic extension guessing we do now.  Without knowing
> the full file name with confidence we wouldn't be able to create it.
>

I'm perfectly fine waiting for broader comments. As to extension guessing,
right now the creation happens after that step in my prototype code, and
simply uses the name verbatim as supplied. I'm perfectly willing to create
such a guess-disabling policy, though. I've never used the guessing
functionality anyway.

Petr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20170411/b663fad5/attachment.html>


More information about the cmake-developers mailing list