-
Notifications
You must be signed in to change notification settings - Fork 87
fix includes for framework libs #630
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
Changes from all commits
4159acf
80e0120
1ebdd64
cafdd3c
577df64
6fda61b
cdf2478
cfff8bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,3 @@ compile_commands.json | |
|
||
# cmps (https://github.com/leonmatthes/cmps) | ||
.cmps/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,7 @@ pub struct QtBuild { | |
qmltyperegistrar_executable: Option<String>, | ||
rcc_executable: Option<String>, | ||
qt_modules: Vec<String>, | ||
has_framework_libs: bool, | ||
} | ||
|
||
impl QtBuild { | ||
|
@@ -232,6 +233,22 @@ impl QtBuild { | |
} | ||
} | ||
|
||
fn determine_if_has_framework_libs(qmake_executable: &String) -> bool { | ||
let lib_path = QtBuild::static_qmake_query(qmake_executable, "QT_INSTALL_LIBS"); | ||
let target = env::var("TARGET"); | ||
|
||
match &target { | ||
Ok(target) => { | ||
if target.contains("apple") { | ||
Path::new(&format!("{lib_path}/QtCore.framework")).exists() | ||
} else { | ||
false | ||
} | ||
} | ||
Err(_) => false, | ||
} | ||
} | ||
|
||
if let Ok(qmake_env_var) = env::var("QMAKE") { | ||
match verify_candidate(qmake_env_var.trim()) { | ||
Ok((executable_name, version)) => { | ||
|
@@ -242,6 +259,9 @@ impl QtBuild { | |
rcc_executable: None, | ||
version, | ||
qt_modules, | ||
has_framework_libs: determine_if_has_framework_libs( | ||
&executable_name.to_string(), | ||
), | ||
}); | ||
} | ||
Err(e) => { | ||
|
@@ -265,6 +285,9 @@ impl QtBuild { | |
rcc_executable: None, | ||
version, | ||
qt_modules, | ||
has_framework_libs: determine_if_has_framework_libs( | ||
&executable_name.to_string(), | ||
), | ||
}); | ||
} | ||
// If QT_VERSION_MAJOR is specified, it is expected that one of the versioned | ||
|
@@ -294,8 +317,12 @@ impl QtBuild { | |
|
||
/// Get the output of running `qmake -query var_name` | ||
pub fn qmake_query(&self, var_name: &str) -> String { | ||
QtBuild::static_qmake_query(&self.qmake_executable, var_name) | ||
} | ||
|
||
fn static_qmake_query(qmake_executable: &String, var_name: &str) -> String { | ||
std::str::from_utf8( | ||
&Command::new(&self.qmake_executable) | ||
&Command::new(qmake_executable) | ||
.args(["-query", var_name]) | ||
.output() | ||
.unwrap() | ||
|
@@ -319,6 +346,9 @@ impl QtBuild { | |
|
||
match std::fs::read_to_string(prl_path) { | ||
Ok(prl) => { | ||
if self.has_framework_libs { | ||
builder.flag(&format!("-F{}", lib_path)); | ||
} | ||
for line in prl.lines() { | ||
if let Some(line) = line.strip_prefix("QMAKE_PRL_LIBS = ") { | ||
parse_cflags::parse_libs_cflags( | ||
|
@@ -369,10 +399,15 @@ impl QtBuild { | |
} | ||
} | ||
|
||
format!( | ||
let prl_file = format!( | ||
"{}/{}Qt{}{}.prl", | ||
lib_path, prefix, version_major, qt_module | ||
) | ||
); | ||
println!( | ||
"cargo:warning=Qt .prl file not found at expected path, falling back to {}", | ||
prl_file | ||
); | ||
prl_file | ||
} | ||
|
||
/// Tell Cargo to link each Qt module. | ||
|
@@ -448,12 +483,21 @@ impl QtBuild { | |
/// Get the include paths for Qt, including Qt module subdirectories. This is intended | ||
/// to be passed to whichever tool you are using to invoke the C++ compiler. | ||
pub fn include_paths(&self) -> Vec<PathBuf> { | ||
let root_path = self.qmake_query("QT_INSTALL_HEADERS"); | ||
let mut paths = Vec::new(); | ||
|
||
if self.has_framework_libs { | ||
let lib_root_path: String = self.qmake_query("QT_INSTALL_LIBS"); | ||
|
||
for qt_module in &self.qt_modules { | ||
paths.push(format!("{lib_root_path}/Qt{qt_module}.framework/Headers")); | ||
} | ||
} | ||
let root_path: String = self.qmake_query("QT_INSTALL_HEADERS"); | ||
for qt_module in &self.qt_modules { | ||
paths.push(format!("{root_path}/Qt{qt_module}")); | ||
} | ||
Comment on lines
496
to
498
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct when Qt is installed as a framework? This allows using include paths like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never included using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code should likely be moved into an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a few researches : I was testing only on qml_minimal example project, so this problem didn't appear. It gave me these errors: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh curious, i found doing Guess we'll have to drop doing that if this doesn't work in macOS anymore (i can create a separate PR to do this), unless there is a different include folder that can be used that does include the module name + the header name ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at the CI output from another projecting using the Qt official binary installer and the include paths are:
So it seems we need: if self.has_framework_libs {
let lib_root_path: String = self.qmake_query("QT_INSTALL_LIBS");
let qt_version = &self.qt_version;
for qt_module in &self.qt_modules {
paths.push(format!("{lib_root_path}/Qt{qt_module}.framework/Headers"));
paths.push(format!("{lib_root_path}/Qt{qt_module}.framework/Headers/{qt_version}"));
paths.push(format!("{lib_root_path}/Qt{qt_module}.framework/Headers/{qt_version}/Qt{qt_module}"));
}
} Please try that code with both I also saw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jacquetc Have you had a chance to test the code I posted above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No yet, I'll take time tomorrow at noon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested, exactly the same error. |
||
paths.push(root_path); | ||
|
||
paths.iter().map(PathBuf::from).collect() | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.