Build Qt Tests with CMake

前端 未结 2 1856
Happy的楠姐
Happy的楠姐 2021-02-01 17:47

Can anyone give me an example of some QT test code and a CMakeLists.txt that build with Cmake and ran with CTest. I can\'t seem to find any!

-Kurtis

2条回答
  •  盖世英雄少女心
    2021-02-01 18:03

    An example taken from Charm (Tests/CMakeLists.txt):

    SET( TestApplication_SRCS TestApplication.cpp )
    SET( TEST_LIBRARIES CharmCore ${QT_QTTEST_LIBRARY} ${QT_LIBRARIES} )
    
    SET( SqLiteStorageTests_SRCS SqLiteStorageTests.cpp )
    QT4_AUTOMOC( ${SqLiteStorageTests_SRCS} )
    ADD_EXECUTABLE( SqLiteStorageTests ${SqLiteStorageTests_SRCS} )
    TARGET_LINK_LIBRARIES( SqLiteStorageTests ${TEST_LIBRARIES} )
    ADD_TEST( NAME SqLiteStorageTests COMMAND SqLiteStorageTests )
    

    The only difference to a normal executable is that you call ADD_TEST macro. Have a look at e.g. Charm to see it in action.

提交回复
热议问题