Skip to content

Commit b4ca688

Browse files
committed
Fix cross compilation for non-macOS apple targets
Define CMAKE_OSX_ARCHITECTURES and CMAKE_OSX_SYSROOT automatically for non-macOS apple targets
1 parent fd56c5a commit b4ca688

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

src/lib.rs

+47-7
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,53 @@ impl Config {
670670
panic!("unsupported msvc target: {}", target);
671671
}
672672
}
673-
} else if target.contains("darwin") && !self.defined("CMAKE_OSX_ARCHITECTURES") {
674-
if target.contains("x86_64") {
675-
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=x86_64");
676-
} else if target.contains("aarch64") {
677-
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=arm64");
678-
} else {
679-
panic!("unsupported darwin target: {}", target);
673+
} else if target.contains("apple") {
674+
if !self.defined("CMAKE_OSX_ARCHITECTURES") {
675+
if target.contains("x86_64") {
676+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=x86_64");
677+
} else if target.contains("aarch64") {
678+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=arm64");
679+
} else if target.contains("i686") {
680+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=i686");
681+
} else if target.contains("arm64e") {
682+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=arm64e");
683+
} else if target.contains("i386") {
684+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=i386");
685+
} else if target.contains("armv7s") {
686+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=armv7s");
687+
} else if target.contains("armv7k") {
688+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=armv7k");
689+
} else if target.contains("arm64_32") {
690+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=arm64_32");
691+
} else {
692+
panic!("unsupported apple target: {}", target);
693+
}
694+
}
695+
696+
if !self.defined("CMAKE_OSX_SYSROOT") {
697+
if target.contains("macabi") {
698+
cmd.arg("-DCMAKE_OSX_SYSROOT=macosx");
699+
} else if target.contains("sim") {
700+
if target.contains("ios") {
701+
cmd.arg("-DCMAKE_OSX_SYSROOT=iphonesimulator");
702+
} else if target.contains("tvos") {
703+
cmd.arg("-DCMAKE_OSX_SYSROOT=appletvsimulator");
704+
} else if target.contains("visionos") {
705+
cmd.arg("-DCMAKE_OSX_SYSROOT=xrsimulator");
706+
} else if target.contains("watchos") {
707+
cmd.arg("-DCMAKE_OSX_SYSROOT=watchsimulator");
708+
}
709+
} else {
710+
if target.contains("ios") {
711+
cmd.arg("-DCMAKE_OSX_SYSROOT=iphoneos");
712+
} else if target.contains("tvos") {
713+
cmd.arg("-DCMAKE_OSX_SYSROOT=appletvos");
714+
} else if target.contains("visionos") {
715+
cmd.arg("-DCMAKE_OSX_SYSROOT=xros");
716+
} else if target.contains("watchos") {
717+
cmd.arg("-DCMAKE_OSX_SYSROOT=watchos");
718+
}
719+
}
680720
}
681721
}
682722
if let Some(ref generator) = generator {

0 commit comments

Comments
 (0)