Skip to content

Commit

Permalink
💥 Qt6 support (#157)
Browse files Browse the repository at this point in the history
This PR introduce some breaking change:
- Stop support for Qt5
- Not sure WASM works
- Not sure static works (ios) (I guess Qt is doing that by itself now)
- Installing only work for shared library. This is what you generally
want anyway.

On the new features:
- It works with Qt6 using qt5compat module for effect
- It uses qt6 macros (that is why installation doesn't work anymore) and
drop my QtGeneratorCmake dependency
- flake dev shell, to quickly get a working dev env

Thanks to #111 and
#135 for the prep work

---------

Co-authored-by: Beautify Robot <[email protected]>
  • Loading branch information
OlivierLDff and Beautify Robot authored Aug 20, 2024
1 parent 5ec5e85 commit 77082aa
Show file tree
Hide file tree
Showing 365 changed files with 1,288 additions and 1,207 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
89 changes: 0 additions & 89 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

77 changes: 29 additions & 48 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,52 @@ name: 👷 Continuous Deployment
on:
push:
branches:
- master
- ci

- main
pull_request:
branches:
- master
types: [opened, synchronize, unlabeled]
workflow_dispatch:

jobs:
Build:
BuildQt6:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-13, windows-latest]
version: ['5.15.2']
include:
- os: ubuntu-latest
enable_icons: 'ON'
- os: ubuntu-latest
enable_icons: 'OFF'
- os: macOS-13
enable_icons: 'ON'
- os: windows-latest
enable_icons: 'ON'
os: [ubuntu-latest, macOS-latest, windows-latest]
qt-version: ['6.6.2']
enable_icons: ['ON', 'OFF']
build_shared: ['ON', 'OFF']

steps:
-
uses: actions/checkout@v2
-
name: 📦 Cache Qt
id: cache-qt
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/Qt-${{ runner.os }}-${{ matrix.version }}
key: ${{ runner.os }}-QtCache-${{ matrix.version }}-modules
uses: actions/checkout@v4
-
name: ⬇ Install Qt
uses: jurplel/install-qt-action@v3
uses: jurplel/install-qt-action@v4
with:
version: ${{ matrix.version }}
dir: ${{ github.workspace }}/Qt-${{ runner.os }}-${{ matrix.version }}
cached: ${{ steps.cache-qt.outputs.cache-hit }}
modules: ''
version: ${{ matrix.qt-version }}
cache: true
modules: 'qt5compat qtshadertools'
-
name: Enable ninja on ubuntu
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get install ninja-build
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
-
name: Enable ninja on macOS
if: contains(matrix.os, 'macOS')
run: |
brew install ninja
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
-
name: 🔧 CMake
run: |
cmake --version
cmake -E make_directory build
cmake \
-DQATERIAL_ENABLE_TESTS=ON \
-DQATERIAL_ENABLE_ICONS=${{ matrix.enable_icons }} \
-DBUILD_SHARED_LIBS=${{ matrix.build_shared }} \
-DCMAKE_BUILD_TYPE="Release" \
-DCPM_SOURCE_CACHE=.cpm \
-B build \
Expand All @@ -77,6 +74,7 @@ jobs:
-
name: 🚀 Install Qaterial
run: cmake --install build --prefix install
if: contains(matrix.build_shared, 'ON')
-
name: ✅ Test install work with find_package
run: |
Expand All @@ -92,21 +90,4 @@ jobs:
--config "Release" \
-j
shell: bash

BuildWasm:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- docker-image: 'reivilo1234/qt-webassembly-cmake:qt5.15-em1.39.8'

steps:
-
uses: actions/checkout@v2
-
name: 🔧 Configure
run: mkdir -p build && docker run --rm -v $(pwd):/src/ -u $(id -u):$(id -g) ${{ matrix.docker-image }} cmake -DQATERIAL_ENABLE_PCH=OFF -DQATERIAL_ENABLE_UNITY_BUILD=OFF -B ./build/ -S . ..
-
name: 🔨 Build
run: docker run --rm -v $(pwd):/src/ -u $(id -u):$(id -g) ${{ matrix.docker-image }} make -C build -j
if: contains(matrix.build_shared, 'ON')
59 changes: 35 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR)

