Build: Suppress moc warnings when building without tests

Many source files have Q_OBJECT inside #ifdef WITH_TESTS. Automoc uses
a very basic parser that detects this file as mocable, but moc shows a
warning: "No relevant classes found."

Just suppress the warning on this case.

See also upstream issue:
https://gitlab.kitware.com/cmake/cmake/-/issues/26224

Fixes: QTCREATORBUG-31492
Change-Id: Idea7b05b4faf4011d7e1ecb44495341d73654170
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Orkun Tokdemir <orkun.tokdemir@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Orgad Shaneh
2024-08-27 17:18:27 +03:00
committed by Orgad Shaneh
parent 4b60312769
commit f95d904d0e

View File

@@ -482,6 +482,12 @@ function(add_qtc_plugin target_name)
if (WITH_TESTS) if (WITH_TESTS)
set(TEST_DEFINES WITH_TESTS SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}") set(TEST_DEFINES WITH_TESTS SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
else()
# Many source files have Q_OBJECT inside #ifdef WITH_TESTS. Automoc uses
# a very basic parser that detects this file as mocable, but moc shows a
# warning: "No relevant classes found."
# Just suppress the warning on this case.
set_target_properties(${target_name} PROPERTIES AUTOMOC_MOC_OPTIONS "-nw")
endif() endif()
if (WITH_SANITIZE) if (WITH_SANITIZE)