diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b74bdf1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,136 @@ +cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR) + +project(QWebdav + VERSION 1.0 + DESCRIPTION "WebDAV server access" + HOMEPAGE_URL "https://github.com/fredldotme/qwebdavlib" + LANGUAGES CXX +) + +### Find ECM up-front and complain otherwise +# +# +include(FeatureSummary) +find_package(ECM 5.103.0 NO_MODULE) +set_package_properties(ECM + PROPERTIES + TYPE REQUIRED + DESCRIPTION "Extra modules and scripts for CMake" + URL "https://invent.kde.org/frameworks/extra-cmake-modules" +) +feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES) + +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) + +include(KDEInstallDirs) +include(KDECMakeSettings) + +include(GenerateExportHeader) + +include(ECMSetupVersion) +include(ECMGenerateHeaders) +include(CMakePackageConfigHelpers) + +### Find available Qt build types +# +# +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) + +set(WITH_QT5 FALSE) # Used when creating the Config.cmake file +set(WITH_QT6 FALSE) +if(TARGET Qt5::Core) + message(STATUS "Building Qt5 version of ${PROJECT_NAME}") + set(WITH_QT5 TRUE) +endif() +if(TARGET Qt6::Core) + message(STATUS "Building Qt6 version of ${PROJECT_NAME}") + set(WITH_QT6 TRUE) +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. + set_package_properties(Qt5 + PROPERTIES + TYPE REQUIRED + DESCRIPTION "Qt libraries (version 5 or 6)" + URL "https://qt.io/" + ) +endif() + +### QWebdav version header is independent of build type +# +# +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" + SOVERSION 1 +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/qwebdav_version.h" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QWebdav + COMPONENT devel +) + +### Build +# +# +add_subdirectory(qwebdavlib) + +### 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 +# ones because the naming of the library is different +# and the installation-directories are, also. +if(WITH_QT5) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/qwebdavlib/qwebdav-qt5.cmake.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/qwebdav-qt5.pc" + @ONLY + ) + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/qwebdav-qt5.pc" + DESTINATION ${KDE_INSTALL_LIBDIR}/pkgconfig + ) +endif() +if(WITH_QT6) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/qwebdavlib/qwebdav-qt6.cmake.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/qwebdav-qt6.pc" + @ONLY + ) + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/qwebdav-qt6.pc" + DESTINATION ${KDE_INSTALL_LIBDIR}/pkgconfig + ) +endif() + +feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/QWebdavConfig.cmake.in b/QWebdavConfig.cmake.in new file mode 100644 index 0000000..67f404d --- /dev/null +++ b/QWebdavConfig.cmake.in @@ -0,0 +1,29 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +set(_qwebdav_WITH_QT5 @WITH_QT5@) +set(_qwebdav_WITH_QT6 @WITH_QT6@) + +set(QT_NO_CREATE_VERSIONLESS_TARGETS ON) + +if(_qwebdav_WITH_QT5) + find_dependency(Qt5Core @QT5_REQUIRED_VERSION@) + find_dependency(Qt5Network @QT5_REQUIRED_VERSION@) + find_dependency(Qt5Xml @QT5_REQUIRED_VERSION@) +endif() + +if(_qwebdav_WITH_QT6) + find_dependency(Qt6Core @QT6_REQUIRED_VERSION@) + find_dependency(Qt6Network @QT6_REQUIRED_VERSION@) + find_dependency(Qt6Xml @QT6_REQUIRED_VERSION@) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/QWebdavTargets.cmake") + +# Versionless alias, prefer Qt6 over Qt5 +if(_qwebdav_WITH_QT6) + add_library(QWebdav ALIAS QWebdav-qt6) +else() + add_library(QWebdav ALIAS QWebdav-qt5) +endif() diff --git a/qwebdavlib/CMakeLists.txt b/qwebdavlib/CMakeLists.txt index a597b3b..a1d3652 100644 --- a/qwebdavlib/CMakeLists.txt +++ b/qwebdavlib/CMakeLists.txt @@ -1,39 +1,80 @@ -# Generated from qwebdavlib.pro. - -##################################################################### -## qwebdav Generic Library: -##################################################################### - -qt_internal_add_cmake_library(qwebdav - SOURCES - qnaturalsort.cpp qnaturalsort.h - qwebdav.cpp qwebdav.h - qwebdav_global.h - qwebdavdirparser.cpp qwebdavdirparser.h - qwebdavitem.cpp qwebdavitem.h - DEFINES - QWEBDAVITEM_EXTENDED_PROPERTIES - QWEBDAV_LIBRARY - PUBLIC_LIBRARIES - Qt::Core - Qt::Network - Qt::Xml - COMPILE_OPTIONS - -Wno-overloaded-virtual -) +# Boilerplate for building the library against a given Qt version +function(add_qwebdav_library QT_VERSION) + add_library(QWebdav-qt${QT_VERSION}) + target_sources(QWebdav-qt${QT_VERSION} + PRIVATE + qnaturalsort.cpp + qwebdav.cpp + qwebdavdirparser.cpp + qwebdavitem.cpp + ) -#### Keys ignored in scope 1:.:.:qwebdavlib.pro:: -# INSTALLS = "target" -# OTHER_FILES = "CHANGES" "LICENSE" "README" -# TEMPLATE = "lib" + target_compile_definitions(QWebdav-qt${QT_VERSION} + PRIVATE + QWEBDAV_LIBRARY=1 + QWEBDAVITEM_EXTENDED_PROPERTIES=1 + ) + if(CMAKE_BUILD_TYPE STREQUAL Release) + target_compile_definitions(QWebdav-qt${QT_VERSION} + PRIVATE + QT_NO_DEBUG_OUTPUT=1 + ) + endif() -## Scopes: -##################################################################### + target_compile_options(QWebdav-qt${QT_VERSION} + PRIVATE + -Wno-overloaded-virtual + ) -qt_internal_extend_target(qwebdav CONDITION CMAKE_BUILD_TYPE STREQUAL Release - DEFINES - QT_NO_DEBUG_OUTPUT -) + target_include_directories(QWebdav-qt${QT_VERSION} + INTERFACE + "$" + ) + + target_link_libraries(QWebdav-qt${QT_VERSION} + PUBLIC + Qt${QT_VERSION}::Core + Qt${QT_VERSION}::Network + Qt${QT_VERSION}::Xml + ) + + set_target_properties(QWebdav-qt${QT_VERSION} + PROPERTIES + VERSION ${QWebdav_VERSION} + SOVERSION ${QWebdav_SOVERSION} + EXPORT_NAME "QWebdav-qt${QT_VERSION}" + ) -#### Keys ignored in scope 2:.:.:qwebdavlib.pro:(CMAKE_BUILD_TYPE STREQUAL Release): -# QMAKE_POST_LINK = "$(STRIP)" "$(TARGET)" + install( + TARGETS QWebdav-qt${QT_VERSION} + EXPORT QWebdavTargets + ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} + ) +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 +) diff --git a/qwebdavlib/qwebdav-qt5.cmake.pc.in b/qwebdavlib/qwebdav-qt5.cmake.pc.in new file mode 100644 index 0000000..ffccb51 --- /dev/null +++ b/qwebdavlib/qwebdav-qt5.cmake.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@CMAKE_INSTALL_PREFIX@/@KDE_INSTALL_LIBDIR@ +includedir=${prefix}/include/QWebdav + +Name: libqwebdav-qt5 +Description: Qt WebDAV library +Version: $$VERSION +Libs: -L${libdir} -lQWebdav-qt5 +Requires: Qt5Core Qt5Network Qt5Xml +Cflags: -I${includedir} + diff --git a/qwebdavlib/qwebdav-qt6.cmake.pc.in b/qwebdavlib/qwebdav-qt6.cmake.pc.in new file mode 100644 index 0000000..5ea22c8 --- /dev/null +++ b/qwebdavlib/qwebdav-qt6.cmake.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@CMAKE_INSTALL_PREFIX@/@KDE_INSTALL_LIBDIR@ +includedir=${prefix}/include/QWebdav + +Name: libqwebdav-qt6 +Description: Qt WebDAV library +Version: $$VERSION +Libs: -L${libdir} -lQWebdav-qt6 +Requires: Qt6Core Qt6Network Qt6Xml +Cflags: -I${includedir} + diff --git a/qwebdavlibExample/CMakeLists.txt b/qwebdavlibExample/CMakeLists.txt new file mode 100644 index 0000000..4c5b5de --- /dev/null +++ b/qwebdavlibExample/CMakeLists.txt @@ -0,0 +1,26 @@ +# QWebdav example application +# +# This example shows how to find QWebdav after is has been built and installed. +cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR) + +project(QWebdavExample + VERSION 1.0 + DESCRIPTION "QWebDAV Example" + HOMEPAGE_URL "https://github.com/fredldotme/qwebdavlib" + LANGUAGES CXX +) + +set(CMAKE_AUTOMOC ON) + +find_package(QWebdav REQUIRED) + +add_executable(QWebdavExample) +target_sources(QWebdavExample + PRIVATE + main.cpp + qexample.cpp +) +target_link_libraries(QWebdavExample + PRIVATE + QWebdav +)