Skip to content

Commit b3c182e

Browse files
authored
Merge pull request #31 from KDABLabs/cmake
Port to CMake
2 parents f0af072 + 8db8fd1 commit b3c182e

File tree

12 files changed

+448
-3
lines changed

12 files changed

+448
-3
lines changed

.github/workflows/build.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2+
#
3+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
4+
5+
name: CI
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
pull_request:
12+
branches:
13+
- master
14+
15+
jobs:
16+
build:
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: true
20+
matrix:
21+
os:
22+
- ubuntu-latest
23+
# - windows-latest
24+
# - macos-15
25+
26+
steps:
27+
- name: Install Qt ${{ matrix.preset.qt_version }}
28+
uses: jurplel/install-qt-action@v3
29+
with:
30+
version: 5.15
31+
cache: true
32+
33+
- name: Install dependencies
34+
if: ${{ runner.os == 'Linux' }}
35+
run: |
36+
sudo apt update -qq
37+
sudo apt install xvfb
38+
39+
- name: Install ninja-build tool (must be after Qt due PATH changes)
40+
uses: turtlesec-no/get-ninja@main
41+
42+
- name: Checkout sources
43+
uses: actions/checkout@v4
44+
45+
- name: Make sure MSVC is found when Ninja generator is in use
46+
if: ${{ runner.os == 'Windows' }}
47+
uses: ilammy/msvc-dev-cmd@v1
48+
49+
- name: Build project (cmake)
50+
run: |
51+
cmake --preset=dev .
52+
cmake --build build-dev
53+
54+
- name: Run tests (Linux)
55+
if: ${{ runner.os == 'Linux' }}
56+
run: xvfb-run ctest --test-dir ./build-dev --verbose
57+
env:
58+
DISPLAY: ":0"

CMakeLists.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
cmake_minimum_required(VERSION 3.21)
7+
project(declarativewidgets)
8+
9+
set(CMAKE_AUTOMOC ON)
10+
set(CMAKE_AUTORCC ON)
11+
set(CMAKE_AUTOUIC ON)
12+
set(CMAKE_INCLUDE_CURRENT_DIRS ON)
13+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
14+
15+
option(USE_QT6 "Use Qt6" OFF)
16+
option(BUILD_EXAMPLES "Build the examples" ON)
17+
option(ENABLE_SANITIZERS "Enable asan/ubsan sanitizers" OFF)
18+
19+
if(USE_QT6)
20+
find_package(Qt6 6.5 NO_MODULE REQUIRED COMPONENTS Qml Widgets QuickWidgets)
21+
find_package(Qt6 6.5 NO_MODULE QUIET COMPONENTS WebEngineWidgets)
22+
set(QTMAJOR 6)
23+
else()
24+
find_package(Qt5 5.15 NO_MODULE REQUIRED COMPONENTS Qml Widgets QuickWidgets)
25+
find_package(Qt5 5.15 NO_MODULE QUIET COMPONENTS WebEngineWidgets)
26+
set(QTMAJOR 5)
27+
endif()
28+
29+
if(ENABLE_SANITIZERS)
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
31+
set(CMAKE_EXE_LINKER_FLAGS
32+
"${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined")
33+
endif()
34+
35+
set(DW_PLUGIN_IMPORT_PATH \"${CMAKE_BINARY_DIR}/qml\")
36+
37+
add_executable(runner main.cpp)
38+
39+
target_compile_definitions(
40+
runner PRIVATE -DPLUGIN_IMPORT_PATH=${DW_PLUGIN_IMPORT_PATH})
41+
42+
target_link_libraries(runner PUBLIC Qt${QTMAJOR}::Qml Qt${QTMAJOR}::Widgets)
43+
44+
set_target_properties(runner PROPERTIES OUTPUT_NAME "declarativewidgets")
45+
46+
add_subdirectory(src)
47+
add_subdirectory(ui2dw)
48+
include(CTest)
49+
if(BUILD_TESTING)
50+
add_subdirectory(tests)
51+
endif()
52+
53+
if(BUILD_EXAMPLES)
54+
add_subdirectory(examples)
55+
endif()

CMakePresets.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"version": 2,
3+
"configurePresets": [
4+
{
5+
"name": "base",
6+
"hidden": true,
7+
"generator": "Ninja",
8+
"binaryDir": "${sourceDir}/build-${presetName}",
9+
"cacheVariables": {
10+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
11+
"USE_QT6": "OFF"
12+
}
13+
},
14+
{
15+
"name": "dev",
16+
"inherits": "base",
17+
"cacheVariables": {
18+
"CMAKE_BUILD_TYPE": "Debug",
19+
"BUILD_TESTING": "ON"
20+
}
21+
},
22+
{
23+
"name": "dev-asan",
24+
"inherits": "dev",
25+
"binaryDir": "${sourceDir}/build-${presetName}",
26+
"cacheVariables": {
27+
"ENABLE_SANITIZERS": "ON"
28+
}
29+
},
30+
{
31+
"name": "rel",
32+
"inherits": "base",
33+
"binaryDir": "${sourceDir}/build-${presetName}",
34+
"cacheVariables": {
35+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
36+
"BUILD_TESTING": "OFF"
37+
}
38+
},
39+
{
40+
"name": "dev6",
41+
"inherits": "dev",
42+
"binaryDir": "${sourceDir}/build-${presetName}",
43+
"cacheVariables": {
44+
"USE_QT6": "ON"
45+
}
46+
},
47+
{
48+
"name": "rel6",
49+
"inherits": "rel",
50+
"binaryDir": "${sourceDir}/build-${presetName}",
51+
"cacheVariables": {
52+
"USE_QT6": "ON"
53+
}
54+
},
55+
{
56+
"name": "dev-asan6",
57+
"inherits": "dev6",
58+
"binaryDir": "${sourceDir}/build-${presetName}",
59+
"cacheVariables": {
60+
"ENABLE_SANITIZERS": "ON"
61+
}
62+
}
63+
]
64+
}

