I want to have one top level custom target, and nested submodules which are able to extend this already existed target by adding/binding custom_command to it. For now I face a problem: if add_custom_command(TARGET target_name ...)
is used not in a file where the target is defined (target is defined on top level CMakeLists.txt), then this custom_command is simply ignored.
Details:
1) custom_target created on the top-level CMakelists.txt
cmake_minimum_required(VERSION 2.8)
add_custom_target(custom_tg
COMMAND ls > custom_target.txt
)
add_custom_command(TARGET custom_tg
COMMAND ls > custom_command1.txt
)
add_subdirectory(sub)
2) In subdirectory "sub" there is other CMakeLists.txt (module) which I was hoping is able to extend the existed target with custom command.
add_custom_command(TARGET custom_tg
COMMAND ls > custom_command2.txt
)
3) When I create build directory and run
cmake .. && make custom_tg
the output files are custom_target.txt and custom_command1.txt, but there is no custom_command2.txt, and that's actually my problem is.
If I look into build/CMakeFiles/custom_tg.dir/build.make I see no mention about custom_command2.txt there. Here is content of build.make file: http://pastebin.com/zVVS4sYL.
Actually I can't find any mention about custom_command2.txt in tree of files generated by Cmake, and this looks weird to me.
Looking forward for you help.