From fe096c5d05c95bfdcfae6a5976e242e324f4152d Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <andreas.sturmlechner@gmail.com>
Date: Fri, 5 Feb 2021 06:17:42 +0000
Subject: [PATCH] Use include(CTest) and BUILD_TESTING to make tests optional

Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
---
 CMakeLists.txt     | 29 ++++++++++++++++++++---------
 src/CMakeLists.txt |  2 +-
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 92d50265..ee476ac5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -211,8 +211,15 @@ endif()
 set(CFG_QMLSRCDIR "${kid3_SOURCE_DIR}/src/qml")
 
 find_package(Threads)
-set(Python_ADDITIONAL_VERSIONS 3)
-find_package(PythonInterp REQUIRED)
+include(CTest)
+if(CMAKE_VERSION VERSION_LESS 3.12.0)
+  set(Python_ADDITIONAL_VERSIONS 3)
+  find_package(PythonInterp REQUIRED)
+  # PythonInterp sets PYTHON_EXECUTABLE
+else()
+  find_package(Python3 COMPONENTS Interpreter REQUIRED)
+  set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
+endif()
 include (CheckCXXSourceCompiles)
 include (CheckCXXCompilerFlag)
 include (CheckLibraryExists)
@@ -256,7 +263,10 @@ else()
   find_package(Qt5Core)
 endif()
 if(Qt5Core_FOUND)
-  set(_qtComponents Core Gui Widgets Network Xml Multimedia LinguistTools Test)
+  set(_qtComponents Core Gui Widgets Network Xml Multimedia LinguistTools)
+  if(BUILD_TESTING)
+    set(_qtComponents ${_qtComponents} Test)
+  endif()
   if(WITH_DBUS)
     set(_qtComponents ${_qtComponents} DBus)
   endif()
@@ -472,12 +482,13 @@ if(ANDROID)
 endif()
 
 
-enable_testing()
-add_test(NAME test_cli_functions
-         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/test/test_cli_functions.py)
-add_custom_target(check ${CMAKE_CTEST_COMMAND} --output-on-failure)
-if(NOT CMAKE_VERSION VERSION_LESS "3.17")
-  list(APPEND CMAKE_CTEST_ARGUMENTS --output-on-failure)
+if(BUILD_TESTING)
+  add_test(NAME test_cli_functions
+           COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/src/test/test_cli_functions.py)
+  add_custom_target(check ${CMAKE_CTEST_COMMAND} --output-on-failure)
+  if(NOT CMAKE_VERSION VERSION_LESS "3.17")
+    list(APPEND CMAKE_CTEST_ARGUMENTS --output-on-failure)
+  endif()
 endif()
 
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c6c703ac..db067265 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,6 +8,6 @@ if(WITH_QML)
   add_subdirectory(qml)
 endif()
 
-if(BUILD_TEST_APP)
+if(BUILD_TESTING AND BUILD_TEST_APP)
   add_subdirectory(test)
 endif()
-- 
GitLab