examples/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
if(USE_QT6)
7+
find_package(Qt6 6.5 NO_MODULE REQUIRED COMPONENTS Sql QuickWidgets)
8+
else()
9+
find_package(Qt5 5.15 NO_MODULE REQUIRED COMPONENTS Sql QuickWidgets)
10+
endif()
11+
12+
add_subdirectory(bookstore)
13+
add_subdirectory(config-editor)
14+
add_subdirectory(text-editor)

examples/bookstore/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
add_executable(bookstore main.cpp bookstore.cpp booksofauthormodel.cpp
7+
booklistproxymodel.cpp bookstore.qrc)
8+
9+
target_link_libraries(
10+
bookstore PRIVATE Qt${QTMAJOR}::Qml Qt${QTMAJOR}::Widgets
11+
Qt${QTMAJOR}::QuickWidgets Qt${QTMAJOR}::Sql)
12+
13+
if(Qt${QTMAJOR}WebEngineWidgets_FOUND)
14+
target_link_libraries(bookstore PRIVATE Qt${QTMAJOR}::WebEngineWidgets)
15+
endif()
16+
17+
target_compile_definitions(
18+
bookstore PRIVATE -DPLUGIN_IMPORT_PATH=${DW_PLUGIN_IMPORT_PATH})
19+
20+
set(QML_FILES main.qml)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
add_executable(config-editor main.cpp configeditor.cpp settingsadaptor.cpp
7+
config-editor.qrc)
8+
9+
target_link_libraries(config-editor PRIVATE Qt${QTMAJOR}::Qml
10+
Qt${QTMAJOR}::Widgets)
11+
12+
if(Qt${QTMAJOR}WebEngineWidgets_FOUND)
13+
target_link_libraries(config-editor PRIVATE Qt${QTMAJOR}::WebEngineWidgets)
14+
endif()
15+
16+
target_compile_definitions(
17+
config-editor PRIVATE -DPLUGIN_IMPORT_PATH=${DW_PLUGIN_IMPORT_PATH})
18+
19+
set(QML_FILES main.qml)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
add_executable(text-editor main.cpp editor.cpp text-editor.qrc)
7+
8+
target_link_libraries(text-editor PRIVATE Qt${QTMAJOR}::Qml
9+
Qt${QTMAJOR}::Widgets)
10+
11+
if(Qt${QTMAJOR}WebEngineWidgets_FOUND)
12+
target_link_libraries(text-editor PRIVATE Qt${QTMAJOR}::WebEngineWidgets)
13+
endif()
14+
15+
target_compile_definitions(
16+
text-editor PRIVATE -DPLUGIN_IMPORT_PATH=${DW_PLUGIN_IMPORT_PATH})
17+
18+
set(QML_FILES main.qml)

