[CMake] add_test command in a sub-directory

Nathaniel Waisbrot (Cont ARL/CISD) nathaniel.waisbrot at arl.army.mil
Thu Oct 1 12:50:59 EDT 2009


Try moving the ENABLE_TESTING() call to the top-level CMakeLists.txt,
before any calls to add_subdirectory().  Add_test() can stay where it
is.


-N


On Thu, 2009-10-01 at 18:30 +0200, romain.jacquet.dev at free.fr wrote:
> Hi everybody,
> 
>     I have found a strange behavior with CTest. I had a very simple projet with
> one test, which works perfectly.
> I have changed the architecture of my project. I have now a subdirectory.
> 
> Now:
> CMakeLists.txt
> ->myDir/
> ->myDir/*cpp
> ->myDir/*h
> ->myDir/CMakeLists.txt
> 
> The idea behind is the top-level CMakeLists.txt just call the other
> CMakeLists.txt with the add_subdirectory command. Everything works except that
> the target make test.
> $make test
> make: *** No rule to make target `test'. Stop.
> 
> I have found some workaround, moving the add_test command in the level
> directory. But it's not very easy to use.
> Is there a reason for the add_test command to not work in a subdirectory?
> 
> Thanks in advance for any help.
> 
> ------------------------------------------
> The top-level CMakeLists.txt:
> project(ROMAIN_CTEST)
> cmake_minimum_required(VERSION 2.6)
> 
> SET(QT_DIR "/data/qt-x11-opensource-src-4.5.2/install_dir/")
> SET(CMAKE_MODULE_PATH "/data/Development/Scripts/CMakeModules")
> INCLUDE(Qt)
> 
> 
> add_subdirectory("messagelib")
> ------------------------------------------
> The inner CMakeLists.txt:
> 
> include_directories("/data/qt-x11-opensource-src-4.5.2/install_dir/include/QtCore/")
> include_directories("/data/qt-x11-opensource-src-4.5.2/install_dir/include/")
> link_directories("/data/qt-x11-opensource-src-4.5.2/install_dir/lib/")
> 
> 
> QT4_AUTOMOC(mocGenList /data/messagelib/qb/message.h)
> 
> #add_library (message message.cpp ${mocGenList})
> message("mocGenList ${mocGenList}")
> 
> add_executable (montest test.cpp message.cpp ${mocGenList})
> target_link_libraries(montest QtCore)
> 
> 
> ENABLE_TESTING()
> ADD_TEST(SimpleTest montest)




More information about the CMake mailing list