[CMake] more targets to run in parallel

Eric Noulard eric.noulard at gmail.com
Mon Feb 20 06:51:39 EST 2012


2012/2/20 Andrea Crotti <andrea.crotti.0 at gmail.com>:
> On 02/17/2012 03:35 PM, Andrea Crotti wrote:
> ..
>
> I can make the question much simpler, is it possible to generate targets
> dynamically with CMake?

As far as I know you can "generate" targets at CMake-time but not at build-time.
So from my point of view this "computed target" but not really "dynamic target".

> I was trying the following (nonsense), a simple loop over a list
> that first generates a custom command and another loop
> that generates a target for every command.
>
> set(target_list uno due tre)
>
> foreach (t ${target_list})
>  set(t_cmd ${t}.out)
>  add_custom_command(OUTPUT ${t_cmd}
>    COMMAND "ls ${t} > ${t_cmd}"
>    )
> endforeach ()
>
> foreach (t ${target_list})
>  message("analyzing target ${t}")
>  set(t_cmd ${t}.out)
>  add_custom_target(${t}
>    COMMAND ${t_cmd}
>    )

This cannot work because "${t_cmd}" is NOT a command
this is the OUTPUT of a custom command (which is't named).


> I would suppose that this should work but it doesn't:
>
> make[3]: uno.out: Command not found

Precisely.

> Any idea why?

if you want your target to trigger the command you may
add the OUTPUT of the command as a dependency of the target.

add_custom_target(${t}
    DEPENDS ${t_cmd}
                            )


-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list