src/CMakeLists.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
set(TARGET declarativewidgets)
7+
8+
add_library(
9+
${TARGET} MODULE
10+
abstractdeclarativeobject.cpp
11+
declarativeaction.cpp
12+
declarativeactionitem.cpp
13+
declarativeboxlayout.cpp
14+
declarativebuttongroupextension.cpp
15+
declarativecolordialog.cpp
16+
declarativecomboboxextension.cpp
17+
declarativefiledialog.cpp
18+
declarativefilesystemmodelextension.cpp
19+
declarativefontdialog.cpp
20+
declarativeformlayout.cpp
21+
declarativegridlayout.cpp
22+
declarativehboxlayout.cpp
23+
declarativeicon.cpp
24+
declarativeinputdialog.cpp
25+
declarativeitemviewextension.cpp
26+
declarativelabelextension.cpp
27+
declarativelayoutextension.cpp
28+
declarativeline.cpp
29+
declarativeloaderwidget.cpp
30+
declarativemessagebox.cpp
31+
declarativeobjectextension.cpp
32+
declarativepixmap.cpp
33+
declarativeqmlcontext.cpp
34+
declarativequickwidgetextension.cpp
35+
declarativeseparator.cpp
36+
declarativespaceritem.cpp
37+
declarativestackedlayout.cpp
38+
declarativestatusbar.cpp
39+
declarativestringlistmodelextension.cpp
40+
declarativetableviewextension.cpp
41+
declarativetabstops.cpp
42+
declarativetabwidget.cpp
43+
declarativetexteditextension.cpp
44+
declarativetreeviewextension.cpp
45+
declarativevboxlayout.cpp
46+
declarativewidgetextension.cpp
47+
declarativewidgets_plugin.cpp
48+
defaultobjectcontainer.cpp
49+
defaultwidgetcontainer.cpp
50+
mainwindowwidgetcontainer.cpp
51+
menubarwidgetcontainer.cpp
52+
menuwidgetcontainer.cpp
53+
objectadaptors.cpp
54+
scrollareawidgetcontainer.cpp
55+
stackedwidgetwidgetcontainer.cpp
56+
staticdialogmethodattached.cpp
57+
toolbarwidgetcontainer.cpp
58+
declarativesizepolicy.cpp)
59+
60+
target_link_libraries(
61+
${TARGET}
62+
PRIVATE Qt${QTMAJOR}::Core Qt${QTMAJOR}::CorePrivate Qt${QTMAJOR}::Qml
63+
Qt${QTMAJOR}::Widgets Qt${QTMAJOR}::QuickWidgets)
64+
65+
if(Qt${QTMAJOR}WebEngineWidgets_FOUND)
66+
target_link_libraries(${TARGET} PRIVATE Qt${QTMAJOR}::WebEngineWidgets)
67+
endif()
68+
69+
target_compile_definitions(${TARGET} PRIVATE BUILDING_DECLARATIVEWIDGETS)
70+
71+
set(PLUGIN_DESTDIR ${CMAKE_BINARY_DIR}/qml)
72+
73+
set_target_properties(${TARGET} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
74+
"${PLUGIN_DESTDIR}/QtWidgets")
75+
76+
if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL "${PLUGIN_DESTDIR}/QtWidgets")
77+
add_custom_command(
78+
TARGET ${TARGET}
79+
POST_BUILD
80+
COMMENT "Copy qmldir to build directory"
81+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir
82+
${PLUGIN_DESTDIR}/QtWidgets/qmldir)
83+
endif()
84+
85+
install(TARGETS ${TARGET}
86+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/qt${QTMAJOR}/qml/QtWidgets)
87+
88+
install(FILES qmldir
89+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/qt${QTMAJOR}/qml/QtWidgets)

tests/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group
2+
# company <info@kdab.com>
3+
#
4+
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
5+
6+
if(USE_QT6)
7+
find_package(Qt6 6.5 NO_MODULE REQUIRED COMPONENTS Test Quick QuickWidgets)
8+
else()
9+
find_package(Qt5 5.15 NO_MODULE REQUIRED COMPONENTS Test Quick QuickWidgets)
10+
endif()
11+
12+
enable_testing()
13+
# Function to create a test executable with Qt dependencies Args: TEST_NAME:
14+
# Name of the test executable to create ARGN: Additional source files for the
15+
# test
16+
function(add_test_executable test_name)
17+
add_executable(${test_name} ${ARGN})
18+
add_test(NAME ${test_name} COMMAND ${test_name})
19+
target_link_libraries(
20+
${test_name} PRIVATE Qt${QTMAJOR}::Quick Qt${QTMAJOR}::Widgets
21+
Qt${QTMAJOR}::QuickWidgets Qt${QTMAJOR}::Test)
22+
if(Qt${QTMAJOR}WebEngineWidgets_FOUND)
23+
target_link_libraries(${test_name} PRIVATE Qt${QTMAJOR}::WebEngineWidgets)
24+
endif()
25+
target_compile_definitions(
26+
${test_name} PRIVATE -DPLUGIN_IMPORT_PATH=${DW_PLUGIN_IMPORT_PATH})
27+
endfunction()
28+
29+
add_test_executable(
30+
tst_instantiatetypes auto/instantiatetypes/tst_instantiatetypes.cpp
31+
auto/instantiatetypes/qml.qrc)
32+
33+
add_test_executable(
34+
tst_layouts
35+
auto/layouts/formlayoutwidget.cpp
36+
auto/layouts/gridlayoutwidget.cpp
37+
auto/layouts/hboxlayoutwidget.cpp
38+
auto/layouts/stackedlayoutwidget.cpp
39+
auto/layouts/stackedwidget.cpp
40+
auto/layouts/tst_layouts.cpp
41+
auto/layouts/vboxlayoutwidget.cpp
42+
auto/layouts/qml.qrc
43+
auto/layouts/formlayout.ui
44+
auto/layouts/gridlayout.ui
45+
auto/layouts/hboxlayout.ui
46+
auto/layouts/stackedwidget.ui
47+
auto/layouts/vboxlayout.ui)
48+
49+
add_test_executable(tst_qmlplugins auto/qmlplugins/tst_qmlplugins.cpp)
50+
51+
add_test_executable(tst_quickwidget auto/quickwidget/tst_quickwidget.cpp
52+
auto/quickwidget/quickwidgets.qrc)

0 commit comments

Comments
 (0)