[CMake] test depending on code compilation

Franck Houssen franck.houssen at inria.fr
Wed Jan 10 04:47:34 EST 2018


I need to design a test (= a bash script) such that : 
1) run a dedicated executable for the test (to be compiled) 
2) diff the run output with a reference log file 

The test is created with : add_test(mytest ./mytest.sh). The bash script would look like: 
>> more mytest.sh 
/path/to/mytestexe > out.log 
diff out.log out.ref 

The dedicated executable for the test is created with : add_executable(mytestexe mytestexe.cpp) 

Ideally, I would like mytestexe to be compiled when I type "make test" (before to run the test) but not "make". 

Seems impossible to add a dependencie with : add_dependencies(mytest mytestexe). I googled this and found https://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests but this was not really clear to me...I added : add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS mytestexe). 

The 2 unexpected problems I have left are: 
1) mytestexe is compiled everytime I type "make" which is a solution but is not really what I am looking for (also compiled when I type "make check" which is expected). 
=> is there a way for make not to compile mytestexe (note I didn't added ALL in add_custom_target so I am not sure to know why make builds mytestexe) 
2) Also the verbosity is broken with check : make test ARGS="-V" is verbose , but, make check ARGS="-V" is not. 
=> how to deal with that ? 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180110/4a940b39/attachment.html>


More information about the CMake mailing list