From e324d82d56efc02f27d09b8becfa5cf39150fea8 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Tue, 19 Jan 2021 18:37:35 -0300 Subject: [PATCH] Allow Compilation with Qt6 --- CMakeLists.txt | 17 ++++++++--------- demos/async1/CMakeLists.txt | 4 ++-- demos/demo1/CMakeLists.txt | 4 ++-- demos/demo2/CMakeLists.txt | 22 +++++++++++++--------- demos/demo2/demo2.cpp | 2 ++ demos/demo3/CMakeLists.txt | 4 ++-- demos/demo4/CMakeLists.txt | 4 ++-- src/CMakeLists.txt | 30 +++++++++++++++--------------- src/mimemessage.cpp | 1 + 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14d1b06..7076e7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,11 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.9) project(libsimplemail VERSION 2.3.0 LANGUAGES CXX) include(GNUInstallDirs) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Network REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} 5.5.0 COMPONENTS Core Network REQUIRED) + set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_VISIBILITY_PRESET hidden) @@ -17,8 +20,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) option(BUILD_SHARED_LIBS "Build in shared lib mode" ON) -find_package(Qt5 5.5.0 REQUIRED COMPONENTS Core Network) - set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -42,8 +43,6 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) "/usr" CACHE PATH "simplemail default install prefix" FORCE) endif() -include(GNUInstallDirs) - add_definitions("-DLOCALSTATEDIR=\"${LOCALSTATEDIR}\"") set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_LIBRARY_ARCHITECTURE}" CACHE PATH "Output directory for libraries") @@ -81,21 +80,21 @@ include_directories( # cmake config files configure_file(${CMAKE_MODULE_PATH}/simplemailqt5-config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt5Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt${QT_VERSION_MAJOR}Config.cmake @ONLY ) configure_file(${CMAKE_MODULE_PATH}/simplemailqt5-config-version.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt5ConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt${QT_VERSION_MAJOR}ConfigVersion.cmake @ONLY ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt5Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt5ConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail2Qt${QT_VERSION_MAJOR}ConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SimpleMail2Qt5/ ) install(EXPORT SimpleMailTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SimpleMail${PROJECT_VERSION_MAJOR}Qt5/ - FILE SimpleMail${PROJECT_VERSION_MAJOR}Qt5Targets.cmake + FILE SimpleMail${PROJECT_VERSION_MAJOR}Qt${QT_VERSION_MAJOR}Targets.cmake NAMESPACE SimpleMail:: COMPONENT Devel ) diff --git a/demos/async1/CMakeLists.txt b/demos/async1/CMakeLists.txt index 110f91f..ab6d2fd 100644 --- a/demos/async1/CMakeLists.txt +++ b/demos/async1/CMakeLists.txt @@ -7,6 +7,6 @@ add_executable(async1 ) target_link_libraries(async1 - SimpleMail2Qt5::Core - Qt5::Core + SimpleMail2Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Core ) diff --git a/demos/demo1/CMakeLists.txt b/demos/demo1/CMakeLists.txt index 51f68b2..f4542b0 100644 --- a/demos/demo1/CMakeLists.txt +++ b/demos/demo1/CMakeLists.txt @@ -7,6 +7,6 @@ add_executable(demo1 ) target_link_libraries(demo1 - SimpleMail2Qt5::Core - Qt5::Core + SimpleMail2Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Core ) diff --git a/demos/demo2/CMakeLists.txt b/demos/demo2/CMakeLists.txt index 6c43c13..e49f825 100644 --- a/demos/demo2/CMakeLists.txt +++ b/demos/demo2/CMakeLists.txt @@ -1,22 +1,26 @@ -find_package(Qt5 5.4.0 REQUIRED COMPONENTS - Widgets -) +find_package(Qt${QT_VERSION_MAJOR} 5.5.0 COMPONENTS Widgets REQUIRED) set(demo_SRCS sendemail.cpp demo2.cpp ) -qt5_wrap_ui(demo_SRCS - sendemail.ui -) +if (${QT_VERSION_MAJOR} EQUAL 5) + qt5_wrap_ui(demo_SRCS + sendemail.ui + ) +else () + qt6_wrap_ui(demo_SRCS + sendemail.ui + ) +endif () add_executable(demo2 ${demo_SRCS} ) target_link_libraries(demo2 - SimpleMail2Qt5::Core - Qt5::Core - Qt5::Widgets + SimpleMail2Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets ) diff --git a/demos/demo2/demo2.cpp b/demos/demo2/demo2.cpp index 3fa09f8..a3b298b 100644 --- a/demos/demo2/demo2.cpp +++ b/demos/demo2/demo2.cpp @@ -25,7 +25,9 @@ using namespace std; int main(int argc, char *argv[]) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif QCoreApplication::setApplicationName(QStringLiteral("SimpleMailQt")); QCoreApplication::setOrganizationName(QStringLiteral("Cutelyst")); QCoreApplication::setOrganizationDomain(QStringLiteral("org.cutelyst.simple-mail-qt")); diff --git a/demos/demo3/CMakeLists.txt b/demos/demo3/CMakeLists.txt index 9d13ae1..5e4339e 100644 --- a/demos/demo3/CMakeLists.txt +++ b/demos/demo3/CMakeLists.txt @@ -7,6 +7,6 @@ add_executable(demo3 ) target_link_libraries(demo3 - SimpleMail2Qt5::Core - Qt5::Core + SimpleMail2Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Core ) diff --git a/demos/demo4/CMakeLists.txt b/demos/demo4/CMakeLists.txt index 2013cc8..1e535ef 100644 --- a/demos/demo4/CMakeLists.txt +++ b/demos/demo4/CMakeLists.txt @@ -7,6 +7,6 @@ add_executable(demo4 ) target_link_libraries(demo4 - SimpleMail2Qt5::Core - Qt5::Core + SimpleMail2Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Core ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae26763..5c230bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,53 +46,53 @@ set(simplemailqt_HEADERS_PRIVATE # common.h ) -add_library(SimpleMail2Qt5 SHARED +add_library(SimpleMail2Qt${QT_VERSION_MAJOR} SHARED ${simplemailqt_SRC} ${simplemailqt_HEADERS} ${simplemailqt_HEADERS_PRIVATE} ) #Add an alias so that library can be used inside the build tree, e.g. when testing -add_library(SimpleMail${PROJECT_VERSION_MAJOR}Qt5::Core ALIAS SimpleMail2Qt5) +add_library(SimpleMail${PROJECT_VERSION_MAJOR}Qt${QT_VERSION_MAJOR}::Core ALIAS SimpleMail2Qt${QT_VERSION_MAJOR}) if (CMAKE_GENERATOR MATCHES "Visual Studio") - set_property(TARGET SimpleMail2Qt5 PROPERTY DEBUG_POSTFIX "d") + set_property(TARGET SimpleMail2Qt${QT_VERSION_MAJOR} PROPERTY DEBUG_POSTFIX "d") endif() -target_compile_definitions(SimpleMail2Qt5 +target_compile_definitions(SimpleMail2Qt${QT_VERSION_MAJOR} PRIVATE PLUGINS_PREFER_DEBUG_POSTFIX=$ ) -target_include_directories(SimpleMail2Qt5 PUBLIC +target_include_directories(SimpleMail2Qt${QT_VERSION_MAJOR} PUBLIC $ - $ + $ ) -set_target_properties(SimpleMail2Qt5 PROPERTIES +set_target_properties(SimpleMail2Qt${QT_VERSION_MAJOR} PROPERTIES EXPORT_NAME Core VERSION ${PROJECT_VERSION} SOVERSION 0 ) -target_link_libraries(SimpleMail2Qt5 +target_link_libraries(SimpleMail2Qt${QT_VERSION_MAJOR} PUBLIC - Qt5::Core - Qt5::Network + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Network ) -set_property(TARGET SimpleMail2Qt5 PROPERTY PUBLIC_HEADER ${simplemailqt_HEADERS}) -install(TARGETS SimpleMail2Qt5 +set_property(TARGET SimpleMail2Qt${QT_VERSION_MAJOR} PROPERTY PUBLIC_HEADER ${simplemailqt_HEADERS}) +install(TARGETS SimpleMail2Qt${QT_VERSION_MAJOR} EXPORT SimpleMailTargets DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION bin COMPONENT runtime ARCHIVE DESTINATION lib COMPONENT devel - PUBLIC_HEADER DESTINATION include/simplemail2-qt5/SimpleMail COMPONENT devel + PUBLIC_HEADER DESTINATION include/simplemail2-qt${QT_VERSION_MAJOR}/SimpleMail COMPONENT devel ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/simplemail-qt5.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail${PROJECT_VERSION_MAJOR}Qt5.pc + ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail${PROJECT_VERSION_MAJOR}Qt${QT_VERSION_MAJOR}.pc @ONLY ) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail${PROJECT_VERSION_MAJOR}Qt5.pc +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SimpleMail${PROJECT_VERSION_MAJOR}Qt${QT_VERSION_MAJOR}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) diff --git a/src/mimemessage.cpp b/src/mimemessage.cpp index 047947f..f59919a 100644 --- a/src/mimemessage.cpp +++ b/src/mimemessage.cpp @@ -22,6 +22,7 @@ x #include "quotedprintable.h" #include +#include #include #include