set(QATERIAL_MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
Expand All @@ -35,7 +35,7 @@ set(QATERIAL_PROJECT "Qaterial" CACHE STRING "Project Name")
set(QATERIAL_TARGET ${QATERIAL_PROJECT} CACHE STRING "Target Name")
set(QATERIAL_FOLDER_PREFIX ${QATERIAL_PROJECT} CACHE STRING "Prefix folder for all Qaterial generated targets in generated project (only decorative)")
set(QATERIAL_VERBOSE ${QATERIAL_MAIN_PROJECT} CACHE BOOL "Qaterial log configuration")
set(QATERIAL_BUILD_SHARED OFF CACHE BOOL "Build as a shared library")
set(QATERIAL_BUILD_SHARED ${BUILD_SHARED_LIBS} CACHE BOOL "Build as a shared library")
set(QATERIAL_ENABLE_TESTS OFF CACHE BOOL "Build Qaterial test executable")
set(QATERIAL_ENABLE_PCH ON CACHE BOOL
"Enable precompile headers support for 'Qaterial'. \"
Expand All @@ -54,7 +54,13 @@ set(QATERIAL_ENABLE_LATO ON CACHE BOOL "Embed to qrc Lato Regular")
# This stays as an option if legacy behavior is desired (for example to do hot reload of qml)
set(QATERIAL_ENABLE_GEN_QMLDIR_BINARY_DIR ON CACHE BOOL "Generate `qmldir` file in binary folder instead of source folder")

set(QATERIAL_ENABLE_INSTALL ${QATERIAL_MAIN_PROJECT} CACHE BOOL "Generate the install target")
if(QATERIAL_MAIN_PROJECT AND QATERIAL_BUILD_SHARED)
set(_default_QATERIAL_ENABLE_INSTALL ON)
else()
set(_default_QATERIAL_ENABLE_INSTALL OFF)
endif()

set(QATERIAL_ENABLE_INSTALL ${_default_QATERIAL_ENABLE_INSTALL} CACHE BOOL "Generate the install target")

project(${QATERIAL_PROJECT} VERSION ${QATERIAL_VERSION} LANGUAGES CXX)
if(QATERIAL_MAIN_PROJECT)
Expand Down Expand Up @@ -94,21 +100,24 @@ endif()

# ───── QT DEPENDENCIES ─────

find_package(Qt5 REQUIRED COMPONENTS
find_package(Qt6 REQUIRED COMPONENTS
Core
Gui
Qml
Quick
QuickControls2
Svg
Xml
QuickCompiler
Core5Compat
)

if(QATERIAL_MAIN_PROJECT)
qt_standard_project_setup()
endif()

# ───── FETCH DEPENDENCIES ─────

include(cmake/FetchQOlm.cmake)
include(cmake/FetchQtGeneratorCMake.cmake)

# ───── RESSOURCES ─────

Expand Down Expand Up @@ -184,10 +193,10 @@ set(QATERIAL_SRCS ${QATERIAL_SRCS} ${QATERIAL_GEN_SRCS})
# ───── QATERIAL TARGET ─────

if(${QATERIAL_BUILD_SHARED})
add_library(${QATERIAL_TARGET} SHARED ${QATERIAL_SRCS})
qt_add_library(${QATERIAL_TARGET} SHARED ${QATERIAL_SRCS})
target_compile_definitions(${QATERIAL_TARGET} PRIVATE -DQATERIAL_SHARED)
else()
add_library(${QATERIAL_TARGET} STATIC ${QATERIAL_SRCS})
qt_add_library(${QATERIAL_TARGET} STATIC ${QATERIAL_SRCS})
target_compile_definitions(${QATERIAL_TARGET} PUBLIC -DQATERIAL_STATIC)
endif()
add_library(${QATERIAL_TARGET}::${QATERIAL_TARGET} ALIAS ${QATERIAL_TARGET})
Expand All @@ -202,23 +211,21 @@ if(QATERIAL_ENABLE_PCH AND COMMAND target_precompile_headers)
target_precompile_headers(${QATERIAL_TARGET} PRIVATE src/Qaterial/Pch/Pch.hpp)
endif()

target_link_libraries(${QATERIAL_TARGET} PRIVATE
${QATERIAL_TARGET}::Icons
${QATERIAL_TARGET}::Fonts
${QATERIAL_TARGET}::Components
QOlm::QOlm
Qt::Core
Qt::Gui
Qt::Svg
Qt::Xml
Qt::Qml
Qt::Quick
Qt::QuickControls2
target_link_libraries(${QATERIAL_TARGET}
PRIVATE ${QATERIAL_TARGET}::Icons
PRIVATE ${QATERIAL_TARGET}::Fonts
PRIVATE ${QATERIAL_TARGET}::Components
PUBLIC QOlm::QOlm
PUBLIC Qt::Core
PUBLIC Qt::Gui
PUBLIC Qt::Svg
PUBLIC Qt::Xml
PUBLIC Qt::Qml
PUBLIC Qt::Quick
PUBLIC Qt::QuickControls2
PUBLIC Qt::Core5Compat
)

set_target_properties(${QATERIAL_TARGET} PROPERTIES
AUTOMOC TRUE
)
if(QATERIAL_ENABLE_UNITY_BUILD)
set_target_properties(${QATERIAL_TARGET} PROPERTIES UNITY_BUILD ON)
endif()
Expand All @@ -237,7 +244,7 @@ if(QATERIAL_FOLDER_PREFIX)
endif()

# Correctly link to static qt
get_target_property(QT_TARGET_TYPE Qt5::Core TYPE)
get_target_property(QT_TARGET_TYPE Qt::Core TYPE)
if(NOT QATERIAL_ENABLE_INSTALL AND ${QT_TARGET_TYPE} STREQUAL "STATIC_LIBRARY")
include(${PROJECT_SOURCE_DIR}/cmake/FetchQtStaticCMake.cmake)
qt_generate_qml_plugin_import(${QATERIAL_TARGET} QML_SRC ${CMAKE_CURRENT_SOURCE_DIR}/qml)
Expand Down Expand Up @@ -267,6 +274,10 @@ endif()
# ───── INSTALL ─────

if (QATERIAL_ENABLE_INSTALL)
if(NOT QATERIAL_BUILD_SHARED)
message(FATAL_ERROR "Qaterial must be built as a shared library to be installed")
endif()

include(GNUInstallDirs)
install(TARGETS ${QATERIAL_TARGET}
EXPORT ${QATERIAL_TARGET}Targets
Expand Down
39 changes: 1 addition & 38 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,7 @@
}
},
{
"name": "base-dev-ninja",
"hidden": true,
"inherits": "base-dev",
"generator": "Ninja",
"cacheVariables": {
"USE_CCACHE": true
}
},
{
"name": "ninja-debug",
"inherits": "base-dev-ninja",
"displayName": "Debug Ninja",
"description": "Build in Debug with Ninja generator",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "ninja-relwithdebinfo",
"inherits": "base-dev-ninja",
"displayName": "RelWithDebInfo Ninja",
"description": "Build in RelWithDebInfo with Ninja generator",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "ninja-release",
"inherits": "base-dev-ninja",
"displayName": "Release Ninja",
"description": "Build in Release with Ninja generator",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "ninja-multi",
"name": "ninja",
"inherits": "base-dev",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
Expand Down
Loading

0 comments on commit 77082aa

Please sign in to comment.