don't auto-clean generated files?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

don't auto-clean generated files?

Aaron Turner-2
I'm look for a way to tell cmake to not automatically remove certain
auto-generated files when the 'clean' target is invoked.

Basically I have:

    add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
        COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
        DEPENDS tcpbridge_opts.def
    )

And of course, other files depend on tcpbridge_opts.[ch]

The problem is that I don't want tcpbridge_opts.[ch] deleted when
'make clean' is run.

Suggestions?



--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing and replay tools for Unix & Windows
Those who would give up essential Liberty, to purchase a little temporary
Safety, deserve neither Liberty nor Safety.
    -- Benjamin Franklin
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: don't auto-clean generated files?

Alan W. Irwin
On 2009-09-06 17:59-0700 Aaron Turner wrote:

> I'm look for a way to tell cmake to not automatically remove certain
> auto-generated files when the 'clean' target is invoked.
>
> Basically I have:
>
>    add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
>        COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
>        DEPENDS tcpbridge_opts.def
>    )
>
> And of course, other files depend on tcpbridge_opts.[ch]
>
> The problem is that I don't want tcpbridge_opts.[ch] deleted when
> 'make clean' is run.
>
> Suggestions?

From the cmake man page, a directory property that might be useful to you is
CLEAN_NO_CUSTOM.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: don't auto-clean generated files?

Aaron Turner-2
On Sun, Sep 6, 2009 at 8:09 PM, Alan W. Irwin<[hidden email]> wrote:

> On 2009-09-06 17:59-0700 Aaron Turner wrote:
>
>> I'm look for a way to tell cmake to not automatically remove certain
>> auto-generated files when the 'clean' target is invoked.
>>
>> Basically I have:
>>
>>   add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
>>       COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
>>       DEPENDS tcpbridge_opts.def
>>   )
>>
>> And of course, other files depend on tcpbridge_opts.[ch]
>>
>> The problem is that I don't want tcpbridge_opts.[ch] deleted when
>> 'make clean' is run.
>>
>> Suggestions?
>
> From the cmake man page, a directory property that might be useful to you is
> CLEAN_NO_CUSTOM.

That actually does work... although making it global for a directory
is a bit unfortunate.  Too bad this isn't per-file.

Thanks!

--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing and replay tools for Unix & Windows
Those who would give up essential Liberty, to purchase a little temporary
Safety, deserve neither Liberty nor Safety.
    -- Benjamin Franklin
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: don't auto-clean generated files?

Alexander Neundorf-3
In reply to this post by Aaron Turner-2
On Monday 07 September 2009, Aaron Turner wrote:

> I'm look for a way to tell cmake to not automatically remove certain
> auto-generated files when the 'clean' target is invoked.
>
> Basically I have:
>
>     add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
>         COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
>         DEPENDS tcpbridge_opts.def
>     )
>
> And of course, other files depend on tcpbridge_opts.[ch]
>
> The problem is that I don't want tcpbridge_opts.[ch] deleted when
> 'make clean' is run.

Why don't you want this file to be deleted ?
Maybe an ADD_CUSTOM_TARGET() would be more suitable ?

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: don't auto-clean generated files?

Aaron Turner-2
On Mon, Sep 7, 2009 at 1:00 PM, Alexander
Neundorf<[hidden email]> wrote:

> On Monday 07 September 2009, Aaron Turner wrote:
>> I'm look for a way to tell cmake to not automatically remove certain
>> auto-generated files when the 'clean' target is invoked.
>>
>> Basically I have:
>>
>>     add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
>>         COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
>>         DEPENDS tcpbridge_opts.def
>>     )
>>
>> And of course, other files depend on tcpbridge_opts.[ch]
>>
>> The problem is that I don't want tcpbridge_opts.[ch] deleted when
>> 'make clean' is run.
>
> Why don't you want this file to be deleted ?

Because, counter to my general rule of thumb of never committing
generated code, I've decided to check in some generated code.  These
files also need to be shipped in the source tarballs.  Long story
short: The templates used to generate the files is *very* particular
about what version of autogen is used and I find I get far too many
users checking out the code who have problems when they use the wrong
version.

> Maybe an ADD_CUSTOM_TARGET() would be more suitable ?

I was under the impression that the outputs of targets are always
deleted when 'make clean' is run... at least that's how it seems to
work.

--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing and replay tools for Unix & Windows
Those who would give up essential Liberty, to purchase a little temporary
Safety, deserve neither Liberty nor Safety.
    -- Benjamin Franklin
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: don't auto-clean generated files?

Alexander Neundorf-3
On Tuesday 08 September 2009, Aaron Turner wrote:

