Skip to content

Commit 4774699

Browse files
committed
cxx-qt-build: move opts to it's own file
1 parent 6730220 commit 4774699

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

crates/cxx-qt-build/src/lib.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
mod diagnostics;
1515
use diagnostics::{Diagnostic, GeneratedError};
1616

17+
mod opts;
18+
pub use opts::CxxQtBuildersOpts;
19+
1720
mod qml_modules;
1821
use qml_modules::OwningQmlModule;
1922
pub use qml_modules::QmlModule;
@@ -308,17 +311,6 @@ pub struct CxxQtBuilder {
308311
extra_defines: HashSet<String>,
309312
}
310313

311-
/// Options for external crates to use
312-
#[derive(Default)]
313-
pub struct CxxQtBuildersOpts {
314-
/// Any extra definitions
315-
pub defines: HashSet<String>,
316-
/// Contents, directory, file name
317-
pub headers: Vec<(String, String, String)>,
318-
/// Qt modules that are required
319-
pub qt_modules: HashSet<String>,
320-
}
321-
322314
impl CxxQtBuilder {
323315
/// Create a new builder
324316
pub fn new() -> Self {

crates/cxx-qt-build/src/opts.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: 2024 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+
use std::collections::HashSet;
7+
8+
/// Options for external crates to use
9+
#[derive(Default)]
10+
pub struct CxxQtBuildersOpts {
11+
/// Any extra definitions
12+
pub(crate) defines: HashSet<String>,
13+
/// Contents, directory, file name
14+
pub(crate) headers: Vec<(String, String, String)>,
15+
/// Qt modules that are required
16+
pub(crate) qt_modules: HashSet<String>,
17+
}
18+
19+
impl CxxQtBuildersOpts {
20+
/// Any additional defines that are required from this opt
21+
pub fn define(mut self, define: &str) -> Self {
22+
self.defines.insert(define.to_owned());
23+
self
24+
}
25+
26+
/// Any additional headers that are required from this opt
27+
///
28+
/// These are placed in the given sub directory with the given file name
29+
pub fn header(mut self, contents: &str, directory: &str, file_name: &str) -> Self {
30+
self.headers.push((
31+
contents.to_owned(),
32+
directory.to_owned(),
33+
file_name.to_owned(),
34+
));
35+
self
36+
}
37+
38+
/// Link additional [Qt modules](https://doc.qt.io/qt-6/qtmodules.html) for this opt.
39+
/// Specify their names without the `Qt` prefix, for example `"Widgets"`.
40+
pub fn qt_module(mut self, module: &str) -> Self {
41+
self.qt_modules.insert(module.to_owned());
42+
self
43+
}
44+
}

crates/cxx-qt-lib-headers/src/lib.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,17 @@ pub fn build_opts() -> cxx_qt_build::CxxQtBuildersOpts {
100100
(include_str!("../include/qml/qqmlengine.h"), "qqmlengine.h"),
101101
(include_str!("../include/common.h"), "common.h"),
102102
] {
103-
opts.headers.push((
104-
file_contents.to_owned(),
105-
"cxx-qt-lib".to_owned(),
106-
file_name.to_owned(),
107-
));
103+
opts = opts.header(file_contents, "cxx-qt-lib", file_name);
108104
}
109105

110106
#[cfg(feature = "qt_gui")]
111107
{
112-
opts.defines.insert("CXX_QT_GUI_FEATURE".to_owned());
113-
opts.qt_modules.insert("Gui".to_owned());
108+
opts = opts.define("CXX_QT_GUI_FEATURE").qt_module("Gui");
114109
}
115110

116111
#[cfg(feature = "qt_qml")]
117112
{
118-
opts.defines.insert("CXX_QT_QML_FEATURE".to_owned());
119-
opts.qt_modules.insert("Qml".to_owned());
113+
opts = opts.define("CXX_QT_QML_FEATURE").qt_module("Qml");
120114
}
121115

122116
opts

0 commit comments

Comments
 (0)