From d650383a45489032f32d15a3cb57cd58e2a045d9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Feb 2026 11:50:20 +0100 Subject: [PATCH 1/9] CMake: add options to selectively turn off Qt5 or Qt6 It should be possible to build a specific (Qt5 or 6) version of the library in the presence of both, without automatically finding both. There's CMake machinery for this already (CMAKE_DISABLE_FIND_PACKAGE_*) but that is hard-to-find and sometimes difficult to spell. --- CMakeLists.txt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74029cb..e1169a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ project(QWebdav LANGUAGES CXX ) +# By default, look for and support both versions of Qt, but they +# can be individually turned off with e.g. -DENABLE_QT5=OFF +option(ENABLE_QT5 "Search for Qt5 libraries and build ${PROJECT_NAME} for Qt5 if found" ON) +option(ENABLE_QT6 "Search for Qt6 libraries and build ${PROJECT_NAME} for Qt6 if found" ON) + ### Find ECM up-front and complain otherwise # # @@ -37,8 +42,12 @@ include(CMakePackageConfigHelpers) set(QT_NO_CREATE_VERSIONLESS_TARGETS ON) set(QT5_REQUIRED_VERSION 5.15.0) set(QT6_REQUIRED_VERSION 6.5.0) -find_package(Qt6 ${QT6_REQUIRED_VERSION} CONFIG COMPONENTS Core Network Xml) -find_package(Qt5 ${QT5_REQUIRED_VERSION} CONFIG COMPONENTS Core Network Xml) +if(ENABLE_QT6) + find_package(Qt6 ${QT6_REQUIRED_VERSION} CONFIG COMPONENTS Core Network Xml) +endif() +if(ENABLE_QT5) + find_package(Qt5 ${QT5_REQUIRED_VERSION} CONFIG COMPONENTS Core Network Xml) +endif() set(WITH_QT5 FALSE) # Used when creating the Config.cmake file set(WITH_QT6 FALSE) @@ -46,10 +55,16 @@ if(TARGET Qt5::Core) message(STATUS "Building Qt5 version of ${PROJECT_NAME}") set(WITH_QT5 TRUE) endif() +if(ENABLE_QT5 AND NOT TARGET Qt5::Core) + message(STATUS "Qt5 enabled but not found.") +endif() if(TARGET Qt6::Core) message(STATUS "Building Qt6 version of ${PROJECT_NAME}") set(WITH_QT6 TRUE) endif() +if(ENABLE_QT6 AND NOT TARGET Qt6::Core) + message(STATUS "Qt5 enabled but not found.") +endif() if(NOT TARGET Qt5::Core AND NOT TARGET Qt6::Core) # If neither is found, complain about Qt5 because then the # error message says ">= 5.15.0" which reads most naturally. From 394c6c4622406a2367ef0c1547a711369975c65f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Feb 2026 12:01:53 +0100 Subject: [PATCH 2/9] CMake: complain earlier if no suitable Qt is found This avoids confusing cmake-time errors from subdirectories that can't use Qt facilities then. --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1169a6..6eef15c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,14 +51,14 @@ endif() set(WITH_QT5 FALSE) # Used when creating the Config.cmake file set(WITH_QT6 FALSE) -if(TARGET Qt5::Core) +if(ENABLE_QT5 AND TARGET Qt5::Core) message(STATUS "Building Qt5 version of ${PROJECT_NAME}") set(WITH_QT5 TRUE) endif() if(ENABLE_QT5 AND NOT TARGET Qt5::Core) message(STATUS "Qt5 enabled but not found.") endif() -if(TARGET Qt6::Core) +if(ENABLE_QT6 AND TARGET Qt6::Core) message(STATUS "Building Qt6 version of ${PROJECT_NAME}") set(WITH_QT6 TRUE) endif() @@ -76,6 +76,8 @@ if(NOT TARGET Qt5::Core AND NOT TARGET Qt6::Core) ) endif() +feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) + ### QWebdav version header is independent of build type # # From 1408ebb6aadcab70944569eaa469c1b1527342e4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Feb 2026 12:17:41 +0100 Subject: [PATCH 3/9] CMake: install per-Qt-version copies of headers Don't install all headers, though (as previously with CMake), leave private and unnecessary ones out. --- qwebdavlib/CMakeLists.txt | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/qwebdavlib/CMakeLists.txt b/qwebdavlib/CMakeLists.txt index 8f3f3c8..46f89ba 100644 --- a/qwebdavlib/CMakeLists.txt +++ b/qwebdavlib/CMakeLists.txt @@ -50,31 +50,32 @@ function(add_qwebdav_library QT_VERSION) EXPORT QWebdavTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) + + generate_export_header(qwebdav-qt${QT_VERSION}) + + # One copy of the headers per Qt-version, even though they are + # identical: this is so that you can build packages of Qt5 and Qt6 + # libraries separately and they won't collide over the headers. + install( + FILES + # Generated export-header isn't used (qwebdav_global contains similar + # definitions) and the naturalsort header is for internal use. + # + # ${CMAKE_CURRENT_BINARY_DIR}/qwebdav_export.h + # qnaturalsort.h + qwebdav.h + qwebdav_global.h + qwebdavdirparser.h + qwebdavitem.h + DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav${QT_VERSION} + COMPONENT devel + ) + endfunction() if(WITH_QT5) add_qwebdav_library(5) - add_library(QWebdav ALIAS qwebdav-qt5) endif() if(WITH_QT6) add_qwebdav_library(6) - if(NOT TARGET QWebdav) - add_library(QWebdav ALIAS qwebdav-qt6) - endif() endif() - -# Only one export header, regardless of which libraries are built -generate_export_header(QWebdav) - -# Only one copy of the headers, regardless of which libraries are built -install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/qwebdav_export.h - qnaturalsort.h - qwebdav.h - qwebdav_global.h - qwebdavdirparser.h - qwebdavitem.h - DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav - COMPONENT devel -) From 195c0645bf36dc5f874ea240ef57b44671a112f9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Feb 2026 12:45:54 +0100 Subject: [PATCH 4/9] CMake: install the version-header in each versioned include-dir --- CMakeLists.txt | 13 ++++--------- qwebdavlib/CMakeLists.txt | 7 ++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6eef15c..3564452 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,19 +80,14 @@ feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKA ### QWebdav version header is independent of build type # -# +# Generate one copy in the top-level, this is installed to +# multiple locations (per-Qt-version) ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX QWebdav - VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/qwebdav_version.h" - PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/QWebdavConfigVersion.cmake" + VERSION_HEADER "${CMAKE_BINARY_DIR}/qwebdav_version.h" + PACKAGE_VERSION_FILE "${CMAKE_BINARY_DIR}/QWebdavConfigVersion.cmake" SOVERSION 1 ) -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/qwebdav_version.h" - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QWebdav - COMPONENT devel -) ### Build # diff --git a/qwebdavlib/CMakeLists.txt b/qwebdavlib/CMakeLists.txt index 46f89ba..ad7dff4 100644 --- a/qwebdavlib/CMakeLists.txt +++ b/qwebdavlib/CMakeLists.txt @@ -70,7 +70,12 @@ function(add_qwebdav_library QT_VERSION) DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav${QT_VERSION} COMPONENT devel ) - + install( + FILES + "${CMAKE_BINARY_DIR}/qwebdav_version.h" + DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav${QT_VERSION} + COMPONENT devel + ) endfunction() if(WITH_QT5) From bd033b7e06e61450bb2e4c49566af066db6d7fb5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Feb 2026 12:39:39 +0100 Subject: [PATCH 5/9] CMake: fix up example build When building as part of QWebdav, we need a different way to get the library alias (preferring Qt6). --- qwebdavlibExample/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qwebdavlibExample/CMakeLists.txt b/qwebdavlibExample/CMakeLists.txt index afffeef..ba5393e 100644 --- a/qwebdavlibExample/CMakeLists.txt +++ b/qwebdavlibExample/CMakeLists.txt @@ -13,8 +13,15 @@ project(QWebdavExample set(CMAKE_AUTOMOC ON) # If we're building as part of the QWebDAV top-level build, we already -# have the target QWebdav available. In that case, do only the CMake- -# based build. +# have a QWebdav target available -- prefer Qt6, and give it an alias. + +if(TARGET qwebdav-qt6) + add_library(QWebdav ALIAS qwebdav-qt6) +elseif(TARGET qwebdav-qt5) + add_library(QWebdav ALIAS qwebdav-qt5) +endif() + +# If we have a QWebdav target, do only the CMake-based build. if(NOT TARGET QWebdav) # Outside of the QWebDAV top-level build, demonstrate both # CMake and pkgconfig approaches. From b69daca1667d49c865fb1599e1bbb84a2b9883da Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Feb 2026 14:30:35 +0100 Subject: [PATCH 6/9] CMake: install config-files with versioned names --- CMakeLists.txt | 21 --------------------- qwebdavlib/CMakeLists.txt | 30 +++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3564452..f9522c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,27 +95,6 @@ ecm_setup_version(${PROJECT_VERSION} add_subdirectory(qwebdavlib) add_subdirectory(qwebdavlibExample) -### CMake Configuration Files -# -# -configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/QWebdavConfig.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/QWebdavConfig.cmake" - INSTALL_DESTINATION ${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav -) -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/QWebdavConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/QWebdavConfigVersion.cmake" - DESTINATION "${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav" - COMPONENT devel -) -install( - EXPORT QWebdavTargets - DESTINATION "${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav" - FILE QWebdavTargets.cmake -) - ### PackageConfig files # # These are slightly different from the qmake-produced diff --git a/qwebdavlib/CMakeLists.txt b/qwebdavlib/CMakeLists.txt index ad7dff4..6a57c7e 100644 --- a/qwebdavlib/CMakeLists.txt +++ b/qwebdavlib/CMakeLists.txt @@ -47,7 +47,7 @@ function(add_qwebdav_library QT_VERSION) install( TARGETS qwebdav-qt${QT_VERSION} - EXPORT QWebdavTargets + EXPORT QWebdav${QT_VERSION}Targets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) @@ -76,6 +76,34 @@ function(add_qwebdav_library QT_VERSION) DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav${QT_VERSION} COMPONENT devel ) + + ### CMake Configuration Files + # + # + configure_package_config_file( + "${CMAKE_SOURCE_DIR}/QWebdavConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/QWebdav${QT_VERSION}Config.cmake" + INSTALL_DESTINATION ${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav${QT_VERSION} + ) + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/QWebdav${QT_VERSION}Config.cmake" + DESTINATION "${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav${QT_VERSION}" + COMPONENT devel + ) + install( + FILES + "${CMAKE_BINARY_DIR}/QWebdavConfigVersion.cmake" + RENAME + "QWebdav${QT_VERSION}ConfigVersion.cmake" + DESTINATION "${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav${QT_VERSION}" + COMPONENT devel + ) + install( + EXPORT QWebdav${QT_VERSION}Targets + DESTINATION "${KDE_INSTALL_CMAKEPACKAGEDIR}/QWebdav${QT_VERSION}" + FILE QWebdav${QT_VERSION}Targets.cmake + ) endfunction() if(WITH_QT5) From aa9982df4cd44c6d611a463c1ae3d9f542de81f2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 19 Feb 2026 19:29:18 +0100 Subject: [PATCH 7/9] CMake: tweak install path of headers CMake-based build places them in /usr/include/qt6/qwebdav-qt6/ QMake-based build places them in /usr/include/x86_64-linux-gnu/qt6/qwebdav-qt6 This may also be a triple (on the part of qmake) to help support multiple architectures binaries packaged and installed on the same host. Tweaking it is outside the scope of this MR. --- qwebdavlib/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qwebdavlib/CMakeLists.txt b/qwebdavlib/CMakeLists.txt index 6a57c7e..f125803 100644 --- a/qwebdavlib/CMakeLists.txt +++ b/qwebdavlib/CMakeLists.txt @@ -56,6 +56,7 @@ function(add_qwebdav_library QT_VERSION) # One copy of the headers per Qt-version, even though they are # identical: this is so that you can build packages of Qt5 and Qt6 # libraries separately and they won't collide over the headers. + set(_includedir ${KDE_INSTALL_INCLUDEDIR}/qt${QT_VERSION}/qwebdav-qt${QT_VERSION}) install( FILES # Generated export-header isn't used (qwebdav_global contains similar @@ -67,13 +68,13 @@ function(add_qwebdav_library QT_VERSION) qwebdav_global.h qwebdavdirparser.h qwebdavitem.h - DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav${QT_VERSION} + DESTINATION ${_includedir} COMPONENT devel ) install( FILES "${CMAKE_BINARY_DIR}/qwebdav_version.h" - DESTINATION ${KDE_INSTALL_INCLUDEDIR}/QWebdav${QT_VERSION} + DESTINATION ${_includedir} COMPONENT devel ) From 7fa15f8f3e0276a0e7086494a0672a52ebc5614a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 19 Feb 2026 19:42:43 +0100 Subject: [PATCH 8/9] example: Tweak example to look for a Qt-version-specific QWebdav --- qwebdavlibExample/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qwebdavlibExample/CMakeLists.txt b/qwebdavlibExample/CMakeLists.txt index ba5393e..c4d2395 100644 --- a/qwebdavlibExample/CMakeLists.txt +++ b/qwebdavlibExample/CMakeLists.txt @@ -35,6 +35,11 @@ if(NOT TARGET QWebdav) if(NOT TARGET Qt5::Core AND NOT TARGET Qt6::Core) message(FATAL_ERROR "No installed Qt version found.") endif() + if(TARGET Qt6::Core) + set(QT_VERSION 6) + else() + set(QT_VERSION 5) + endif() find_package(PkgConfig) if(PkgConfig_FOUND) @@ -46,7 +51,7 @@ if(NOT TARGET QWebdav) endif() endif() - find_package(QWebdav 1.0) # Works with whatever Qt versions are installed + find_package(QWebdav${QT_VERSION} 1.0) # Works with whatever Qt versions are installed if(NOT TARGET QWebdav AND NOT TARGET PkgConfig::QWebdav) message(FATAL_ERROR "No installed QWebDAV found.") From c0bb1e773a0c2d4f040731b1e3280ffffacd243a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 19 Feb 2026 21:29:51 +0100 Subject: [PATCH 9/9] CMake: typo in message that complains about Qt6 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9522c7..3a6b38a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ if(ENABLE_QT6 AND TARGET Qt6::Core) set(WITH_QT6 TRUE) endif() if(ENABLE_QT6 AND NOT TARGET Qt6::Core) - message(STATUS "Qt5 enabled but not found.") + message(STATUS "Qt6 enabled but not found.") endif() if(NOT TARGET Qt5::Core AND NOT TARGET Qt6::Core) # If neither is found, complain about Qt5 because then the