Hi all, I've been searching for a way to implement "make check" the GNU Autotools way. That is: tests are not compiled and linked as part of the "all" target, but as part of the "check" target.
I followed section 10.5 "Using CTest to Drive Complex Tests" of the book "Mastering CMake" and I looked at the Tests directory of the CMake distribution. From that I created my little toy project "Hello". Now the problem is: it doesn't work. For details, see below. It appears that ctest is running cmake (again), but it doesn't read the CMakeLists.txt files (should it?). Hence, I get all kind of warnings, like "No cmake_minimum_required command is present." And then, ctest fails, because it cannot find the executable "t_hello", which should have been built by ctest. At least, it is my understanding that it should have been built, since that was the purpose of using this complex add_test() statement. Could someone explain what I'm doing wrong? Many thanks in advance. Best regards, Marcel Loose. Details follow: ------------------------------------------------------------------------ $ cd hello $ cat CMakeLists.txt project(Hello) cmake_minimum_required(VERSION 2.6) include(CTest) add_subdirectory(src) add_subdirectory(test) $ cat src/CMakeLists.txt include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_library(hello STATIC hello.cc) add_executable(main main.cc) target_link_libraries(main hello) $ cat test/CMakeLists.txt include_directories(${CMAKE_SOURCE_DIR}/src) add_test(t_hello ${CMAKE_CTEST_COMMAND} --build-and-test "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_BINARY_SOURCE_DIR}" --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-project t_hello --test-command t_hello) $ cd build $ cmake .. -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- CTest cannot determine repository type. Please set UPDATE_TYPE to 'cvs' or 'svn'. CTest update will not work. -- Configuring done -- Generating done -- Build files have been written to: /export/home/loose/work/hello/build $ ctest -V UpdateCTestConfiguration from :/export/home/loose/work/hello/build/DartConfiguration.tcl Parse Config file:/export/home/loose/work/hello/build/DartConfiguration.tcl Start processing tests UpdateCTestConfiguration from :/export/home/loose/work/hello/build/DartConfiguration.tcl Parse Config file:/export/home/loose/work/hello/build/DartConfiguration.tcl Test project /export/home/loose/work/hello/build Constructing a list of tests Done constructing a list of tests Changing directory into /export/home/loose/work/hello/build/test 1/ 1 Testing t_hello Test command: /usr/bin/ctest --build-and-test /export/home/loose/work/hello/test --build-generator Unix\ Makefiles --build-makeprogram /usr/bin/gmake --build-project t_hello --test-command t_hello Test timeout computed to be: 1500 Could not find executable t_hello Looked in the following places: t_hello t_hello Release/t_hello Release/t_hello Debug/t_hello Debug/t_hello MinSizeRel/t_hello MinSizeRel/t_hello RelWithDebInfo/t_hello RelWithDebInfo/t_hello Deployment/t_hello Deployment/t_hello Development/t_hello Development/t_hello Internal cmCTest object used to run test. Internal cmake changing into directory: /export/home/loose/work/hello/build/test ======== CMake output ====== The C compiler identification is GNU The CXX compiler identification is GNU Check for working C compiler: /usr/bin/gcc Configuring Check for working C compiler: /usr/bin/gcc -- works Detecting C compiler ABI info Configuring Detecting C compiler ABI info - done Check for working CXX compiler: /usr/bin/c++ Configuring Check for working CXX compiler: /usr/bin/c++ -- works Detecting CXX compiler ABI info Configuring Detecting CXX compiler ABI info - done CMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 2.6) should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more information run "cmake --help-policy CMP0000". This warning is for project developers. Use -Wno-dev to suppress it. Configuring Configuring done Generating Generating done Build files have been written to: /export/home/loose/work/hello/build/test ======== End CMake output ====== Change Dir: /export/home/loose/work/hello/build/test Run Clean Command:/usr/bin/gmake "clean" gmake[1]: *** No rule to make target `clean'. Stop. gmake: *** [clean] Error 2 Run Build Command:/usr/bin/gmake Could not find path to executable, perhaps it was not built: t_hello tried to find it in these places: t_hello t_hello Release/t_hello Release/t_hello Debug/t_hello Debug/t_hello MinSizeRel/t_hello MinSizeRel/t_hello RelWithDebInfo/t_hello RelWithDebInfo/t_hello Deployment/t_hello Deployment/t_hello Development/t_hello Development/t_hello ***Failed 0% tests passed, 1 tests failed out of 1 The following tests FAILED: 1 - t_hello (Failed) Errors while running CTest _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake