@@ -459,9 +459,17 @@ else if (ch == 1) {
459459 boolean macGpp = false ;
460460 try { macGpp = Runtime .getRuntime ().exec (new String []{"g++" ,"--version" }).waitFor ()==0 ; }
461461 catch (Exception ignored ) {}
462- boolean macGlfw = new File ("/opt/homebrew/include/GLFW/glfw3.h" ).exists ()
462+ 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
466+ boolean hasBundledGlfw = new File (macLibsDir , "libglfw.3.dylib" ).exists ();
467+ boolean hasBundledGlew = new File (macLibsDir , "libGLEW.dylib" ).exists ();
468+ boolean macGlfw = hasBundledGlfw
469+ || new File ("/opt/homebrew/include/GLFW/glfw3.h" ).exists ()
463470 || new File ("/usr/local/include/GLFW/glfw3.h" ).exists ();
464- boolean macGlew = new File ("/opt/homebrew/include/GL/glew.h" ).exists ()
471+ boolean macGlew = hasBundledGlew
472+ || new File ("/opt/homebrew/include/GL/glew.h" ).exists ()
465473 || new File ("/usr/local/include/GL/glew.h" ).exists ();
466474 if (macGpp && macGlfw && macGlew ) return ; // everything present, skip wizard
467475 // Try the guided installer first (Xcode Command Line Tools, then
@@ -3164,10 +3172,17 @@ else if (!cmd.contains(defaultsCpp.getAbsolutePath()))
31643172 "-lcomdlg32" , "-lshell32" , "-lole32" , "-luuid" ,
31653173 "-mwindows" , "-pthread" , "-D_USE_MATH_DEFINES" );
31663174 } else if (mac ) {
3167- // macOS has no separate libGL/libGLU â OpenGL is a system framework,
3168- // bundled with Xcode Command Line Tools (no extra install needed).
3169- // GLFW/GLEW come from Homebrew, so link against its lib directory too.
3170- if (homebrewPrefix != null ) {
3175+ // macOS: prefer bundled dylibs shipped with the mode (libs/macos-arm64
3176+ // or libs/macos-x64) so users need no Homebrew install at all.
3177+ String arch = System .getProperty ("os.arch" ,"" ).contains ("aarch64" ) ? "arm64" : "x64" ;
3178+ File macLibsDir = new File (runtimeDir .getParentFile (), "libs/macos-" + arch );
3179+ boolean hasBundled = new File (macLibsDir , "libglfw.3.dylib" ).exists ()
3180+ && new File (macLibsDir , "libGLEW.dylib" ).exists ();
3181+ if (hasBundled ) {
3182+ cmd .add ("-L" + macLibsDir .getAbsolutePath ());
3183+ cmd .add ("-Wl,-rpath," + macLibsDir .getAbsolutePath ());
3184+ cmd .add ("-Wl,-rpath,@executable_path" );
3185+ } else if (homebrewPrefix != null ) {
31713186 cmd .add ("-L" + homebrewPrefix + "/lib" );
31723187 }
31733188 Collections .addAll (cmd , "-lglfw" , "-lGLEW" , "-lm" , "-pthread" );
0 commit comments