Skip to content

Commit

Permalink
Allow Compilation with Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Jan 19, 2021
1 parent b04eb6d commit e324d82
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 41 deletions.
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions demos/async1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions demos/demo1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
22 changes: 13 additions & 9 deletions demos/demo2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions demos/demo2/demo2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
4 changes: 2 additions & 2 deletions demos/demo3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions demos/demo4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
30 changes: 15 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=$<CONFIG:Debug>
)

target_include_directories(SimpleMail2Qt5 PUBLIC
target_include_directories(SimpleMail2Qt${QT_VERSION_MAJOR} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/simplemail2-qt5>
$<INSTALL_INTERFACE:include/simplemail2-qt${QT_VERSION_MAJOR}>
)

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
)
1 change: 1 addition & 0 deletions src/mimemessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ x
#include "quotedprintable.h"
#include <typeinfo>

#include <QIODevice>
#include <QDateTime>
#include <QLoggingCategory>

Expand Down

0 comments on commit e324d82

Please sign in to comment.