[CMake] test depending on code compilation

Franck Houssen franck.houssen at inria.fr
Wed Jan 10 06:22:39 EST 2018


I tried to reduce the example: 

>> ls 
CMakeLists.txt main.cpp mytest.cpp mytest.sh 

>> more * 
:::::::::::::: 
CMakeLists.txt 
:::::::::::::: 
cmake_minimum_required(VERSION 3.7) 
enable_language(CXX) 

project(main) 
add_executable(main main.cpp) 
add_executable(mytestcpp mytest.cpp) 

include(CTest) 
enable_testing() 
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mytest.sh" "${CMAKE_CURRENT_BINARY_DIR}/mytest.sh") 
add_test(NAME mytestsh COMMAND ./mytest.sh WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS mytestcpp) 
:::::::::::::: 
main.cpp 
:::::::::::::: 
int main() {return 0;} 
:::::::::::::: 
mytest.cpp 
:::::::::::::: 
int main() {return 0;} 
:::::::::::::: 
mytest.sh 
:::::::::::::: 
#!/bin/bash 
exit 0 

I want make to build only main => KO 
>> make 
[ 50%] Built target main 
[100%] Built target mytestcpp 

I want make check to build mytestcpp and run tests => OK but verbose is KO. 
>> make check ARGS="-V" 
[100%] Built target mytestcpp 
Test project /tmp/BUILD 
Start 1: mytestsh 
1/1 Test #1: mytestsh ......................... Passed 0.00 sec 

I want make test to run test only => OK and verbose is OK. 

----- Mail original -----

> De: "Franck Houssen" <franck.houssen at inria.fr>
> À: "CMake Mail List" <cmake at cmake.org>
> Envoyé: Mercredi 10 Janvier 2018 10:47:34
> Objet: [CMake] test depending on code compilation

> 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 ?

> --

> Powered by www.kitware.com

> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ

> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:

> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html

> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html

> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180110/9e45b364/attachment-0001.html>


More information about the CMake mailing list