@@ -236,58 +236,31 @@ pub struct QtBuild {
236
236
}
237
237
238
238
impl QtBuild {
239
- /// Search for where Qt is installed using qmake. Specify the Qt modules you are
240
- /// linking with the `qt_modules` parameter, ommitting the `Qt` prefix (`"Core"`
241
- /// rather than `"QtCore"`). After construction, use the [QtBuild::qmake_query]
242
- /// method to get information about the Qt installation.
243
- ///
244
- /// The directories specified by the `PATH` environment variable are where qmake is
245
- /// searched for. Alternatively, the `QMAKE` environment variable may be set to specify
246
- /// an explicit path to qmake.
247
- ///
248
- /// If multiple major versions (for example, `5` and `6`) of Qt could be installed, set
249
- /// the `QT_VERSION_MAJOR` environment variable to force which one to use. When using Cargo
250
- /// as the build system for the whole build, prefer using `QT_VERSION_MAJOR` over the `QMAKE`
251
- /// environment variable because it will account for different names for the qmake executable
252
- /// that some Linux distributions use.
253
- ///
254
- /// However, when building a Rust staticlib that gets linked to C++ code by a C++ build
255
- /// system, it is best to use the `QMAKE` environment variable to ensure that the Rust
256
- /// staticlib is linked to the same installation of Qt that the C++ build system has
257
- /// detected.
258
- /// With CMake, this will automatically be set up for you when using cxxqt_import_crate.
259
- ///
260
- /// Alternatively, you can get this from the `Qt::qmake` target's `IMPORTED_LOCATION`
261
- /// property, for example:
262
- /// ```cmake
263
- /// find_package(Qt6 COMPONENTS Core)
264
- /// if(NOT Qt6_FOUND)
265
- /// find_package(Qt5 5.15 COMPONENTS Core REQUIRED)
266
- /// endif()
267
- /// get_target_property(QMAKE Qt::qmake IMPORTED_LOCATION)
268
- ///
269
- /// execute_process(
270
- /// COMMAND cmake -E env
271
- /// "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}/cargo"
272
- /// "QMAKE=${QMAKE}"
273
- /// cargo build
274
- /// WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
275
- /// )
276
- /// ```
277
- pub fn new ( mut qt_modules : Vec < String > ) -> anyhow:: Result < Self > {
278
- if qt_modules. is_empty ( ) {
279
- qt_modules. push ( "Core" . to_string ( ) ) ;
280
- }
281
-
239
+ /// Create a [QtBuild] using the default [QtInstallation] (currently uses [QtInstallationQMake])
240
+ /// and specify which Qt modules you are linking, ommitting the `Qt` prefix (`"Core"`
241
+ /// rather than `"QtCore"`).
242
+ //
243
+ // TODO: is there a better name for this method or a sane way to create a default QtInstallation?
244
+ pub fn new_with_default_installation ( qt_modules : Vec < String > ) -> anyhow:: Result < Self > {
282
245
#[ cfg( feature = "qmake" ) ]
283
246
let qt_installation = Box :: new ( QtInstallationQMake :: new ( ) ?) ;
284
247
#[ cfg( not( feature = "qmake" ) ) ]
285
248
unsupported ! ( "Only qmake feature is supported" ) ;
286
249
287
- Ok ( Self {
250
+ Ok ( Self :: new ( qt_installation, qt_modules) )
251
+ }
252
+
253
+ /// Create a [QtBuild] using the given [QtInstallation] and specify which
254
+ /// Qt modules you are linking, ommitting the `Qt` prefix (`"Core"` rather than `"QtCore"`).
255
+ pub fn new ( qt_installation : Box < dyn QtInstallation > , mut qt_modules : Vec < String > ) -> Self {
256
+ if qt_modules. is_empty ( ) {
257
+ qt_modules. push ( "Core" . to_string ( ) ) ;
258
+ }
259
+
260
+ Self {
288
261
qt_installation,
289
262
qt_modules,
290
- } )
263
+ }
291
264
}
292
265
293
266
/// Tell Cargo to link each Qt module.
0 commit comments