[CMake] Execution order

Chris Hillery chillery-cmake at lambda.nu
Fri Sep 17 06:04:49 EDT 2010


The message() and file(REMOVE) commands will be executed when you run CMake.
The command to generate the .cpp file won't be executed until you run make.
That's why it's still around after you're done.

You can't really do exactly what you want here very easily; you'd need to
have a separate custom command to delete the file after the build is
complete, and I'm not sure how to set up the dependencies to automate that
for you.

Why do you want this? Wouldn't it make more sense to generate the source
file into the binary directory and just leave it there? Your
add_custom_command() and list(APPEND SRCS) steps below will do this if you
just change the OUTPUT to "${CMAKE_CURRENT_BINARY_DIR}/SourceFileInfo.cpp".
This would have the added benefit of not forcing a rebuild of
SourceFileInfo.o every time you run "make".

Ceej
aka Chris Hillery

On Fri, Sep 17, 2010 at 2:53 AM, David Aldrich <David.Aldrich at eu.nec.com>wrote:

>  Hi
>
> I want to generate a source file ‘SourceFileInfo.cpp’, then build a library
> and then delete the generated file.
>
> So I wrote:
>
> <snip>
>
> add_custom_command (
>   OUTPUT SourceFileInfo.cpp
>   COMMAND ../VersionInfo/_gnuRelease/versionInfo . KERNEL
>   DEPENDS ${SRCS}
>   COMMENT "Generating SourceFileInfo.cpp"
>   VERBATIM)
>
> list(APPEND SRCS SourceFileInfo.cpp)
>
> add_library( Kernel STATIC ${SRCS} )
>
> message("Removing file")
> file( REMOVE SourceFileInfo.cpp )
>
> But the message ‘Removing file’ appears as the first action when executing
> make and the file remains after make has finished.
>
> I guess that one can’t interpret a CMakeLists.txt file sequentially, just
> like you can’t interpret a makefile sequentially.
>
> What am I doing wrong?
>
> Where can I find an explanation of CMake command ordering?
> Best regards
> David
>
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100917/a147dbf3/attachment.htm>


More information about the CMake mailing list