[CMake] Use of ADD_CUSTOM_COMMAND

Michael Hertling mhertling at online.de
Wed Apr 20 11:20:20 EDT 2011


On 04/20/2011 05:40 AM, Fraser Hutchison wrote:
> Hi Gib,
> 
> Try the following:
> 
> GET_TARGET_PROPERTY(FUBAR_EXE fubar LOCATION)
> ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD COMMAND ${CMAKE_COMMAND} -E 
> copy ${FUBAR_EXE} somepath)
> 
> Cheers,
> 
> Fraser.

Don't use the obsolete LOCATION property since it might have subtle
side effects, see [1]. Instead, use the new "generator expressions"

ADD_CUSTOM_COMMAND(TARGET fubar POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:fubar> somepath)

or follow the advice Michael W. has provided in the meantime.

Regards,

Michael H.

[1] http://www.mail-archive.com/cmake@cmake.org/msg33675.html

> On 20/04/2011 03:31, Gib Bogle wrote:
>> I'm a real cmake novice, and I find the cmake documentation hard to 
>> follow, because it assumes that you know what you're doing (and I 
>> obviously don't) and doesn't provide examples.  I simply want to add 
>> to CMakeLists.txt an instruction to copy the executable created to 
>> another directory.  I gather that I want to use ADD_CUSTOM_COMMAND, 
>> and naively I thought this might do it:
>>
>> ADD_CUSTOM_COMMAND( TARGET fubar POST_BUILD COMMAND copy fubar.exe 
>> somepath/fubar.exe)
>>
>> but although this doesn't trigger a cmake error, it doesn't do 
>> anything either, and doesn't even seem to change Makefile.  Can 
>> someone point me in the right direction?  I'm using MinGW tools on 
>> Windows.
>>
>> Thanks
>> Gib


More information about the CMake mailing list