Skip to content

Commit

Permalink
qt-build-utils: handle linking Qt as macOS framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing authored and ahayzen-kdab committed Nov 18, 2022
1 parent 173f936 commit c6ac928
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
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 {
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",
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

0 comments on commit c6ac928

Please sign in to comment.