[Development] How to build unit tests & examples on demand with Qt6/CMake?

Alexandru Croitor alexandru.croitor at qt.io
Mon Nov 16 20:19:11 CET 2020


Hi,

With the configure line you posted, all tests will be configured and built as part of the default 'all' target.

If you wish the default all target not to build all tests (but still configure the tests and build them manually / explicitly), you can configure with -DQT_NO_MAKE_TESTS=ON.
Note the option might be renamed soon https://codereview.qt-project.org/c/qt/qtbase/+/318032

Ninja has special targets to build all targets under a directory.

e.g. ninja tests/auto/gui/all

You can also build a specific test by name
ninja tst_qmake
ninja tst_qmake_check (builds and runs the test)

If you want to build tests out-of-tree aka not part of the Qt build (standalone tests), there's the script in $prefix/bin/qt-cmake-standalone-test

Note it might not work in all cases (long story).

________________________________________
From: Development <development-bounces at qt-project.org> on behalf of Thiago Macieira <thiago.macieira at intel.com>
Sent: Monday, November 16, 2020 8:08 PM
To: development at qt-project.org
Subject: [Development] How to build unit tests & examples on demand with        Qt6/CMake?

With Qt5, I just did:
./configure -nomake tests -nomake examples [...]

And for each one I needed, I just ran qmake directly. For example:

 mkdir -p tests/auto/corelib
 cd tests/auto/corelib
 qmake $srcdir
 make qmake_all
 cd serialization/qcborvalue
 make check

 mkdir -p examples/corelib/serialization/cbordump
 cd examples/corelib/serialization/cbordump
 qmake $srcdir
 make

How do I do that with CMake? Configure line:

cmake -G Ninja $srcdir '-DBUILD_WITH_PCH=OFF' \
'-DCMAKE_INSTALL_PREFIX=/home/tjmaciei/obj/qt/qt6/qtbase' \
'-DQT_QMAKE_TARGET_MKSPEC=linux-g++-optimised' \
'-DFEATURE_optimize_debug=OFF' '-DFEATURE_developer_build=ON' \
'-DFEATURE_reduce_relocations=ON' '-DFEATURE_journald=ON' \
'-DFEATURE_sctp=ON' -DINPUT_qt_libinfix=.t -DFEATURE_openssl_linked=ON \
'-DBUILD_TESTING=ON' '-DBUILD_EXAMPLES=OFF'

The last line is likely significant. I want to be able to build only the tests
and examples I specify. Never all.

--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering



_______________________________________________
Development mailing list
Development at qt-project.org
https://lists.qt-project.org/listinfo/development


More information about the Development mailing list