I have custom target to run my test after test target is built
add_executable( my_unit_test
${SRC}
)
Before running the test I patch elf
add_custom_command(
TARGET my_unit_test POST_BUILD
COMMENT "=================== PATCH UNIT TEST ELF ==================="
COMMAND patchelf --set-interpreter /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 my_unit_test
VERBATIM
)
And this is the target to run test
add_test(
NAME UT
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/my_unit_test
)
add_custom_target( run_ut_tests ALL
DEPENDS my_unit_test
)
add_custom_command( TARGET run_ut_tests POST_BUILD
COMMENT "=================== RUN UNIT TESTS ==================="
COMMAND ctest ARGS --output-on-failure
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
The problem is the test runs twice. What is the mistake here ?