[CMake] adding a custom command with the file name as a target
Jim Newsome
jnewsome at cmu.edu
Fri Mar 11 12:05:16 EST 2011
Unfortunately it seems that the target needs to have a different name
from its dependencies. When building I get:
make[2]: Circular CMakeFiles/hello.bin <- hello.bin dependency dropped.
Another workaround I thought of is to change the output filename to,
e.g., _hello.bin and have a command in the target to move _hello.bin
to hello.bin. Unfortunately this forces _hello.bin to be regenerated
every time. I suppose I could work around _that_ by copying instead of
moving, but that's getting fairly ugly.
On Fri, Mar 11, 2011 at 11:56 AM, Tyler <tyler at cryptio.net> wrote:
> The target in the Makefile is created with the add_custom_target()
> call. So just change yours to:
>
> add_custom_target(hello.bin ALL DEPENDS hello.bin)
>
> hth,
> tyler
>
> On Fri, Mar 11, 2011 at 7:58 AM, Jim Newsome <jnewsome at cmu.edu> wrote:
>> I'd like to do something like add_custom_command, with the output file
>> name as a target in the generated makefile. Is there an elegant way of
>> doing this?
>>
>> The closest I've come is:
>> add_executable (hello hello.c)
>> add_custom_command(OUTPUT hello.bin
>> COMMAND objcopy --output-format=binary hello hello.bin
>> DEPENDS hello
>> COMMENT "objcopying hello to hello.bin")
>> add_custom_target(bin ALL DEPENDS hello.bin)
>>
>> However, the target name in the generated makefile is 'bin' rather
>> than 'hello.bin'. Is there a way to make 'hello.bin' itself a target
>> in the generated makefile?
>
More information about the CMake
mailing list