Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support linking Qt as macOS framework #358

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Multiple QObjects can be defined in one bridge

### Fixed

- Fixed linking Qt with macOS frameworks. This allows using Qt from Homebrew.

## [0.4.0](https://github.com/KDAB/cxx-qt/compare/v0.3.0...v0.4.0) - 2022-10-28

### Added
Expand Down
39 changes: 33 additions & 6 deletions crates/qt-build-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ impl QtBuild {
let lib_path = self.qmake_query("QT_INSTALL_LIBS");
println!("cargo:rustc-link-search={}", lib_path);

let prefix = match env::var("TARGET") {
let target = env::var("TARGET");
let prefix = match &target {
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
Ok(target) => {
if target.contains("msvc") {
""
Expand All @@ -245,11 +246,37 @@ impl QtBuild {
};

for qt_module in &self.qt_modules {
println!("cargo:rustc-link-lib=Qt{}{}", self.version.major, qt_module);
let prl_path = format!(
"{}/{}Qt{}{}.prl",
lib_path, prefix, self.version.major, qt_module
);
let framework = match &target {
Ok(target) => {
if target.contains("apple") {
Path::new(&format!("{}/Qt{}.framework", lib_path, qt_module)).exists()
} else {
false
}
}
Err(_) => false,
};

let (link_lib, prl_path) = if framework {
(
format!("framework=Qt{}", qt_module),
format!(
"{}/Qt{}.framework/Resources/Qt{}.prl",
ahayzen-kdab marked this conversation as resolved.
Show resolved Hide resolved
lib_path, qt_module, qt_module
),
)
} else {
(
format!("Qt{}{}", self.version.major, qt_module),
format!(
"{}/{}Qt{}{}.prl",
lib_path, prefix, self.version.major, qt_module
),
)
};

println!("cargo:rustc-link-lib={}", link_lib);

match std::fs::read_to_string(&prl_path) {
Ok(prl) => {
for line in prl.lines() {
Expand Down