Skip to content

Commit

Permalink
integrate qml-minimal-no-cmake into CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Aug 26, 2022
1 parent 9e7a527 commit 6af145f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/github-cxx-qt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ jobs:
# Ubuntu 22.04 uses GCC 11 by default. Somehow when using that compiler,
# GNU ld fails to link, though lld works. To test a full GNU toolchain,
# use GCC 12 (with the default GNU ld).
#
# mold (or lld) is required for qml-minimal-no-cmake to link.
run: >-
sudo apt-get update &&
sudo apt-get install -y
gcc-12
mold
ninja-build
clang-format-12
libssl-dev
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# SPDX-License-Identifier: MIT OR Apache-2.0

add_subdirectory(cargo_without_cmake)
add_subdirectory(qml_extension_plugin)
add_subdirectory(qml_features)
add_subdirectory(qml_minimal)
Expand Down
47 changes: 47 additions & 0 deletions examples/cargo_without_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-FileContributor: Be Wilson <[email protected]>
#
# SPDX-License-Identifier: MIT OR Apache-2.0

# This CMakeLists.txt does not build any C++ directly. It is only here to integrate building
# this crate into the larger CMake build of this repository. For development and testing, you
# can run
#
# cargo build -p qml-minimal-no-cmake
#
# from any directory in this repository to build this crate without using CMake at all.

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Qml QuickControls2 QmlImportScanner REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Qml QuickControls2 QmlImportScanner REQUIRED)
get_target_property(QMAKE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)

# Use Corrosion to create a target for the crate that can be built without CMake.
# This allows it to share built dependencies with the other crates in the workspace.
find_package(Corrosion QUIET)
if(NOT Corrosion_FOUND)
include(FetchContent)
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.2.1
)

FetchContent_MakeAvailable(Corrosion)
endif()

set(CRATE qml-minimal-no-cmake)
corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES ${CRATE})
corrosion_set_env_vars(${CRATE} "QMAKE=${QMAKE}")
if(UNIX AND NOT APPLE)
find_program(MOLD_EXECUTABLE mold)
if(MOLD_EXECUTABLE)
corrosion_add_target_rustflags(${CRATE} "-Clink-arg=-fuse-ld=mold")
else()
find_program(LLD_EXECUTABLE lld)
if(LLD_EXECUTABLE)
corrosion_add_target_rustflags(${CRATE} "-Clink-arg=-fuse-ld=lld")
else()
message(WARNING "Neither mold nor lld linkers were found. ${CRATE} will likely fail to link without using one of these.")
endif()
endif()
endif()

0 comments on commit 6af145f

Please sign in to comment.