Skip to content

Commit a7750f9

Browse files
committed
use new corrosion_add_target_generated_headers function
1 parent c8e5c58 commit a7750f9

File tree

37 files changed

+81
-109
lines changed

37 files changed

+81
-109
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ members = [
2222
"tests/basic_cxx_qt/rust",
2323
"tests/qt_types_standalone/rust",
2424
]
25+
26+
[patch.crates-io]
27+
cxx = { git = "https://github.com/Be-ing/cxx.git", branch = "cxxbuild_output_var" }
28+
cxx-build = { git = "https://github.com/Be-ing/cxx.git", branch = "cxxbuild_output_var" }

book/src/concepts/build_systems.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ CXX-Qt can be integrated into existing CMake projects or built with only cargo.
1212
* [CMake Integration](../getting-started/5-cmake-integration.md)
1313
* [Cargo Integration](../getting-started/6-cargo-executable.md)
1414

15-
CXX-Qt could work with any C++ build system so long as the `QMAKE` and `CXXQT_EXPORT_DIR` environment variables are set before calling Cargo,
15+
CXX-Qt could work with any C++ build system so long as the `QMAKE` and `GENERATED_HEADER_DIR` environment variables are set before calling Cargo,
1616
as documented in [CMake integration](../getting-started/5-cmake-integration.md). However, using C++ build systems besides CMake with CXX-Qt is untested.

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn generate_cxxqt_cpp_files(
221221
/// running `cargo build`. Otherwise [CxxQtBuilder] prefers the newer version by default.
222222
///
223223
/// To use [CxxQtBuilder] for a library to link with a C++ application, specify a directory to output
224-
/// cxx-qt's autogenerated headers by having the C++ build system set the `CXXQT_EXPORT_DIR`
224+
/// cxx-qt's autogenerated headers by having the C++ build system set the `GENERATED_HEADER_DIR`
225225
/// environment variable before calling `cargo build`. Then, add the same directory path to the C++
226226
/// include paths. Also, set the `QMAKE` environment variable to the path of the `qmake` executable
227227
/// for the Qt installation found by the C++ build system. This ensures that the C++ build system and
@@ -350,12 +350,11 @@ impl CxxQtBuilder {
350350

351351
// The include directory needs to be namespaced by crate name when exporting for a C++ build system,
352352
// but for using cargo build without a C++ build system, OUT_DIR is already namespaced by crate name.
353-
let header_root = match env::var("CXXQT_EXPORT_DIR") {
354-
Ok(export_dir) => format!("{}/{}", export_dir, env::var("CARGO_PKG_NAME").unwrap()),
355-
Err(_) => env::var("OUT_DIR").unwrap(),
356-
};
353+
let header_root =
354+
env::var("GENERATED_HEADER_DIR").unwrap_or_else(|_| env::var("OUT_DIR").unwrap());
355+
let generated_header_dir =
356+
format!("{}/{}", header_root, env::var("CARGO_PKG_NAME").unwrap());
357357
self.cc_builder.include(&header_root);
358-
let generated_header_dir = format!("{}/cxx-qt-gen", header_root);
359358

360359
cxx_qt_lib_headers::write_headers(&format!("{}/cxx-qt-lib", header_root));
361360

crates/cxx-qt-gen/src/generator/rust/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ impl GeneratedRustBlocks {
4848

4949
/// Generate the include line for this parsed block
5050
fn generate_include(parser: &Parser) -> Result<Item> {
51-
let import_path = format!("cxx-qt-gen/{}.cxxqt.h", parser.cxx_file_stem);
51+
let crate_name = std::env::var("CARGO_PKG_NAME").unwrap();
52+
let import_path = format!("{}/{}.cxxqt.h", crate_name, parser.cxx_file_stem);
5253

5354
syn::parse2(quote! {
5455
unsafe extern "C++" {

crates/cxx-qt-gen/src/writer/cpp/header.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ pub fn write_cpp_header(generated: &GeneratedCppBlocks) -> String {
129129
}}
130130
131131
{forward_declare}
132-
#include "cxx-qt-gen/{cxx_file_stem}.cxx.h"
132+
#include "{crate_name}/{cxx_file_stem}.cxx.h"
133133
134134
{qobjects}
135135
"#,
136136
cxx_file_stem = generated.cxx_file_stem,
137137
forward_declare = forward_declare(generated).join("\n"),
138+
crate_name = std::env::var("CARGO_PKG_NAME").unwrap(),
138139
qobjects = qobjects_header(generated).join("\n"),
139140
}
140141
}

crates/cxx-qt-gen/src/writer/cpp/source.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ fn qobjects_source(generated: &GeneratedCppBlocks) -> Vec<String> {
8080
/// For a given GeneratedCppBlocks write this into a C++ source
8181
pub fn write_cpp_source(generated: &GeneratedCppBlocks) -> String {
8282
formatdoc! {r#"
83-
#include "cxx-qt-gen/{cxx_file_stem}.cxxqt.h"
83+
#include "{crate_name}/{cxx_file_stem}.cxxqt.h"
8484
8585
{qobjects}
8686
"#,
87+
crate_name = std::env::var("CARGO_PKG_NAME").unwrap(),
8788
cxx_file_stem = generated.cxx_file_stem,
8889
qobjects = qobjects_source(generated).join("\n"),
8990
}

examples/cargo_without_cmake/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ if(NOT Corrosion_FOUND)
2626
include(FetchContent)
2727
FetchContent_Declare(
2828
Corrosion
29-
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
30-
GIT_TAG v0.2.1
29+
GIT_REPOSITORY https://github.com/Be-ing/corrosion.git
30+
GIT_TAG code_generators
3131
)
3232

3333
FetchContent_MakeAvailable(Corrosion)

examples/cargo_without_cmake/src/cpp/run.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <QtGui/QGuiApplication>
1212
#include <QtQml/QQmlApplicationEngine>
1313

14-
#include "cxx-qt-gen/my_object.cxxqt.h"
14+
#include "qml-minimal-no-cmake/my_object.cxxqt.h"
1515

1616
// Include the C++ code generated by rcc from the .qrc file
1717
#include "qml.qrc.cpp"

examples/demo_threading/CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@ if(NOT Corrosion_FOUND)
2727
include(FetchContent)
2828
FetchContent_Declare(
2929
Corrosion
30-
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
31-
GIT_TAG v0.2.1
30+
GIT_REPOSITORY https://github.com/Be-ing/corrosion.git
31+
GIT_TAG code_generators
3232
)
3333

3434
FetchContent_MakeAvailable(Corrosion)
3535
endif()
3636

3737
set(CRATE demo-threading)
3838
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})
39-
set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
40-
corrosion_set_env_vars(${CRATE}
41-
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
42-
"QMAKE=${QMAKE}"
43-
)
44-
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
39+
corrosion_add_target_generated_headers(${CRATE})
40+
corrosion_set_env_vars(${CRATE} "QMAKE=${QMAKE}")
4541
target_link_libraries(${CRATE} INTERFACE
4642
Qt::Core
4743
Qt::Gui

examples/demo_threading/cpp/helpers/energyusageproxymodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <QAbstractListModel>
1313
#include <QVector>
1414

15-
#include "cxx-qt-gen/energy_usage.cxxqt.h"
15+
#include "demo-threading/energy_usage.cxxqt.h"
1616

1717
class EnergyUsageProxyModel : public QAbstractListModel
1818
{

0 commit comments

Comments
 (0)