From 968152b81e71fdaf78301d999ef3c2954eba1564 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <asturm@gentoo.org>
Date: Sat, 11 Jul 2020 23:04:16 +0200
Subject: [PATCH] ECMAddTests.cmake: Skip ecm_add_test early if Qt::Test is not
 available

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 modules/ECMAddTests.cmake        | 10 ++++++++++
 tests/ECMAddTests/CMakeLists.txt |  5 +++++
 2 files changed, 15 insertions(+)

diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake
index ce0586f0..e362d990 100644
--- a/modules/ECMAddTests.cmake
+++ b/modules/ECMAddTests.cmake
@@ -373,6 +373,11 @@ function(ecm_add_test)
       message(FATAL_ERROR "ecm_add_test() called with both \"NO_NAME_PREFIX\" and \"NAME_PREFIX\"")
     endif()
   endif()
+
+  if(NOT TARGET Qt::Test)
+    return()
+  endif()
+
   set(_testname ${ARG_NAME_PREFIX}${_targetname})
   set(gui_args)
   if(ARG_GUI)
@@ -441,6 +446,11 @@ function(ecm_add_tests)
   endif()
   set(test_names)
   set(target_names)
+
+  if(NOT TARGET Qt::Test)
+    return()
+  endif()
+
   foreach(_test_source ${ARG_UNPARSED_ARGUMENTS})
     ecm_add_test(${_test_source}
       ${_name_prefix}
diff --git a/tests/ECMAddTests/CMakeLists.txt b/tests/ECMAddTests/CMakeLists.txt
index ca82c7e9..48aa420e 100644
--- a/tests/ECMAddTests/CMakeLists.txt
+++ b/tests/ECMAddTests/CMakeLists.txt
@@ -4,6 +4,11 @@ else()
     set(QT_VERSION_OPT "-DBUILD_WITH_QT6=OFF")
 endif()
 
+if(NOT TARGET Qt::Test)
+    message(STATUS "WARNING: skipping tests that require Qt::Test")
+    return()
+endif()
+
 macro(add_check NAME)
     string(REPLACE "." "/" dir "${NAME}")
     string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
-- 
2.52.0

