On 09/17/2010 12:04 PM, Chris Hillery wrote:
> 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.

You can use ADD_CUSTOM_COMMAND()'s TARGET signature and POST_BUILD option:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(CUSTOM_REMOVE C)
ADD_CUSTOM_COMMAND(
    OUTPUT main.c
    COMMAND echo "int main(void){return 0;}" > main.c
    VERBATIM)
ADD_EXECUTABLE(main main.c)
ADD_CUSTOM_COMMAND(
    TARGET main
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E remove main.c)

This removes main.c right after main has been built.

Regards,

Michael

> 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.aldr...@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

Reply via email to