From ad0ee0cd369bdac3b76136e2e8171643e45a356e Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 30 Apr 2020 16:37:07 +0300 Subject: [PATCH] CMake: Enable/disable GUI application via option --- .travis.yml | 2 +- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 12 +++--------- src/app/CMakeLists.txt | 6 +++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index db0e5cd55..ead529097 100644 --- a/.travis.yml +++ b/.travis.yml @@ -94,7 +94,7 @@ before_install: - | if [ "$gui" = "false" ]; then qmake_conf="$qmake_conf --disable-gui" - cmake_conf="$cmake_conf -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Widgets=ON" + cmake_conf="$cmake_conf -DGUI=OFF" fi # print settings diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bca70457..f7282e7d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ optional_compile_definitions(COUNTRIES_RESOLUTION FEATURE DESCRIPTION "Enable re DEFAULT ON DISABLED DISABLE_COUNTRIES_RESOLUTION) optional_compile_definitions(STACKTRACE FEATURE DESCRIPTION "Enable stacktraces" DEFAULT ON ENABLED STACKTRACE) +optional_compile_definitions(GUI FEATURE DESCRIPTION "Build GUI application" + DEFAULT ON DISABLED DISABLE_GUI) optional_compile_definitions(WEBUI FEATURE DESCRIPTION "Enables built-in HTTP server for headless use" DEFAULT ON DISABLED DISABLE_WEBUI) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a8f3aaa1..66a5ad29d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,19 +12,13 @@ if (Boost_VERSION VERSION_LESS 106000) endif() find_package(Qt5 ${requiredQtVersion} REQUIRED COMPONENTS Core Network Xml LinguistTools) -find_package(Qt5Widgets ${requiredQtVersion}) -if (Qt5Widgets_FOUND) +if (NOT DISABLE_GUI) + find_package(Qt5Widgets ${requiredQtVersion} REQUIRED) find_package(Qt5DBus ${requiredQtVersion}) else() add_definitions(-DDISABLE_GUI) endif() -set_package_properties(Qt5Widgets PROPERTIES - DESCRIPTION "Set of components for creating classic desktop-style UIs for the Qt5 framework" - PURPOSE "Enables qBittorrent GUI. Unneeded for headless configuration." - TYPE OPTIONAL -) - set_package_properties(Qt5DBus PROPERTIES DESCRIPTION "Qt5 module for inter-process communication over the D-Bus protocol" PURPOSE "Enables communication with other system components (e.g. notification service) via D-Bus. " @@ -60,7 +54,7 @@ configure_file(config.h.cmakein ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_subdirectory(app) add_subdirectory(base) -if (Qt5Widgets_FOUND) +if (NOT DISABLE_GUI) add_subdirectory(gui) endif () diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 3827af815..7ff7f5f9b 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -63,7 +63,7 @@ if (STACKTRACE) target_sources(qBittorrent PRIVATE stacktrace.h) else() target_sources(qBittorrent PRIVATE stacktrace_win.h) - if (Qt5Widgets_FOUND) + if (NOT DISABLE_GUI) target_sources(qBittorrent PRIVATE stacktracedialog.cpp stacktracedialog.h) endif() @@ -85,7 +85,7 @@ if (STACKTRACE) endif() endif() -if (Qt5Widgets_FOUND) +if (NOT DISABLE_GUI) target_link_libraries(qBittorrent PRIVATE qbt_gui) set_target_properties(qBittorrent PROPERTIES @@ -156,7 +156,7 @@ install(TARGETS qBittorrent COMPONENT runtime ) -if (Qt5Widgets_FOUND AND APPLE) +if (NOT DISABLE_GUI AND APPLE) find_package(Qt5Svg REQUIRED) include(bundle) endif()