2012/2/20 Andrea Crotti <[email protected]>:
> 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
--

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