1

I am using CMake and Linux to run my test cases from CMakeLists.txt using the following command:

add_custom_command( TARGET  tests
                POST_BUILD
                COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests
                )

This only executes if the code has been changed, is there anyway to do this so that it will always run the binary?

For the solution, I had to do this:

add_custom_command( OUTPUT tests.a
                POST_BUILD
                COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests
                )

add_custom_target( runTests
                ALL
                DPEENDS tests.a
                )
user1876942
  • 1,411
  • 2
  • 20
  • 32
  • While I certainly encourage the spirit of testing, do you really think it's a good idea to *always* run them on *every* build, as opposed to everytime you're running `make test` (or `ctest`) explicitly? – DevSolar Nov 27 '14 at 10:22
  • Yes, it is behind a test flag. The problem is that the binary only executes when the code is changed. If someone else changes their code and mine is the same then the binary is not executed and it upsets the integration system. – user1876942 Nov 27 '14 at 10:25

1 Answers1

3

Use add_custom_target instead. It is executed at every build. http://www.cmake.org/cmake/help/v3.0/command/add_custom_target.html

add_custom_target( run_test ALL
                   COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests )
user1766169
  • 1,932
  • 3
  • 22
  • 44