Browse Source

somewhat experimental support for 64-bits OS X and OS X Lion

rdb 13 years ago
parent
commit
30872b617e

+ 6 - 1
dtool/Config.OSX.pp

@@ -28,10 +28,15 @@
 #define C++FLAGS_GEN -ftemplate-depth-30
 
 // Configure for universal binaries on OSX.
-#defer ARCH_FLAGS $[if $[UNIVERSAL_BINARIES],-arch i386 -arch ppc,]
+#defer ARCH_FLAGS $[if $[UNIVERSAL_BINARIES],-arch i386 -arch ppc -arch x86_64,]
 #define OSX_CDEFS
 #define OSX_CFLAGS -Wno-deprecated-declarations
 
+// Whether to build for Cocoa, Carbon or both.  64-bits systems do not
+// have Carbon.  We also disable it for universal and 64-bits builds.
+#define HAVE_COCOA 1
+#defer HAVE_CARBON $[not $[or $[eq $[shell uname -m], x86_64],$[UNIVERSAL_BINARIES]]]
+
 // How to compile a C or C++ file into a .o file.  $[target] is the
 // name of the .o file, $[source] is the name of the source file,
 // $[ipath] is a space-separated list of directories to search for

+ 12 - 0
dtool/LocalSetup.pp

@@ -260,6 +260,14 @@
 #print Configuring Panda without threading support.
 #endif
 
+#if $[OSX_PLATFORM]
+#if $[UNIVERSAL_BINARIES]
+#print Compilation will create universal binaries.
+#else
+#print Compilation will not create universal binaries.
+#endif
+#endif
+
 #print
 #print See dtool_config.h for more details about the specified configuration.
 
@@ -737,6 +745,10 @@ $[cdefine LINK_ALL_STATIC]
 /* Define to compile the plugin code. */
 $[cdefine HAVE_P3D_PLUGIN]
 
+/* Define to compile for Cocoa or Carbon on Mac OS X. */
+$[cdefine HAVE_COCOA]
+$[cdefine HAVE_CARBON]
+
 /* Platform-identifying defines. */
 $[cdefine IS_OSX]
 $[cdefine IS_LINUX]

+ 4 - 1
dtool/Package.pp

@@ -9,7 +9,7 @@
 //
 // This is the package-specific file, which should be at the top of
 // every source hierarchy.  It generally gets the ball rolling, and is
-// responsible for explicitly including all of the relevent Config.pp
+// responsible for explicitly including all of the relevant Config.pp
 // files.
 
 // Check the version of ppremake in use.
@@ -253,6 +253,9 @@
 
 #set HAVE_WGL $[HAVE_WGL]
 
+#set HAVE_COCOA $[HAVE_COCOA]
+#set HAVE_CARBON $[HAVE_CARBON]
+
 #set DX8_IPATH $[unixfilename $[DX8_IPATH]]
 #set DX8_LPATH $[unixfilename $[DX8_LPATH]]
 #set DX8_LIBS $[DX8_LIBS]

+ 62 - 10
makepanda/makepanda.py

@@ -61,6 +61,7 @@ MAJOR_VERSION=None
 COREAPI_VERSION=None
 PLUGIN_VERSION=None
 OSXTARGET=None
+UNIVERSAL=False
 HOST_URL="https://runtime.panda3d.org/"
 global STRDXSDKVERSION, STRMSPLATFORMVERSION, BOOUSEINTELCOMPILER
 STRDXSDKVERSION = 'default'
