On 12 September 2012 14:50, Rolf Eike Beer <[email protected]> wrote: > Am 2012-09-12 12:36, schrieb Brett Delle Grazie: > >> Hi, >> >> I've come across some strange behaviour when using add_custom_target and >> an >> add_custom_command( PRE_BUILD or PRE_LINK ) in nested projects. >> >> We have a number of static analysis checks that were working using >> cppcheck. >> The technique was to add a non-automatic global custom target called >> 'all_static_checks' like: >> >> add_custom_target(all_static_checks) >> set_target_properties(all_static_checks PROPERTIES EXCLUDE_FROM_ALL TRUE) >> >> This make target 'all_static_checks' is run by the build system and >> generates output from >> the static analysis tool on a per-project basis. >> >> For each sub-project we would: >> add_custom_command(TARGET all_static_checks PRE_BUILD >> COMMAND custom command goes here >> WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" >> VERBATIM) >> >> This works when the add_custom_command and the add_custom_target are >> defined within the same CMakeLists.txt >> But it fails in the nested case (when the add_custom_command part is >> added in a sub-directory). In the nested case >> no PRE_BUILD commands are executed. > > > Targets and commands added by add_custom_target()/add_custom_command() may > only be referenced from the same directory.
Thank you, that explains it. The documentation states that 'DEPENDS' of add_custom_target must be specified in the same CMakeLists.txt but there is no such stipulation on add_custom_command( PRE_BUILD). I'm not doubting you, I simply remember it working before... > > Why don't you just do add_test()? Because I need to capture the stdout / stderr of the tests for post-processing by CI system and you can't do that and get sane responses from ctest (without nesting the invocation via execute_process). Plus I want to separate tests from static analysis for various reasons (we run them at different times). As far as I know there is no way to 'group' tests at this time (to be fair I haven't pursued this). Thanks for your time. > > Eike > -- > > 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 -- Best Regards, Brett Delle Grazie -- 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
