1

My project structure is https://github.com/yumyai/cmake-sample. It is similar to project in this thread CMake: Project structure with unit tests.

Whenever I add include(CTest) into a top-level CMakeLists.txt, I couldn't build a test file (make test does not build anything). But if I comment include(CTest) out, I could build unit test exec using make test just fine.

Is this normal behaviour or I forgot something ?

Community
  • 1
  • 1
Tg.
  • 5,608
  • 7
  • 39
  • 52

1 Answers1

1

Your sample looks fine - it should work with or without the include(CTest) line.

It may be that nothing is recompiled after changing the CMakeLists.txt, so it appears that make test is doing nothing?

If you omit the include(CTest) line and do make test, then ctest -N should output something like:

 Test project <path to build>

 Total Tests: 0

If you add include(CTest) line and do make test, then ctest -N should output something like:

 Test project <path to build>
 Test #1: SqrTest

 Total Tests: 1

This should be the only difference - that the test is registered with CTest or not. In each case, if make test has previously been run successfully, then the only effect make test will really have is to rerun CMake. If the changes in the CMakeLists.txt between runs don't affect the actual test target, it won't be rebuilt.

Fraser
  • 74,704
  • 20
  • 238
  • 215
  • I tried that but it does not work. (`ctest -N` shows number of the test just right but `make test` still fail as describe in topic). Did you try that on top-level directory ? I build in ./build directory instead of at top-level of project. Oh, and "nothing is built" as a no executable was built at all. I clear everything in each iteration to make sure that nothing amiss. – Tg. Apr 01 '13 at 16:48
  • Ah - I never spotted this since it's not an issue on Windows with MSVC, but you shouldn't call your target "test". Try changing the name to e.g. "Test" or "my_test". (See http://stackoverflow.com/a/736838/424459). I'll update my other answer to reflect this. Also, you need to remove the extra `Sqr` from the `add_executable(demo main.cpp Sqr)` in src/CMakeLists.txt – Fraser Apr 01 '13 at 19:35