From d69d6325cef0c6c095f40f7f74ecef02456ebb89 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Thu, 28 Oct 2021 23:40:03 +0200 Subject: [PATCH] Introduce option to build without X11 libs Currently we are very inconsistent with how we handle our various X11 dependencies. Some places check whether specific sub-libraries are found and disable parts of the code accordingly. Sometimes this is controlled by whether X11 is found at all, sometimes it depends on the sublibrary being present. Some of this is obviously broken, e.g. in one like we check whether X11 is there and then use it unconditionally a few lines down. Instead of the current system of optional deps and deps being conditional on other deps I propose that we introduce an explicit build option that controls the X11 support. If on (the default) then all X11 libs are required. If off then no X11 libs are searched for. Currently this results in a broken build since some places use X11 stuff unconditionally, but it gives us an easier way to test and fix those cases. --- CMakeLists.txt | 72 ++++++++++++++++---------------- ConfigureChecks.cmake | 2 - dataengines/mouse/CMakeLists.txt | 18 ++++---- kcms/colors/CMakeLists.txt | 2 +- kcms/cursortheme/CMakeLists.txt | 39 ++++++++--------- kcms/fonts/CMakeLists.txt | 2 +- kcms/kfontinst/CMakeLists.txt | 2 +- kcms/lookandfeel/CMakeLists.txt | 13 ++---- klipper/CMakeLists.txt | 3 +- libkworkspace/CMakeLists.txt | 5 +-- libtaskmanager/CMakeLists.txt | 6 +-- 11 files changed, 76 insertions(+), 88 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 432fd69f5..fbcfdd7ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(KF5_MIN_VERSION "5.94") set(KDE_COMPILERSETTINGS_LEVEL "5.82") set(INSTALL_SDDM_THEME TRUE) option(INSTALL_SDDM_WAYLAND_SESSION OFF) +option(WITH_X11 "Build with X11 support. Building without is experimental" ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -115,26 +116,43 @@ set_package_properties(Fontconfig PROPERTIES DESCRIPTION "Font access configurat PURPOSE "Needed to build font configuration and installation tools" ) - -find_package(X11) -set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" - URL "https://www.x.org" - TYPE OPTIONAL - PURPOSE "Required for building the X11 based workspace") -function(check_X11_lib _lib) - if (NOT TARGET X11::${_lib}) - message(SEND_ERROR "Required component ${_lib} of X11 was not found") +if(WITH_X11) + find_package(X11) + set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" + URL "https://www.x.org" + TYPE REQUIRED + PURPOSE "Required for building the X11 based workspace") + function(check_X11_lib _lib) + if (NOT TARGET X11::${_lib}) + message(SEND_ERROR "Required component ${_lib} of X11 was not found") + endif() + endfunction() + check_X11_lib(ICE) + check_X11_lib(SM) + check_X11_lib(X11) + check_X11_lib(Xau) + check_X11_lib(Xcursor) + check_X11_lib(Xfixes) + check_X11_lib(Xft) + check_X11_lib(Xrender) + check_X11_lib(Xtst) + + set(HAVE_X11 1) + set(HAVE_XCURSOR 1) + set(HAVE_XFIXES 1) + + find_package(XCB MODULE REQUIRED COMPONENTS XCB RANDR IMAGE) + set_package_properties(XCB PROPERTIES TYPE REQUIRED) + + if (QT_MAJOR_VERSION EQUAL "5") + find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras) endif() -endfunction() -check_X11_lib(ICE) -check_X11_lib(SM) -check_X11_lib(X11) -check_X11_lib(Xau) -check_X11_lib(Xcursor) -check_X11_lib(Xfixes) -check_X11_lib(Xft) -check_X11_lib(Xrender) -check_X11_lib(Xtst) + +else() + set(HAVE_X11 0) + set(HAVE_XCURSOR 0) + set(HAVE_XFIXES 0) +endif() find_package(PkgConfig REQUIRED) pkg_check_modules(PipeWire IMPORTED_TARGET libpipewire-0.3) @@ -159,22 +177,6 @@ if(FONTCONFIG_FOUND) find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS PrintSupport) endif() -if(X11_FOUND) - find_package(XCB MODULE REQUIRED COMPONENTS XCB RANDR IMAGE) - set_package_properties(XCB PROPERTIES TYPE REQUIRED) - if(NOT X11_SM_FOUND) - message(FATAL_ERROR "\nThe X11 Session Management (SM) development package could not be found.\nPlease install libSM.\n") - endif(NOT X11_SM_FOUND) - - if (QT_MAJOR_VERSION EQUAL "5") - find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras) - endif() -endif() - -if(X11_FOUND AND XCB_XCB_FOUND) - set(HAVE_X11 1) -endif() - find_package(AppStreamQt 0.10.6) set_package_properties(AppStreamQt PROPERTIES DESCRIPTION "Access metadata for listing available software" URL "https://www.freedesktop.org/wiki/Distributions/AppStream/" diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 7ab5e2995..18d781377 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -5,5 +5,3 @@ check_include_files(sys/time.h HAVE_SYS_TIME_H) # ksmserver, ksplashml, sftp check_include_files(unistd.h HAVE_UNISTD_H) set(HAVE_FONTCONFIG ${FONTCONFIG_FOUND}) # kcms/{fonts,kfontinst} -set(HAVE_XCURSOR ${X11_Xcursor_FOUND}) # many uses -set(HAVE_XFIXES ${X11_Xfixes_FOUND}) # klipper, kicker diff --git a/dataengines/mouse/CMakeLists.txt b/dataengines/mouse/CMakeLists.txt index 6f75e4903..3ed13d4fa 100644 --- a/dataengines/mouse/CMakeLists.txt +++ b/dataengines/mouse/CMakeLists.txt @@ -5,7 +5,7 @@ set(mouse_engine_SRCS mouseengine.h ) -if (X11_Xfixes_FOUND) +if (HAVE_X11) set(mouse_engine_SRCS ${mouse_engine_SRCS} cursornotificationhandler.cpp) endif () @@ -14,14 +14,14 @@ target_link_libraries(plasma_engine_mouse Qt::Widgets KF5::Plasma KF5::WindowSystem - X11::X11 ) -if (QT_MAJOR_VERSION EQUAL "5") - target_link_libraries(plasma_engine_mouse Qt::X11Extras) -else() - target_link_libraries(plasma_engine_mouse Qt::GuiPrivate) -endif() -if (X11_Xfixes_FOUND) - target_link_libraries(plasma_engine_mouse X11::Xfixes) +if (HAVE_X11) + if (QT_MAJOR_VERSION EQUAL "5") + target_link_libraries(plasma_engine_mouse Qt::X11Extras) + else() + target_link_libraries(plasma_engine_mouse Qt::GuiPrivate) + endif() + + target_link_libraries(plasma_engine_mouse X11::X11 X11::Xfixes) endif () diff --git a/kcms/colors/CMakeLists.txt b/kcms/colors/CMakeLists.txt index 412e47b34..ae95faaac 100644 --- a/kcms/colors/CMakeLists.txt +++ b/kcms/colors/CMakeLists.txt @@ -60,7 +60,7 @@ target_link_libraries(kcm_colors krdb ) -if(X11_FOUND) +if(HAVE_X11) target_link_libraries(kcm_colors X11::X11) if (QT_MAJOR_VERSION EQUAL "5") target_link_libraries(kcm_colors Qt::X11Extras) diff --git a/kcms/cursortheme/CMakeLists.txt b/kcms/cursortheme/CMakeLists.txt index 8ca48a7d6..aa0237ea4 100644 --- a/kcms/cursortheme/CMakeLists.txt +++ b/kcms/cursortheme/CMakeLists.txt @@ -46,17 +46,15 @@ target_link_libraries(kcm_cursortheme PW::KWorkspace krdb ) -if (QT_MAJOR_VERSION EQUAL "5") - target_link_libraries(kcm_cursortheme Qt::X11Extras) -else() - target_link_libraries(kcm_cursortheme Qt::GuiPrivate) -endif() -if (X11_Xcursor_FOUND) - target_link_libraries(kcm_cursortheme X11::Xcursor) -endif () -if (X11_Xfixes_FOUND) - target_link_libraries(kcm_cursortheme X11::Xfixes) +if (HAVE_X11) + if (QT_MAJOR_VERSION EQUAL "5") + target_link_libraries(kcm_cursortheme Qt::X11Extras) + else() + target_link_libraries(kcm_cursortheme Qt::GuiPrivate) + endif() + + target_link_libraries(kcm_cursortheme X11::Xcursor X11::Xfixes) endif () ########### next target ############### @@ -81,21 +79,18 @@ target_link_libraries(plasma-apply-cursortheme KF5::I18n KF5::KCMUtils KF5::WindowSystem - X11::X11 - XCB::XCB PW::KWorkspace ) -if (QT_MAJOR_VERSION EQUAL "5") - target_link_libraries(plasma-apply-cursortheme Qt::X11Extras) -else() - target_link_libraries(plasma-apply-cursortheme Qt::GuiPrivate) + +if (HAVE_X11) + if (QT_MAJOR_VERSION EQUAL "5") + target_link_libraries(plasma-apply-cursortheme Qt::X11Extras) + else() + target_link_libraries(plasma-apply-cursortheme Qt::GuiPrivate) + endif() + + target_link_libraries(plasma-apply-cursortheme X11::X11 X11::Xcursor X11::Xfixes) endif() -if (X11_Xcursor_FOUND) - target_link_libraries(plasma-apply-cursortheme X11::Xcursor) -endif () -if (X11_Xfixes_FOUND) - target_link_libraries(plasma-apply-cursortheme X11::Xfixes) -endif () install(TARGETS plasma-apply-cursortheme DESTINATION ${KDE_INSTALL_BINDIR}) diff --git a/kcms/fonts/CMakeLists.txt b/kcms/fonts/CMakeLists.txt index 10ab59950..984095628 100644 --- a/kcms/fonts/CMakeLists.txt +++ b/kcms/fonts/CMakeLists.txt @@ -28,7 +28,7 @@ kcmutils_generate_desktop_file (kcm_fonts) target_link_libraries(kcm_fonts KF5::I18n KF5::WindowSystem KF5::KCMUtils KF5::QuickAddons KF5::Declarative kfontinst krdb) -if(X11_FOUND) +if(HAVE_X11) target_link_libraries(kcm_fonts X11::X11 X11::Xft XCB::IMAGE) if (QT_MAJOR_VERSION EQUAL "5") target_link_libraries(kcm_fonts Qt::X11Extras) diff --git a/kcms/kfontinst/CMakeLists.txt b/kcms/kfontinst/CMakeLists.txt index b3f7bf793..3e4c67bd5 100644 --- a/kcms/kfontinst/CMakeLists.txt +++ b/kcms/kfontinst/CMakeLists.txt @@ -1,7 +1,7 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kfontinst\") -if (X11_Xft_FOUND) +if (HAVE_X11) check_include_files(locale.h HAVE_LOCALE_H) configure_file(config-fontinst.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-fontinst.h) include_directories( diff --git a/kcms/lookandfeel/CMakeLists.txt b/kcms/lookandfeel/CMakeLists.txt index 87909a553..8d2d9339d 100644 --- a/kcms/lookandfeel/CMakeLists.txt +++ b/kcms/lookandfeel/CMakeLists.txt @@ -1,7 +1,7 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kcm_lookandfeel\") -if(X11_Xcursor_FOUND) +if(HAVE_X11) set(HAVE_XCURSOR TRUE) endif() @@ -19,7 +19,7 @@ add_library(lookandfeelmanager STATIC ../kcms-common.cpp ) -if (X11_Xcursor_FOUND) +if (HAVE_X11) target_sources(lookandfeelmanager PRIVATE ../cursortheme/xcursor/cursortheme.cpp ../cursortheme/xcursor/xcursortheme.cpp @@ -49,19 +49,14 @@ target_link_libraries(lookandfeelmanager krdb ) -if(X11_FOUND) +if(HAVE_X11) if (QT_MAJOR_VERSION EQUAL "5") target_link_libraries(lookandfeelmanager Qt::X11Extras) else() target_link_libraries(lookandfeelmanager Qt::GuiPrivate) endif() + target_link_libraries(lookandfeelmanager X11::Xcursor X11::Xfixes) endif() -if (X11_Xcursor_FOUND) - target_link_libraries(lookandfeelmanager X11::Xcursor) -endif () -if (X11_Xfixes_FOUND) - target_link_libraries(lookandfeelmanager X11::Xfixes) -endif () add_library(kcm_lookandfeel_objects OBJECT kcm.cpp) target_link_libraries(kcm_lookandfeel_objects diff --git a/klipper/CMakeLists.txt b/klipper/CMakeLists.txt index c7a3eea24..ee27ad14e 100644 --- a/klipper/CMakeLists.txt +++ b/klipper/CMakeLists.txt @@ -50,7 +50,8 @@ target_link_libraries(libklipper_common_static KF5::WaylandClient KF5::IconThemes ${ZLIB_LIBRARY}) -if (X11_FOUND) + +if (HAVE_X11) target_link_libraries(libklipper_common_static XCB::XCB) if (QT_MAJOR_VERSION EQUAL "5") target_link_libraries(libklipper_common_static Qt::X11Extras) diff --git a/libkworkspace/CMakeLists.txt b/libkworkspace/CMakeLists.txt index 1d9c63a9f..d10b3688d 100644 --- a/libkworkspace/CMakeLists.txt +++ b/libkworkspace/CMakeLists.txt @@ -68,10 +68,7 @@ target_include_directories(kworkspace PUBLIC "$