Skip to content

Commit 0da4e86

Browse files
committed
macOS: use bundled GLFW+GLEW dylibs, copy to sketch folder at build time, update detection
1 parent 796f971 commit 0da4e86

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

mode/CppMode.jar

606 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ else if (ch == 1) {
460460
try { macGpp = Runtime.getRuntime().exec(new String[]{"g++","--version"}).waitFor()==0; }
461461
catch (Exception ignored) {}
462462
String macArch = System.getProperty("os.arch","").contains("aarch64") ? "arm64" : "x64";
463-
File macLibsDir = new File(System.getProperty("user.home") +
464-
"/Library/Application Support/Processing/modes/CppMode/libs/macos-" + macArch);
465-
// Also check relative to the mode's own directory
463+
File macLibsDir = (runtimeDir != null)
464+
? new File(runtimeDir.getParentFile(), "libs/macos-" + macArch)
465+
: new File(System.getProperty("user.home") +
466+
"/Library/Application Support/Processing/modes/CppMode/libs/macos-" + macArch);
466467
boolean hasBundledGlfw = new File(macLibsDir, "libglfw.3.dylib").exists();
467468
boolean hasBundledGlew = new File(macLibsDir, "libGLEW.dylib").exists();
468469
boolean macGlfw = hasBundledGlfw
@@ -636,6 +637,18 @@ public File compile(RunnerListener listener) throws Exception {
636637
if (!dest.exists())
637638
java.nio.file.Files.copy(font.toPath(), dest.toPath());
638639
}
640+
// Copy bundled macOS dylibs to sketch folder so the binary finds them at runtime.
641+
if (isMac) {
642+
String macArch2 = System.getProperty("os.arch","").contains("aarch64") ? "arm64" : "x64";
643+
File macLibsDir2 = new File(runtimeDir.getParentFile(), "libs/macos-" + macArch2);
644+
if (macLibsDir2.exists()) {
645+
for (File dylib : macLibsDir2.listFiles((d,n) -> n.endsWith(".dylib"))) {
646+
File destDylib = new File(sketch.getFolder(), dylib.getName());
647+
if (!destDylib.exists())
648+
java.nio.file.Files.copy(dylib.toPath(), destDylib.toPath());
649+
}
650+
}
651+
}
639652
listener.statusNotice("Built: " + binary.getName());
640653

641654
// Check for required native libraries on all platforms

src/java/InstallWizard.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,18 @@ private java.util.List<String> detectMacMissing() {
392392
boolean haveCompiler = commandExists("xcrun", "-find", "g++")
393393
|| commandExists("g++", "--version");
394394
// Check headers (needed at compile time) not just dylibs (needed at link time).
395-
boolean glfwOk = new File("/opt/homebrew/include/GLFW/glfw3.h").exists()
395+
// Check bundled dylibs first (shipped with the mode, no Homebrew needed)
396+
String macArch = System.getProperty("os.arch","").contains("aarch64") ? "arm64" : "x64";
397+
String home = System.getProperty("user.home");
398+
File bundledLibs = new File(home + "/Library/Application Support/Processing/modes/CppMode/libs/macos-" + macArch);
399+
boolean glfwOk = new File(bundledLibs, "libglfw.3.dylib").exists()
400+
|| new File("/opt/homebrew/include/GLFW/glfw3.h").exists()
396401
|| new File("/usr/local/include/GLFW/glfw3.h").exists()
397402
|| new File("/opt/homebrew/lib/libglfw.dylib").exists()
398403
|| new File("/usr/local/lib/libglfw.dylib").exists()
399404
|| commandExists("pkg-config", "--exists", "glfw3");
400-
boolean glewOk = new File("/opt/homebrew/include/GL/glew.h").exists()
405+
boolean glewOk = new File(bundledLibs, "libGLEW.dylib").exists()
406+
|| new File("/opt/homebrew/include/GL/glew.h").exists()
401407
|| new File("/usr/local/include/GL/glew.h").exists()
402408
|| new File("/opt/homebrew/lib/libGLEW.dylib").exists()
403409
|| new File("/usr/local/lib/libGLEW.dylib").exists()

0 commit comments

Comments
 (0)