Skip to content

Commit

Permalink
cmake: Use cxx-qt-cmake repo for CMake code
Browse files Browse the repository at this point in the history
This allows us to download a lot less data with FetchContent for
quickier deployment.
  • Loading branch information
LeonMatthesKDAB committed Jul 29, 2024
1 parent 2c319ec commit fd77bcb
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 134 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dependencies are now automatically detected and configured by cxx-qt-build
- Libraries can pass build information to cxx-qt-build in the form of a `cxx_qt_build::Interface`
- Add CMake wrappers around corrosion to simplify importing crates and qml modules that were built with cxx-qt-build
- CMake code has been extracted into a separate repository for faster downloads (kdab/cxx-qt-cmake)

### Removed

Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(CompilerCaching)
include(CxxQt)

# Enable extra Qt definitions for all projects
add_compile_definitions(
Expand Down
4 changes: 3 additions & 1 deletion book/src/getting-started/5-cmake-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ For this example, we are [supporting both Qt5 and Qt6 with CMake](https://doc.qt
Download CXX-Qts CMake code with FetchContent:

```cmake,ignore
{{#include ../../../examples/qml_minimal/CMakeLists.txt:book_cmake_find_cxx_qt}}
{{#include ../../../examples/qml_minimal/CMakeLists.txt:book_cmake_find_cxx_qt_start}}
GIT_TAG v0.7.0
{{#include ../../../examples/qml_minimal/CMakeLists.txt:book_cmake_find_cxx_qt_end}}
```

This provides you with a few wrappers around [Corrosion](https://github.com/corrosion-rs/corrosion), a tool for integrating Rust libraries into CMake:
Expand Down
123 changes: 0 additions & 123 deletions cmake/CxxQt.cmake

This file was deleted.

12 changes: 12 additions & 0 deletions examples/demo_threading/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ if(NOT Qt6_FOUND)
find_package(Qt5 5.15 COMPONENTS Core Gui Qml QuickControls2 QmlImportScanner REQUIRED)
endif()

find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
GIT_TAG main
)

FetchContent_MakeAvailable(CxxQt)
endif()

set(CRATE cxx_qt_demo_threading)
cxx_qt_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})
cxx_qt_import_qml_module(${CRATE}_qml
Expand Down
12 changes: 12 additions & 0 deletions examples/qml_features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ if(NOT Qt6_FOUND)
find_package(Qt5 5.15 COMPONENTS Core Gui Qml Quick QuickControls2 QmlImportScanner QuickTest Test REQUIRED)
endif()

find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
GIT_TAG main
)

FetchContent_MakeAvailable(CxxQt)
endif()

set(CRATE qml_features)
cxx_qt_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})
cxx_qt_import_qml_module(${CRATE}_qml
Expand Down
24 changes: 15 additions & 9 deletions examples/qml_minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ if(NOT Qt6_FOUND)
endif()
# ANCHOR_END: book_cmake_setup

# ANCHOR: book_cmake_find_qmake
# The path to the qmake executable path needs to be passed to the Rust
# library's build script to ensure it uses the same installation of Qt as CMake.
# TODO: This has been removed, document it
# ANCHOR_END: book_cmake_find_qmake

# ANCHOR: book_cmake_find_cxx_qt
# TODO: Replace with fetch-content co cxx-qt-cmake
# ANCHOR_END: book_cmake_find_cxx_qt
# ANCHOR: book_cmake_find_cxx_qt_start
find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
# ANCHOR_END: book_cmake_find_cxx_qt_start
GIT_TAG main
# ANCHOR: book_cmake_find_cxx_qt_end
)

FetchContent_MakeAvailable(CxxQt)
endif()
# ANCHOR_END: book_cmake_find_cxx_qt_end

# ANCHOR: book_cmake_use_cxx_qt
# CXX-Qt (using Corrosion) creates a CMake target with the same name as the crate.
Expand Down
3 changes: 3 additions & 0 deletions scripts/release_crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ function release_crate() {
# Remind about cargo login
question_yesno "Have you run cargo login before and setup credentials"

# cxx-qt-cmake (no dependencies)
question_yesno "Have you created a new tag in the cxx-qt-cmake repo"

# No other dependencies
release_crate "qt-build-utils"

Expand Down
12 changes: 12 additions & 0 deletions tests/basic_cxx_only/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ if(NOT Qt6_FOUND)
find_package(Qt5 5.15 COMPONENTS Core Gui Qml Test REQUIRED)
endif()

find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
GIT_TAG main
)

FetchContent_MakeAvailable(CxxQt)
endif()

set(CRATE basic_cxx_only)
cxx_qt_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})

Expand Down
12 changes: 12 additions & 0 deletions tests/basic_cxx_qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ if(NOT Qt6_FOUND)
find_package(Qt5 5.15 COMPONENTS Core Gui Qml Test REQUIRED)
endif()

find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
GIT_TAG main
)

FetchContent_MakeAvailable(CxxQt)
endif()

set(CRATE basic_cxx_qt)
cxx_qt_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})

Expand Down
12 changes: 12 additions & 0 deletions tests/qt_types_standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ if(NOT Qt6_FOUND)
find_package(Qt5 5.15 COMPONENTS Core Gui Qml Test REQUIRED)
endif()

find_package(CxxQt QUIET)
if(NOT CxxQt_FOUND)
include(FetchContent)
FetchContent_Declare(
CxxQt
GIT_REPOSITORY https://github.com/kdab/cxx-qt-cmake.git
GIT_TAG main
)

FetchContent_MakeAvailable(CxxQt)
endif()

set(CRATE qt_types_standalone)
cxx_qt_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})

Expand Down

0 comments on commit fd77bcb

Please sign in to comment.