From 653d2dd3e0f156ec57605b506b61edc5252af583 Mon Sep 17 00:00:00 2001 From: Diego Iastrubni Date: Fri, 6 May 2022 13:55:12 +0300 Subject: [PATCH] Add support for Qt6 building using CMake This commit fixes build of the appplication using Qt6 (fixed all upstreams I needed). Tested scenarios (locally): - Debian Qt5 - Windows Qt6 (Using MinGW) I will assume that Debian Qt6 will work, and Qt6/5 MSVC will work. If not - the CI will find it (lol). Next steps: - Finish windows installer - Finish OS bundle - Revert back to ninja? - Document how to use CPM cache - Document how to handle a scenario in which the user has Qt5 and Qt6 installed. I am unsure how this works at all. --- CMakeLists.txt | 17 +++++++++++------ src/NotepadNext/CMakeLists.txt | 29 +++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 086f7c73c..2fb3f88c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,10 @@ set(BUILD_BINARY OFF) set(USE_BUILD_SHARED_LIBS CACHE BOOL OFF) set(BUILD_STATICCACHE OFF) +# Qt single app... is being petty +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) +set(QT_DEFAULT_MAJOR_VERSION ${QT_VERSION_MAJOR}) + # setup singleapplication - we want the GUI application, not console set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication") @@ -37,25 +41,26 @@ CPMAddPackage("gh:itay-grudev/SingleApplication#v3.3.4") # this a a repack of the 8426d9b4d4df1da3c5b2d759e509ae1c50a86667 upstream version with a cmake file CPMAddPackage("gh:elcuco/lua#9f06e8ad5b562d71c10fb38e6213c2a07465191a") -#include(lua.cmake) # this a a repack of the upstream#52820d5 with a cmake file (upstream does # not support building the library, but only unit tests) -CPMAddPackage("gh:elcuco/editorconfig-core-qt#ffd7d12657fb543a480b5c924cd450c31d107c72") +CPMAddPackage("gh:elcuco/editorconfig-core-qt#d3d0573066a60cdf73537cfd89e6d90f843daea3") # this a a repack of the upstream#62e0ce7 with a cmake file -CPMAddPackage("gh:elcuco/QSimpleUpdater#3407c2d257cc2c1758f864df7aa8657addc5e73f") +CPMAddPackage("gh:elcuco/QSimpleUpdater#dfbbd8db78cf3c40df5fb3ee9b5a75cd50cae185") # this a a repack of the upstream#f85a8baec6f401d481341ead87f39d9fe9d284ec with a cmake file -CPMAddPackage("gh:elcuco/scintilla-code#27dca0231d437db3c1c1aedf8afd243d1854ee6c") +CPMAddPackage("gh:elcuco/scintilla-code#dd6c3c7ff6d56e24afe69716835e19c4d55db3c9") # TODO - should we backport this to a stable release? # this a a repack of the upstream#0bd13d84b3fef7a72553ab95c43d0d4c9677f70f with a cmake file CPMAddPackage("gh:elcuco/lexilla#270fb410dd7518736141c9c9c84880b938d957a7") -# Instead of the two above, you can use a moving branch. Both track -# upstream `master`. Seem to compile and work. +# Instead of the repos above, you can use a moving branch. All track +# upstream `master`. +#CPMAddPackage("gh:elcuco/editorconfig-core-qt#cmake-support") #CPMAddPackage("gh:elcuco/scintilla-code#cmake-support") +#CPMAddPackage("gh:elcuco/QSimpleUpdater#cmake-support") #CPMAddPackage("gh:elcuco/lexilla#cmake-support") add_subdirectory(src/NotepadNext) diff --git a/src/NotepadNext/CMakeLists.txt b/src/NotepadNext/CMakeLists.txt index 9b4bf564a..d537369ab 100644 --- a/src/NotepadNext/CMakeLists.txt +++ b/src/NotepadNext/CMakeLists.txt @@ -2,7 +2,14 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) -find_package(Qt5 COMPONENTS Widgets PrintSupport REQUIRED) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Core Gui Network Widgets PrintSupport REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Network Widgets PrintSupport) + +# TODO: why do I need to add print support also here? +if (Qt6_FOUND) + find_package(Qt6 REQUIRED COMPONENTS Core5Compat PrintSupport) +endif() + set(CMAKE_INCLUDE_CURRENT_DIR ON) add_executable(NotepadNext @@ -115,7 +122,9 @@ add_executable(NotepadNext scripts.qrc ) -target_link_libraries(NotepadNext Qt5::Widgets Qt5::PrintSupport +# TODO: why do I need to add print support also here? +target_link_libraries(NotepadNext ${QT_LIBRARIES} + Qt::PrintSupport libuchardet_static lua LuaBridge @@ -126,11 +135,23 @@ target_link_libraries(NotepadNext Qt5::Widgets Qt5::PrintSupport scintilla-qt-edit lexzilla ) + +if (Qt6_FOUND) + target_link_libraries(NotepadNext Qt6::Core5Compat) +endif() + +if(UNIX AND NOT APPLE) + # TODO: For some reason - this library slips the linking part. + target_link_libraries(NotepadNext xcb) +endif() + target_include_directories(NotepadNext PRIVATE decorators dialogs docks widgets src) target_compile_definitions(NotepadNext PRIVATE APP_VERSION="0.5.0") target_compile_definitions(NotepadNext PRIVATE APP_COPYRIGHT="Copyright 2019-2022 Justin Dailey") target_compile_definitions(NotepadNext PRIVATE CMAKE_EXPERIMENTAL) + +# TODO - this needs to be removed from this file. if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") target_compile_options(NotepadNext PRIVATE -Wall -Wextra -pedantic --warn-no-unused-variable -Wformat -Wformat-security) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -142,10 +163,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") target_link_options(NotepadNext PRIVATE /guard:cf) endif() -# For some reason - this library slips the linking part. -if(UNIX AND NOT APPLE) - target_link_libraries(NotepadNext xcb) -endif() include(GNUInstallDirs) install(TARGETS NotepadNext)