From 517054ec60348e7a0fb860d4b1a36764c2d5d92d Mon Sep 17 00:00:00 2001 From: Diego Iastrubni Date: Sat, 16 Nov 2024 16:39:39 +0200 Subject: [PATCH] Disable unit tests on demand A consumer of this library, might not need to build unit tests. Let the consumer of this library a way for him to disable tests building. --- CMakeLists.txt | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed14a38..2ab42ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,18 @@ project(QSimpleUpdater LANGUAGES CXX ) +option(QSIMPLE_UPDATER_BUILD_TESTS "Build the unit tests" ON) + set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network Test) -find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS Widgets Network Test) +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network) +find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS Widgets Network) + +if(QSIMPLE_UPDATER_BUILD_TESTS) + find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED COMPONENTS Test) +endif() add_library(QSimpleUpdater STATIC etc/resources/qsimpleupdater.qrc @@ -28,14 +34,15 @@ target_link_libraries(QSimpleUpdater PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_V add_subdirectory(tutorial) - -enable_testing() -add_executable(UnitTests - tests/main.cpp - tests/Test_Versioning.h - tests/Test_Updater.h - tests/Test_QSimpleUpdater.h - tests/Test_Downloader.h -) -add_test(NAME ApiTest COMMAND ApiTest) -target_link_libraries(UnitTests PRIVATE Qt${QT_VERSION_MAJOR}::Test QSimpleUpdater) +if(QSIMPLE_UPDATER_BUILD_TESTS) + enable_testing() + add_executable(UnitTests + tests/main.cpp + tests/Test_Versioning.h + tests/Test_Updater.h + tests/Test_QSimpleUpdater.h + tests/Test_Downloader.h + ) + add_test(NAME ApiTest COMMAND ApiTest) + target_link_libraries(UnitTests PRIVATE Qt${QT_VERSION_MAJOR}::Test QSimpleUpdater) +endif()