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.
Attached are two test cases that have no 'C/C++' code (only
CMakeLists.txt) and simply execute an echo of A or B
when running the 'static checks'. The static check is defined in a
module and is identical for both tests.
The tests are compressed in .7z format so please let me know if that's
not appropriate.
The simple-test should succeed, the nested-test should fail.
My questions are:
(1) Is this correct? Should it fail in the nested case? My perception
is that it _used_ to work on earlier versions of CMake (2.8.6 for
example)
(2) Is there a better way?
I have already worked around this by using an add_custom_command and
add_dependencies but that solution is somewhat clunky and clutters
the set of targets.
Thanks in advance,
--
Best Regards,
Brett Delle Grazie
add_custom_target-test.7z
Description: Binary data
-- 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
