[cmake-developers] Feature suggestion: auto-create missing files
Florent Castelli
florent.castelli at gmail.com
Tue Apr 11 18:06:08 EDT 2017
It is easy enough in recent CMake versions to list all the subdirectories and their targets recursively.
Then you can list their files, check if they exist and create them if you want.
It can be done with a macro in your project and doesn’t need upstream support.
The next possible solution would be to create the file on disk and use a glob to list all the files.
You would need to rerun CMake manually whenever you add a file.
I would say that both solutions are not really good, even dangerous.
But if you really want them, you can pick your poison.
/Florent
> On 11 Apr 2017, at 21:28, Alexander Neundorf <neundorf at kde.org> wrote:
>
> On 2017 M04 11, Tue 11:52:52 CEST Brad King 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.
>>
>>> 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 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.
>>
>>> 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).
>
> personally I'm not convinced.
> Technically it would violate the "the source dir is read-only" rule.
> A typo would generate files. With multiple build dirs the behaviour will be
> slightly different in the two dirs.
> ...not very strong arguments, but OTOH touching the file manually is also not
> too complicated.
>
> Alex
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake-developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20170412/776cc95b/attachment-0001.html>
More information about the cmake-developers
mailing list