views:

72

answers:

2

It's a well known problem that executing make "test" doesn't build the tests as discussed here. As suggested, the problem can be partly solved with the artificial target "check". I want to know how I can force building of tests when i call "make Nightly".

What I've done so far:

  add_custom_target(buildtests)
  add_custom_target(check COMMAND "ctest")
  add_dependencies(check buildtests)
  add_dependencies(Nightly buildtests)

  add_dependencies(buildtests Test1)
  ...
  add_dependencies(buildtests TestN)

Now "make check" builds an runs the tests, but "make Nightly"

  • builds the tests
  • updates the repo to CTEST_NIGHTLY_START_TIME
  • builds all other targets
  • runs the (now outdated) tests
A: 

If you look at the output of,

cmake --help-command add_custom_target

It mentions the ALL argument, "If the ALL option is specified it indicates that this target should be added to the default build target so that it will be run every time". You would need to add this argument to your custom target, and the Nightly target runs a make to build everything in the default build target. So the following should do it,

add_custom_target(buildtests)

Your other option would be to write a custom CTest script, which gives you much finer grained control of the build and testing of your project.

Marcus D. Hanwell
Your right, it was actually my own fault for calling: add_subdirectory(test EXCLUDE_FROM_ALL)The solution was to change it to if(LEAVE_TEST_IN_ALL_TARGET) add_subdirectory(test) else() add_subdirectory(test EXCLUDE_FROM_ALL) endif()and then call cmake ${SRC_DIR} -DLEAVE_TEST_IN_ALL_TARGET=ON make Nightly
bgp2000
A: 

You're right, it was actually my own fault for calling:

add_subdirectory(test EXCLUDE_FROM_ALL)

The solution was to change it to

if(LEAVE_TEST_IN_ALL_TARGET) 
  add_subdirectory(test) 
else() 
  add_subdirectory(test EXCLUDE_FROM_ALL) 
endif() 

and then call

cmake ${SRC_DIR} -DLEAVE_TEST_IN_ALL_TARGET=ON make Nightly
bgp2000