@@ -85,6 +86,7 @@ PkgListSet(["PYTHON", "DIRECT",                        # Python support
   "NPAPI", "AWESOMIUM",                                # Browser embedding
   "GTK2", "WX", "FLTK",                                # Toolkit support
   "ROCKET",                                            # GUI libraries
+  "CARBON", "COCOA",                                   # Mac OS X toolkits
   "OSMESA", "X11", "XF86DGA", "XRANDR", "XCURSOR",     # Unix platform support
   "PANDATOOL", "PVIEW", "DEPLOYTOOLS",                 # Toolchain
   "SKEL",                                              # Example SKEL project
@@ -131,6 +133,7 @@ def usage(problem):
     print "  --host URL        (set the host url (runtime build only))"
     print "  --threads N       (use the multithreaded build system. see manual)"
     print "  --osxtarget N     (the OSX version number to build for (OSX only))"
+    print "  --universal       (build universal binaries (OSX only))"
     print "  --override \"O=V\"  (override dtool_config/prc option value)"
     print "  --static          (builds libraries for static linking)"
     print ""
@@ -181,6 +184,7 @@ def parseopts(args):
             elif (option=="--threads"): THREADCOUNT=int(value)
             elif (option=="--outputdir"): SetOutputDir(value.strip())
             elif (option=="--osxtarget"): OSXTARGET=value.strip()
+            elif (option=="--universal"): UNIVERSAL=True
             elif (option=="--nocolor"): DisableColors()
             elif (option=="--version"):
                 VERSION=value
@@ -432,6 +436,8 @@ if (COMPILER=="MSVC"):
     PkgDisable("GLES")
     PkgDisable("GLES2")
     PkgDisable("EGL")
+    PkgDisable("CARBON")
+    PkgDisable("COCOA")
     if (PkgSkip("PYTHON")==0):
         IncDirectory("ALWAYS", SDK["PYTHON"] + "/include")
         LibDirectory("ALWAYS", SDK["PYTHON"] + "/libs")
@@ -591,6 +597,10 @@ if (COMPILER=="MSVC"):
 
 if (COMPILER=="LINUX"):
     PkgDisable("AWESOMIUM")
+    if (sys.platform != "darwin"):
+        PkgDisable("CARBON")
+        PkgDisable("COCOA")
+
     if (PkgSkip("PYTHON")==0):
         IncDirectory("ALWAYS", SDK["PYTHON"])
     if (sys.platform == "darwin"):
@@ -653,7 +663,7 @@ if (COMPILER=="LINUX"):
     SmartPkgEnable("GTK2",      "gtk+-2.0")
     SmartPkgEnable("JPEG",      "",          ("jpeg"), "jpeglib.h")
     SmartPkgEnable("OPENSSL",   "openssl",   ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h"))
-    SmartPkgEnable("PNG",       "libpng",    ("png"), "png.h")
+    SmartPkgEnable("PNG",       "libpng",    ("png"), "png.h", tool = "libpng-config")
     SmartPkgEnable("ZLIB",      "zlib",      ("z"), "zlib.h")
     if (RTDIST and sys.platform == "darwin" and "PYTHONVERSION" in SDK):
         # Don't use the framework for the OSX rtdist build. I'm afraid it gives problems somewhere.
@@ -967,16 +977,22 @@ def CompileCxx(obj,src,opts):
         for (opt,var,val) in DEFSYMBOLS:
             if (opt=="ALWAYS") or (opt in opts): cmd += ' -D' + var + '=' + val
         for x in ipath: cmd += ' -I' + x
+
+        # Mac-specific flags.
         if (sys.platform == "darwin"):
             cmd += " -Wno-deprecated-declarations"
             if (OSXTARGET != None):
                 cmd += " -isysroot " + SDK["MACOSX"]
                 cmd += " -mmacosx-version-min=" + OSXTARGET
-            if is_64:
-                cmd += " -arch x86_64"
-            else:
+            if (UNIVERSAL):
                 cmd += " -arch i386"
-                if ("NOPPC" not in opts): cmd += " -arch ppc"
+                if int(platform.mac_ver()[0][3]) >= 5 and not RTDIST and not RUNTIME:
+                    #XXX we don't support 64-bits rtdist or plugin at the moment.
+                    # 10.5 supports building 64-bits Cocoa apps.
+                    cmd += " -arch x86_64"
+                if ("NOPPC" not in opts):
+                    cmd += " -arch ppc"
+
         cmd += " -pthread"
         if PkgSkip("SSE2") == 0:
             cmd += " -msse2"
@@ -1285,11 +1301,14 @@ def CompileLink(dll, obj, opts):
             if (OSXTARGET != None):
                 cmd += " -isysroot " + SDK["MACOSX"] + " -Wl,-syslibroot," + SDK["MACOSX"]
                 cmd += " -mmacosx-version-min=" + OSXTARGET
-            if is_64:
-                cmd += " -arch x86_64"
-            else:
+            if (UNIVERSAL):
                 cmd += " -arch i386"
-                if ("NOPPC" not in opts): cmd += " -arch ppc"
+                if int(platform.mac_ver()[0][3]) >= 5 and not RTDIST and not RUNTIME:
+                    #XXX we don't support 64-bits rtdist or plugin at the moment.
+                    # 10.5 supports building 64-bits Cocoa apps.
+                    cmd += " -arch x86_64"
+                if ("NOPPC" not in opts):
+                    cmd += " -arch ppc"
         if (LDFLAGS !=""): cmd += " " + LDFLAGS
 
         for (opt, dir) in LIBDIRECTORIES:
@@ -1740,6 +1759,8 @@ DTOOL_CONFIG=[
     ("HAVE_DIRECTCAM",                 'UNDEF',                  'UNDEF'),
     ("HAVE_SQUISH",                    'UNDEF',                  'UNDEF'),
     ("HAVE_FCOLLADA",                  'UNDEF',                  'UNDEF'),
+    ("HAVE_CARBON",                    'UNDEF',                  'UNDEF'),
+    ("HAVE_COCOA",                     'UNDEF',                  'UNDEF'),
     ("HAVE_OPENAL_FRAMEWORK",          'UNDEF',                  'UNDEF'),
     ("HAVE_ROCKET_PYTHON",             '1',                      '1'),
     ("HAVE_ROCKET_DEBUGGER",           'UNDEF',                  'UNDEF'),
@@ -1807,6 +1828,10 @@ def WriteConfigSettings():
         dtool_config["PHAVE_MALLOC_H"] = 'UNDEF'
         dtool_config["PHAVE_SYS_MALLOC_H"] = '1'
         dtool_config["HAVE_OPENAL_FRAMEWORK"] = '1'
+        if not RTDIST and not RUNTIME:
+            dtool_config["HAVE_COCOA"] = '1'
+        if not (UNIVERSAL or is_64):
+            dtool_config["HAVE_CARBON"] = '1'
         dtool_config["HAVE_X11"] = 'UNDEF'  # We might have X11, but we don't need it.
         dtool_config["HAVE_XRANDR"] = 'UNDEF'
         dtool_config["HAVE_XF86DGA"] = 'UNDEF'
@@ -2347,6 +2372,7 @@ if (sys.platform.startswith("win")):
     CopyAllHeaders('panda/src/wgldisplay')
 elif (sys.platform == "darwin"):
     CopyAllHeaders('panda/src/osxdisplay')
+    CopyAllHeaders('panda/src/cocoadisplay')
 else:
     CopyAllHeaders('panda/src/x11display')
     CopyAllHeaders('panda/src/glxdisplay')
@@ -2717,6 +2743,7 @@ if (not RUNTIME):
   TargetAdd('p3putil_composite2.obj', opts=OPTS, input='p3putil_composite2.cxx')
   IGATEFILES=GetDirectoryContents('panda/src/putil', ["*.h", "*_composite*.cxx"])
   IGATEFILES.remove("test_bam.h")
+  IGATEFILES.remove("paramValue.h")
   TargetAdd('libp3putil.in', opts=OPTS, input=IGATEFILES)
   TargetAdd('libp3putil.in', opts=['IMOD:panda', 'ILIB:libp3putil', 'SRCDIR:panda/src/putil'])
   TargetAdd('libp3putil_igate.obj', input='libp3putil.in', opts=["DEPENDENCYONLY"])
@@ -3017,6 +3044,7 @@ if (not RUNTIME):
   TargetAdd('p3grutil_composite1.obj', opts=OPTS, input='p3grutil_composite1.cxx')
   TargetAdd('p3grutil_composite2.obj', opts=OPTS, input='p3grutil_composite2.cxx')
   IGATEFILES=GetDirectoryContents('panda/src/grutil', ["*.h", "*_composite*.cxx"])
+  IGATEFILES.remove("convexHull.h")
   TargetAdd('libp3grutil.in', opts=OPTS, input=IGATEFILES)
   TargetAdd('libp3grutil.in', opts=['IMOD:panda', 'ILIB:libp3grutil', 'SRCDIR:panda/src/grutil'])
   TargetAdd('libp3grutil_igate.obj', input='libp3grutil.in', opts=["DEPENDENCYONLY"])
@@ -3689,11 +3717,30 @@ if (sys.platform != "win32" and sys.platform != "darwin" and PkgSkip("GL")==0 an
   TargetAdd('libpandagl.dll', input=COMMON_PANDA_LIBS)
   TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'NVIDIACG', 'CGGL', 'X11', 'XRANDR', 'XF86DGA', 'XCURSOR'])
 
+#
+# DIRECTORY: panda/src/cocoadisplay/
+#
+
+if (sys.platform == 'darwin' and PkgSkip("COCOA")==0 and PkgSkip("GL")==0 and not RUNTIME):
+  OPTS=['DIR:panda/src/cocoadisplay', 'BUILDING:PANDAGL', 'GL', 'NVIDIACG', 'CGGL']
+  TargetAdd('p3cocoadisplay_composite1.obj', opts=OPTS, input='p3cocoadisplay_composite1.mm')
+  OPTS=['DIR:panda/metalibs/pandagl', 'BUILDING:PANDAGL', 'GL', 'NVIDIACG', 'CGGL']
+  TargetAdd('pandagl_pandagl.obj', opts=OPTS, input='pandagl.cxx')
+  TargetAdd('libpandagl.dll', input='pandagl_pandagl.obj')
+  TargetAdd('libpandagl.dll', input='p3glgsg_config_glgsg.obj')
+  TargetAdd('libpandagl.dll', input='p3glgsg_glgsg.obj')
+  TargetAdd('libpandagl.dll', input='p3cocoadisplay_composite1.obj')
+  TargetAdd('libpandagl.dll', input='libp3glstuff.dll')
+  if (PkgSkip('PANDAFX')==0):
+    TargetAdd('libpandagl.dll', input='libpandafx.dll')
+  TargetAdd('libpandagl.dll', input=COMMON_PANDA_LIBS)
+  TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'NVIDIACG', 'CGGL', 'COCOA'])
+
 #
 # DIRECTORY: panda/src/osxdisplay/
 #
 
-if (sys.platform == 'darwin' and PkgSkip("GL")==0 and not RUNTIME):
+if (sys.platform == 'darwin' and PkgSkip("CARBON")==0 and PkgSkip("GL")==0 and not RUNTIME):
   OPTS=['DIR:panda/src/osxdisplay', 'BUILDING:PANDAGL',  'GL', 'NVIDIACG', 'CGGL']
   TargetAdd('p3osxdisplay_composite1.obj', opts=OPTS, input='p3osxdisplay_composite1.cxx')
   TargetAdd('p3osxdisplay_osxGraphicsWindow.obj', opts=OPTS, input='osxGraphicsWindow.mm')
@@ -5954,10 +6001,15 @@ def MakeInstallerOSX():
         plist.close()
         if not os.path.isdir("dstroot/" + pkg):
             os.makedirs("dstroot/" + pkg)
+
         if os.path.exists("/Developer/usr/bin/packagemaker"):
             cmd = '/Developer/usr/bin/packagemaker --info /tmp/Info_plist --version ' + VERSION + ' --out dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg --target 10.4 --domain system --root dstroot/' + pkg + '/ --no-relocate'
             if os.path.isdir("dstroot/scripts/" + pkg):
                 cmd += ' --scripts dstroot/scripts/' + pkg
+        elif os.path.exists("/Applications/Xcode.app/Contents/Applications/PackageMaker.app/Contents/MacOS/PackageMaker"):
+            cmd = '/Applications/Xcode.app/Contents/Applications/PackageMaker.app/Contents/MacOS/PackageMaker --info /tmp/Info_plist --version ' + VERSION + ' --out dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg --target 10.4 --domain system --root dstroot/' + pkg + '/ --no-relocate'
+            if os.path.isdir("dstroot/scripts/" + pkg):
+                cmd += ' --scripts dstroot/scripts/' + pkg
         elif os.path.exists("/Developer/Tools/packagemaker"):
             cmd = '/Developer/Tools/packagemaker -build -f dstroot/' + pkg + '/ -p dstroot/Panda3D/Panda3D.mpkg/Contents/Packages/' + pkg + '.pkg -i /tmp/Info_plist'
         else:

+ 1 - 1
panda/metalibs/pandagl/Sources.pp

@@ -10,7 +10,7 @@
 
 #define COMPONENT_LIBS \
     p3glgsg p3x11display p3glxdisplay  \
-    p3wgldisplay p3osxdisplay
+    p3wgldisplay p3osxdisplay p3cocoadisplay
 
 #define LOCAL_LIBS p3gsgbase p3display p3express
 #define OTHER_LIBS p3interrogatedb:c p3dconfig:c p3dtoolconfig:m \

+ 16 - 5
panda/metalibs/pandagl/pandagl.cxx

@@ -12,7 +12,12 @@
 #include "wglGraphicsPipe.h"
 #endif
 
-#ifdef IS_OSX
+#ifdef HAVE_COCOA
+#include "config_cocoadisplay.h"
+#include "cocoaGraphicsPipe.h"
+#endif
+
+#ifdef HAVE_CARBON
 #include "config_osxdisplay.h"
 #include "osxGraphicsPipe.h"
 #endif
@@ -22,8 +27,8 @@
 #include "glxGraphicsPipe.h"
 #endif
 
-#if !defined(HAVE_WGL) && !defined(IS_OSX) && !defined(HAVE_GLX)
-#error One of HAVE_WGL, IS_OSX or HAVE_GLX must be defined when compiling pandagl!
+#if !defined(HAVE_WGL) && !defined(HAVE_COCOA) && !defined(HAVE_CARBON) && !defined(HAVE_GLX)
+#error One of HAVE_WGL, HAVE_COCOA, HAVE_CARBON or HAVE_GLX must be defined when compiling pandagl!
 #endif
 
 // By including checkPandaVersion.h, we guarantee that runtime
@@ -48,7 +53,11 @@ init_libpandagl() {
   init_libwgldisplay();
 #endif  // HAVE_GL
 
-#ifdef IS_OSX
+#ifdef HAVE_COCOA
+  init_libcocoadisplay();
+#endif
+
+#ifdef HAVE_CARBON
   init_libosxdisplay();
 #endif
 
@@ -68,7 +77,9 @@ get_pipe_type_pandagl() {
   return wglGraphicsPipe::get_class_type().get_index();
 #endif
 
-#ifdef IS_OSX
+#if defined(HAVE_COCOA)
+  return CocoaGraphicsPipe::get_class_type().get_index();
+#elif defined(HAVE_CARBON)
   return osxGraphicsPipe::get_class_type().get_index();
 #endif
 

+ 1 - 1
panda/src/osxdisplay/Sources.pp

@@ -1,4 +1,4 @@
-#define BUILD_DIRECTORY $[and $[IS_OSX],$[HAVE_GL]]
+#define BUILD_DIRECTORY $[and $[IS_OSX],$[HAVE_GL],$[HAVE_CARBON]]
 
 #define OTHER_LIBS p3interrogatedb:c p3dconfig:c p3dtoolconfig:m \
                    p3dtoolutil:c p3dtoolbase:c p3dtool:m p3prc:c 

+ 1 - 1
panda/src/tinydisplay/Sources.pp

@@ -33,7 +33,7 @@
     tinyOffscreenGraphicsPipe.I tinyOffscreenGraphicsPipe.h \
     tinyOsxGraphicsPipe.I tinyOsxGraphicsPipe.h \
     tinyOsxGraphicsWindow.h tinyOsxGraphicsWindow.I \
-    $[if $[IS_OSX],tinyOsxGraphicsWindow.mm,] \
+    $[if $[and $[IS_OSX],$[HAVE_CARBON]],tinyOsxGraphicsWindow.mm,] \
     zbuffer.h zfeatures.h zgl.h \
     zline.h zmath.h \
     ztriangle_1.cxx ztriangle_2.cxx \

+ 2 - 2
panda/src/tinydisplay/config_tinydisplay.cxx

@@ -116,7 +116,7 @@ init_libtinydisplay() {
   ps->set_system_tag("TinyPanda", "native_window_system", "Win");
 #endif
 
-#if defined(IS_OSX) && !defined(BUILD_IPHONE)
+#if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON)
   TinyOsxGraphicsPipe::init_type();
   TinyOsxGraphicsWindow::init_type();
   selection->add_pipe_type(TinyOsxGraphicsPipe::get_class_type(),
@@ -150,7 +150,7 @@ get_pipe_type_p3tinydisplay() {
   return TinyWinGraphicsPipe::get_class_type().get_index();
 #endif
 
-#if defined(IS_OSX) && !defined(BUILD_IPHONE)
+#if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON)
   return TinyOsxGraphicsPipe::get_class_type().get_index();
 #endif
 

+ 1 - 1
panda/src/tinydisplay/tinyOsxGraphicsPipe.cxx

@@ -14,7 +14,7 @@
 
 #include "pandabase.h"
 
-#if defined(IS_OSX) && !defined(BUILD_IPHONE)
+#if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON)
 
 #include "tinyOsxGraphicsPipe.h"
 #include "config_tinydisplay.h"

+ 1 - 1
panda/src/tinydisplay/tinyOsxGraphicsPipe.h

@@ -17,7 +17,7 @@
 
 #include "pandabase.h"
 
-#if defined(IS_OSX) && !defined(BUILD_IPHONE)
+#if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON)
 
 // We have to include this early, before anyone includes
 // netinet/tcp.h, which will define TCP_NODELAY and other symbols and

+ 1 - 1
panda/src/tinydisplay/tinyOsxGraphicsWindow.h

@@ -17,7 +17,7 @@
 
 #include "pandabase.h"
 
-#if defined(IS_OSX) && !defined(BUILD_IPHONE)
+#if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON)
 
 #include <Carbon/Carbon.h>
 

+ 5 - 5
panda/src/tinydisplay/tinyOsxGraphicsWindow.mm

@@ -11,7 +11,7 @@
 
 #include "pandabase.h"
 
-#if defined(IS_OSX) && !defined(BUILD_IPHONE)
+#if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON)
 
 #include <Carbon/Carbon.h>
 #include <Cocoa/Cocoa.h>
@@ -48,7 +48,7 @@ struct work1
 };
 
 #define PANDA_CREATE_WINDOW  101
-static void Post_Event_Wiait(unsigned short type, unsigned int data1 , unsigned int data2 , int target_window ) {
+static void Post_Event_Wait(unsigned short type, unsigned int data1 , unsigned int data2 , int target_window ) {
     work1 w;
     w.work_done = false;
     NSEvent *ev = [NSEvent otherEventWithType:NSApplicationDefined
@@ -58,8 +58,8 @@ static void Post_Event_Wiait(unsigned short type, unsigned int data1 , unsigned
                                  windowNumber:target_window
                                       context:nil
                                       subtype:type
-                                        data1:data1
-                                        data2:(int)&w];
+                                        data1:(NSInteger)data1
+                                        data2:(NSInteger)&w];
 
     [NSApp postEvent:ev atStart:NO];
     while (!w.work_done)
@@ -1050,7 +1050,7 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties) {
       //    NSWindow*    childWindow            =    [[NSWindow alloc] initWithWindowRef:_osx_window];
 
 
-          Post_Event_Wiait(PANDA_CREATE_WINDOW,(unsigned long) _osx_window,1,[parentWindow windowNumber]);
+          Post_Event_Wait(PANDA_CREATE_WINDOW,(unsigned long) _osx_window,1,[parentWindow windowNumber]);
 
       //    [childWindow setFrameOrigin:origin];
       //    [childWindow setAcceptsMouseMovedEvents:YES];