[CMake] add_custom_command question
Łukasz Tasz
lukasz at tasz.eu
Thu Oct 20 14:07:36 EDT 2011
Hi Michael, Hi All
Thanks a lot for answer,
I tried something else, let's assume that we have some output,
then we are registering target which is dependend on ouptut -
registered target is responsible to provide output in a global scope.
I have other cmake lists, in which I have some targets that are
referring output.
My idea is to recreate/replicate output in other cmakelists which will
point to global target and create the referenced output.
according to docs it should be avaliable:
If DEPENDS specifies any target (created by an ADD_* command) a
target-level dependency is created to make sure the target is built
before any target using this custom command. Additionally, if the
target is an executable or library a file-level dependency is created
to cause the custom command to re-run whenever the target is
recompiled.
but somehow it does not work for cmake 2.6 and 2.8, dependencies to
custom target are not taken, to executables works fine:
example:
add_custom_target(TARGET generator
COMMAND touch aaa.cxx
COMMENT generate file
)
add_custom_command(OUTPUT aaa.cxx
COMMAND echo "command"
DEPENDS generator bar
This does not work^^^^^^^^^^^^^^^^^^^^^^^^^^^
COMMENT "i'm just echo"
)
add_executable(bar EXCLUDE_FROM_ALL c.cxx)
add_executable(foo aaa.cxx)
error is:
[ 33%] Built target bar
make[2]: *** No rule to make target `../generator', needed by `aaa.cxx'. Stop.
make[1]: *** [CMakeFiles/foo.dir/all] Error 2
Why cmake assumes that generator is an output, since it is already
valid target...
thanks for help, regards
Lukasz
2011/10/20 Michael Hertling <mhertling at online.de>:
> On 10/20/2011 12:37 PM, Łukasz Tasz wrote:
>> Hi all,
>>
>> In my cmake project I have few commands that are creating outputs.
>>
>> But Unfortunately those outputs are used across many directories.
>>
>> So my question is what's the real scope of output_command? only
>> Current_CmakeLists.txt?
>
> Yes, a custom command's OUTPUT must be referred to by an ADD_LIBRARY/
> EXECUTABLE() or an ADD_CUSTOM_TARGET() within the same CMakeLists.txt
> file; otherwise, it is silently ignored.
>
>> Can I somehow make make_target that is creating output registered in
>> global scope?
>
> Mention the custom command's OUTPUT in a custom target's DEPENDS clause
> in the same CMakeLists.txt, and use ADD_DEPENDENCIES() to ensure that
> the custom target is triggered at the proper time. Note the issues
> w.r.t. relative paths in this regard.
>
>> I'm familiar with pattern of attaching custom target with custom
>> command, but I would like to avoid managing separately target, and
>> output name.
>
> AFAIK, there's currently no chance to do this in another way, but a
> custom command can generate more than one output file, and a custom
> target can refer to more than one prerequisite, so you can possibly
> aggregate and don't need an own target/command per output file.
>
>> thanks in advance
>> Lukasz
>
> Regards,
>
> Michael
> --
>
> 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
--
Lukasz Tasz
More information about the CMake
mailing list