|
| 1 | +# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> |
| 2 | +# SPDX-FileContributor: Andrew Hayzen <[email protected]> |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT OR Apache-2.0 |
| 5 | + |
| 6 | +cmake_minimum_required(VERSION 3.24) |
| 7 | + |
| 8 | +project(example_meta_project) |
| 9 | +set(APP_NAME ${PROJECT_NAME}) |
| 10 | + |
| 11 | +set(CMAKE_AUTOMOC ON) |
| 12 | +set(CMAKE_AUTORCC ON) |
| 13 | +set(CMAKE_CXX_STANDARD 17) |
| 14 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 15 | + |
| 16 | +if(NOT USE_QT5) |
| 17 | + find_package(Qt6 COMPONENTS Core Gui Qml QuickControls2 QmlImportScanner QuickTest Test) |
| 18 | +endif() |
| 19 | +if(NOT Qt6_FOUND) |
| 20 | + find_package(Qt5 5.15 COMPONENTS Core Gui Qml QuickControls2 QmlImportScanner QuickTest Test REQUIRED) |
| 21 | +endif() |
| 22 | +get_target_property(QMAKE Qt::qmake IMPORTED_LOCATION) |
| 23 | + |
| 24 | +find_package(Corrosion QUIET) |
| 25 | +if(NOT Corrosion_FOUND) |
| 26 | + include(FetchContent) |
| 27 | + FetchContent_Declare( |
| 28 | + Corrosion |
| 29 | + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git |
| 30 | + GIT_TAG v0.4.1 |
| 31 | + ) |
| 32 | + |
| 33 | + FetchContent_MakeAvailable(Corrosion) |
| 34 | +endif() |
| 35 | + |
| 36 | +set(CRATE qml-meta-project) |
| 37 | +corrosion_import_crate(MANIFEST_PATH rust/main/Cargo.toml CRATES ${CRATE}) |
| 38 | +set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt") |
| 39 | +corrosion_set_env_vars(${CRATE} |
| 40 | + "CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}" |
| 41 | + "QMAKE=${QMAKE}" |
| 42 | +) |
| 43 | +add_library(${APP_NAME}_lib INTERFACE) |
| 44 | +target_include_directories(${APP_NAME}_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}") |
| 45 | +target_link_libraries(${APP_NAME}_lib INTERFACE |
| 46 | + "$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>" |
| 47 | + Qt::Core |
| 48 | + Qt::Gui |
| 49 | + Qt::Qml |
| 50 | + Qt::QuickControls2 |
| 51 | +) |
| 52 | + |
| 53 | +add_executable(${APP_NAME} |
| 54 | + cpp/main.cpp |
| 55 | + qml/qml.qrc |
| 56 | +) |
| 57 | + |
| 58 | +target_include_directories(${APP_NAME} PRIVATE cpp) |
| 59 | +target_link_libraries(${APP_NAME} PRIVATE ${APP_NAME}_lib) |
| 60 | +qt_import_qml_plugins(${APP_NAME}) |
0 commit comments