Skip to content

Commit

Permalink
Disable unit tests on demand
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
diegoiast committed Nov 16, 2024
1 parent 5bfeb1f commit 517054e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 517054e

Please sign in to comment.