c++ - cmake add_custom_command failure, target gets deleted -
i building test executable using cmake. during build process, run executable, returns whether tests pass or not. if not, build fail. however, when use add_custom_command(... post_build ... )
, , use makefile
generator, test executable deleted (explain in question: why gnu make delete file).
is there way have cmake treat executable .precious
, or otherwise change cmakelists.txt such executable doesn't deleted if tests fail?
for reference, cmakelist.txt looks following (simplified actual):
add_executable(unittest unittest.cpp) add_custom_command(target unittest post_build command $<target_file:unittest>)
the solution alluding use add_custom_target
instead of add_custom_command
. while not delete executable if test fails , build process whole fails if rununittest fails, target not built result of building unittest target specifically.
add_executable(unittest unittest.cpp) add_custom_target(rununittest unittest command $<target_file:unittest> depends unittest)
Comments
Post a Comment