From 2fb17775ac879e41e1b6f8a9f24bc28651c6df15 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Mon, 11 Nov 2024 19:04:44 +0300
Subject: [PATCH 3/5] Make building of tests optional

---
 CMakeLists.txt           | 13 +++++++++++--
 UnitTests/CMakeLists.txt |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fed05c6..bc16b59 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,7 @@ if(WIN32 AND MSVC)
 endif()
 
 option(PDF4QT_BUILD_ONLY_CORE_LIBRARY "Build only core library" OFF)
+option(PDF4QT_BUILD_TESTS "Build UnitTests" ON)
 
 set(PDF4QT_QT_ROOT "" CACHE PATH "Qt root directory")
 
@@ -56,7 +57,11 @@ find_package(Qt6 REQUIRED COMPONENTS Core LinguistTools)
 if(PDF4QT_BUILD_ONLY_CORE_LIBRARY)
     find_package(Qt6 REQUIRED COMPONENTS Core Gui Svg Xml)
 else()
-    find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Svg Xml PrintSupport TextToSpeech Test)
+    find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Svg Xml PrintSupport TextToSpeech)
+endif()
+
+if(PDF4QT_BUILD_TESTS)
+    find_package(Qt6 REQUIRED COMPONENTS Test)
 endif()
 
 qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES en de cs es ko)
@@ -135,7 +140,6 @@ if(NOT PDF4QT_BUILD_ONLY_CORE_LIBRARY)
     add_subdirectory(JBIG2_Viewer)
     add_subdirectory(PdfExampleGenerator)
     add_subdirectory(PdfTool)
-    add_subdirectory(UnitTests)
     add_subdirectory(Pdf4QtLibGui)
     add_subdirectory(Pdf4QtEditorPlugins)
     add_subdirectory(Pdf4QtEditor)
@@ -146,6 +150,11 @@ if(NOT PDF4QT_BUILD_ONLY_CORE_LIBRARY)
     add_subdirectory(WixInstaller)
 endif()
 
+if(PDF4QT_BUILD_TESTS)
+    enable_testing()
+    add_subdirectory(UnitTests)
+endif()
+
 qt_collect_translation_source_targets(i18n_targets)
 message("CMAKE_TRANSLATION_TARGETS = " ${i18n_targets})
 
diff --git a/UnitTests/CMakeLists.txt b/UnitTests/CMakeLists.txt
index c1a912f..9f64ec8 100644
--- a/UnitTests/CMakeLists.txt
+++ b/UnitTests/CMakeLists.txt
@@ -32,3 +32,4 @@ set_target_properties(UnitTests PROPERTIES
     LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PDF4QT_INSTALL_LIB_DIR}
     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PDF4QT_INSTALL_BIN_DIR}
 )
+add_test(UnitTests  "${CMAKE_BINARY_DIR}/${PDF4QT_INSTALL_BIN_DIR}/UnitTests")
-- 
2.49.1

