Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues preventing library from building with Qt 6 #9

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: MIT

Expand All @@ -13,14 +13,17 @@ jobs:
fail-fast: true
matrix:
os:
- macos-12
- macos-11
- macos-latest
build_type:
- Debug
- Release
qt:
- version: "5.15.2"
requested: "5.15"
architectures: "x86_64"
- version: "6.4.*"
requested: "6.4"
architectures: "x86_64;arm64"

steps:
- name: Install Qt with options and default aqtversion
Expand All @@ -34,16 +37,14 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4

- name: Create build directory
run: mkdir build

- name: Install ninja-build tool (must be after Qt due PATH changes)
uses: turtlesec-no/get-ninja@main

- name: Configure project
run: >
cmake -S . -B ./build -G Ninja
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.qt.architectures }}"

- name: Build Project
run: cmake --build ./build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ lib
.qmake.cache
.qmake.stash
.DS_Store
CMakeLists.txt.user
**/build/**
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.12)

if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
set(USE_DEFAULT_INSTALL_LOCATION True)
Expand All @@ -13,30 +13,32 @@ if(NOT CMAKE_BUILD_TYPE)
endif()

set(${PROJECT_NAME}_VERSION_MAJOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 0)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH})

if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_COMPILER_IS_GNUCXX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD 11)

if(USE_DEFAULT_INSTALL_LOCATION)
set(CMAKE_INSTALL_PREFIX "/usr/local/KDAB/${PROJECT_NAME}-${${PROJECT_NAME}_VERSION}" CACHE STRING "" FORCE)
endif()

message(STATUS "Building ${PROJECT_NAME} ${${PROJECT_NAME}_VERSION} in ${CMAKE_BUILD_TYPE} mode. Installing to ${CMAKE_INSTALL_PREFIX}")

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(QT NAMES Qt6 Qt5)
if("${QT_VERSION_MAJOR}" STREQUAL "5")
set(QT_REQUIRED_VERSION "5.15.2")
else()
set(QT_REQUIRED_VERSION "6.4.0")
endif()

find_package(Qt${QT_VERSION_MAJOR} ${QT_REQUIRED_VERSION}
COMPONENTS Core Widgets
REQUIRED)

set(CMAKE_AUTOMOC TRUE)
set(QT_LIBRARIES Qt5::Widgets)
set(QT_USE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Qt5Portability.cmake")
set(QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Widgets)
set(QT_USE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Qt${QT_VERSION_MAJOR}Portability.cmake")

install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/KDMacTouchBarConfig.cmake"
Expand Down
32 changes: 32 additions & 0 deletions cmake/Qt6Portability.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

include_directories(${QtWidgets_INCLUDE_DIRS})

if(QT_USE_QTNETWORK)
find_package(QtNetwork REQUIRED)
list(APPEND QT_LIBRARIES Qt::Network)
include_directories(${QtNetwork_INCLUDE_DIRS})
endif()

if(QT_USE_QTXML)
find_package(QtXml REQUIRED)
list(APPEND QT_LIBRARIES Qt::Xml)
include_directories(${QtXml_INCLUDE_DIRS})
endif()

if(QT_USE_QTTEST)
find_package(QtTest REQUIRED)
list(APPEND QT_LIBRARIES Qt::Test)
include_directories(${QtTest_INCLUDE_DIRS})
endif()

macro(qt4_wrap_ui)
qt_wrap_ui(${ARGN})
endmacro()

macro(qt4_wrap_cpp)
qt_wrap_cpp(${ARGN})
endmacro()

macro(qt4_add_resources)
qt_add_resources(${ARGN})
endmacro()
4 changes: 2 additions & 2 deletions examples/mactouchbar/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** All rights reserved.
**
** This file is part of the KD MacTouchBar library.
Expand Down Expand Up @@ -34,7 +34,7 @@

MainWindow::MainWindow()
{
setWindowTitle("KDMacTouchBar Example");
setWindowTitle(tr("KDMacTouchBar Example"));
resize(400, 200);

// attach a touchbar to this window
Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ add_library(KDMacTouchBar SHARED
kdmactouchbar.mm
${HEADERS})

install(TARGETS KDMacTouchBar
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")

target_link_libraries(KDMacTouchBar ${QT_LIBRARIES} "-framework Cocoa")

set_target_properties(KDMacTouchBar PROPERTIES
Expand All @@ -22,3 +19,6 @@ set_target_properties(KDMacTouchBar PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib"
MACOSX_RPATH TRUE
)

install(TARGETS KDMacTouchBar
LIBRARY FRAMEWORK DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
4 changes: 2 additions & 2 deletions src/kdmactouchbar.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
** Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected].
** All rights reserved.
**
** This file is part of the KD MacTouchBar library.
Expand Down Expand Up @@ -49,7 +49,7 @@

auto nsImage = [[[NSImage alloc] initWithSize:NSZeroSize] autorelease];

for (const auto& size : qAsConst(sizes)) {
for (const auto& size : sizes) {
const QImage qimage = icon.pixmap(size).toImage();
CGImageRef cgImage = qimage.toCGImage();
if (!cgImage)
Expand Down