> On Mon, Sep 7, 2009 at 1:00 PM, Alexander
>
> Neundorf<[hidden email]> wrote:
> > On Monday 07 September 2009, Aaron Turner wrote:
> >> I'm look for a way to tell cmake to not automatically remove certain
> >> auto-generated files when the 'clean' target is invoked.
> >>
> >> Basically I have:
> >>
> >>     add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
> >>         COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
> >>         DEPENDS tcpbridge_opts.def
> >>     )
> >>
> >> And of course, other files depend on tcpbridge_opts.[ch]
> >>
> >> The problem is that I don't want tcpbridge_opts.[ch] deleted when
> >> 'make clean' is run.
> >
> > Why don't you want this file to be deleted ?
>
> Because, counter to my general rule of thumb of never committing
> generated code, I've decided to check in some generated code.  These
> files also need to be shipped in the source tarballs.  Long story
> short: The templates used to generate the files is *very* particular
> about what version of autogen is used and I find I get far too many
> users checking out the code who have problems when they use the wrong
> version.

That's indeed what I was assuming, and for this case add_custom_target()
should be used.

> > Maybe an ADD_CUSTOM_TARGET() would be more suitable ?
>
> I was under the impression that the outputs of targets are always
> deleted when 'make clean' is run... at least that's how it seems to
> work.

With ADD_CUSTOM_TARGET() no output files are specified, so they cannot be
cleaned.
Here's a simple example:
$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 2.6)

add_custom_target(MakeMyFiles COMMAND touch abc )

add_executable(foo main.c)
$

This gives you a custom target "MakeMyFiles", which is only executed if you
explicitely build it. And I think that's also what you actually want.
I would suggest to have the custom target generate the files in the build
tree, and then you can do with them what you want. You can copy them into the
source tree, check them into the version control system, etc.

If you use add_custom_command() you will always have the rule to regenerate
the files in your makefiles, and so your users can still get the problem
(since the custom command would *have* to depend on the input file) if for
whatever reason their template file got a newer date than the generated file.

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: don't auto-clean generated files?

Aaron Turner-2
On Tue, Sep 8, 2009 at 10:36 AM, Alexander
Neundorf<[hidden email]> wrote:

> On Tuesday 08 September 2009, Aaron Turner wrote:
>> On Mon, Sep 7, 2009 at 1:00 PM, Alexander
>>
>> Neundorf<[hidden email]> wrote:
>> > On Monday 07 September 2009, Aaron Turner wrote:
>> >> I'm look for a way to tell cmake to not automatically remove certain
>> >> auto-generated files when the 'clean' target is invoked.
>> >>
>> >> Basically I have:
>> >>
>> >>     add_custom_command(OUTPUT tcpbridge_opts.c tcpbridge_opts.h
>> >>         COMMAND ${AUTOGEN} -L tcpedit tcpbridge_opts.def
>> >>         DEPENDS tcpbridge_opts.def
>> >>     )
>> >>
>> >> And of course, other files depend on tcpbridge_opts.[ch]
>> >>
>> >> The problem is that I don't want tcpbridge_opts.[ch] deleted when
>> >> 'make clean' is run.
>> >
>> > Why don't you want this file to be deleted ?
>>
>> Because, counter to my general rule of thumb of never committing
>> generated code, I've decided to check in some generated code.  These
>> files also need to be shipped in the source tarballs.  Long story
>> short: The templates used to generate the files is *very* particular
>> about what version of autogen is used and I find I get far too many
>> users checking out the code who have problems when they use the wrong
>> version.
>
> That's indeed what I was assuming, and for this case add_custom_target()
> should be used.
>
>> > Maybe an ADD_CUSTOM_TARGET() would be more suitable ?
>>
>> I was under the impression that the outputs of targets are always
>> deleted when 'make clean' is run... at least that's how it seems to
>> work.
>
> With ADD_CUSTOM_TARGET() no output files are specified, so they cannot be
> cleaned.
> Here's a simple example:
> $ cat ../CMakeLists.txt
> cmake_minimum_required(VERSION 2.6)
>
> add_custom_target(MakeMyFiles COMMAND touch abc )
>
> add_executable(foo main.c)
> $
>
> This gives you a custom target "MakeMyFiles", which is only executed if you
> explicitely build it. And I think that's also what you actually want.
> I would suggest to have the custom target generate the files in the build
> tree, and then you can do with them what you want. You can copy them into the
> source tree, check them into the version control system, etc.
>
> If you use add_custom_command() you will always have the rule to regenerate
> the files in your makefiles, and so your users can still get the problem
> (since the custom command would *have* to depend on the input file) if for
> whatever reason their template file got a newer date than the generated file.

Well proper dependency tracking is a good thing IMHO.  That's why I
use a build system like cmake- so I don't have to remember what files
have changed and the ripple effects of those changes.

Honestly I'm totally OK with breakage for users foolish enough to
change a timestamp on the template file- who knows, maybe they know
what they're doing.  They can always do an 'svn revert' to put things
back the way they were if it breaks.  I know I'm stupid enough to
forget regenerating the files after making a slight change. :)

Anyways, I have a working solution it seems- just not very elegant
since it's semi-global.  I'll open up a feature request to make an
equivalent CLEAN_NO_CUSTOM property for individual files.


--
Aaron Turner
http://synfin.net/
http://tcpreplay.synfin.net/ - Pcap editing and replay tools for Unix & Windows
Those who would give up essential Liberty, to purchase a little temporary
Safety, deserve neither Liberty nor Safety.
    -- Benjamin Franklin
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake