It has been noted a few months ago that hiding an objective-C++
file inside a .cxx file is not a very good practice.

I would like to propose to stop this practice, and thus to
compile, specifically for Mac OS X, three .mm files
Fl_cocoa.mm
Fl_Quartz_Printer.mm
Fl_Native_File_Chooser_MAC.mm
instead of having them included by .cxx files and compiled with the
option -x objective-c++.

I include here the svn diff that implements this change. Two
files of the building system are impacted:
src/Makefile
makeinclude.in
I checked that
   configure; make
run well on Mac OS X and Linux with these changes.

The construction of the Xcode project would have to be changed
a little as well (I don't have access to that). Essentially, the
changes are to add the three .mm files listed above to the list
of files compiled for the libfltk target, and to remove the special
flags that forced files Fl.cxx, Fl_Printer.cxx and
Fl_Native_File_Chooser.cxx to be compiled with -x objective-c++.

Any opinion/objection about this proposal ?


Index: src/Fl_Native_File_Chooser.cxx
===================================================================
--- src/Fl_Native_File_Chooser.cxx      (revision 8041)
+++ src/Fl_Native_File_Chooser.cxx      (working copy)
@@ -32,7 +32,7 @@

 // Use Apple's chooser
 #ifdef __APPLE__
-#include "Fl_Native_File_Chooser_MAC.mm"
+//#include "Fl_Native_File_Chooser_MAC.mm"
 #endif

 // All else falls back to FLTK's own chooser
Index: src/Fl_Printer.cxx
===================================================================
--- src/Fl_Printer.cxx  (revision 8022)
+++ src/Fl_Printer.cxx  (working copy)
@@ -29,7 +29,7 @@
 #include <FL/Fl_Printer.H>

 #ifdef __APPLE__
-#include "Fl_Quartz_Printer.mm"
+//#include "Fl_Quartz_Printer.mm"
 #elif defined(WIN32)
 #include "Fl_GDI_Printer.cxx"
 #endif
Index: src/Makefile
===================================================================
--- src/Makefile        (revision 8022)
+++ src/Makefile        (working copy)
@@ -166,6 +166,10 @@
        screen_xywh.cxx \
        fl_utf8.cxx \
        ps_image.cxx
+
+MMFILES = $(shell \
+       if [ `uname` = Darwin ]; then echo 'Fl_cocoa.mm Fl_Quartz_Printer.mm 
Fl_Native_File_Chooser_MAC.mm';\
+       fi)

 FLCPPFILES = \
        forms_compatability.cxx \
@@ -215,7 +219,7 @@

 include ../makeinclude

-OBJECTS = $(CPPFILES:.cxx=.o) $(CFILES:.c=.o) $(UTF8CFILES:.c=.o)
+OBJECTS = $(CPPFILES:.cxx=.o) $(CFILES:.c=.o) $(UTF8CFILES:.c=.o) 
$(MMFILES:.mm=.o)
 GLOBJECTS = $(GLCPPFILES:.cxx=.o)
 FLOBJECTS = $(FLCPPFILES:.cxx=.o)
 IMGOBJECTS = $(IMGCPPFILES:.cxx=.o)
@@ -472,8 +476,8 @@
                libfltk_gl.dylib libfltk_images.dylib \
                cmap core

-depend:        $(CPPFILES) $(FLCPPFILES) $(GLCPPFILES) $(IMGCPPFILES) 
$(CFILES) $(UTF8CFILES)
-       makedepend -Y -I.. -f makedepend $(CPPFILES) $(FLCPPFILES) \
+depend:        $(CPPFILES) $(MMFILES) $(FLCPPFILES) $(GLCPPFILES) 
$(IMGCPPFILES) $(CFILES) $(UTF8CFILES)
+       makedepend -Y -I.. -f makedepend $(CPPFILES) $(MMFILES) $(FLCPPFILES) \
                $(GLCPPFILES) $(IMGCPPFILES) $(CFILES) $(UTF8CFILES)

 # Automatically generated dependencies... generated on a Linux/Unix host !
@@ -484,8 +488,10 @@
 # Please add only non-Linux/Unix files or such that are optional
 # (like "*xft*") here:
 Fl_get_key.o:  Fl_get_key_mac.cxx Fl_get_key_win32.cxx
-Fl_Native_File_Chooser.o : Fl_Native_File_Chooser_MAC.cxx 
Fl_Native_File_Chooser_WIN32.cxx
-Fl.o:          Fl_mac.cxx Fl_win32.cxx Fl_cocoa.mm
+Fl_Native_File_Chooser.o : Fl_Native_File_Chooser_WIN32.cxx
+Fl_Native_File_Chooser_MAC.o:  Fl_Native_File_Chooser_MAC.mm
+Fl.o:          Fl_mac.cxx Fl_win32.cxx
+Fl_cocoa.o:    Fl_cocoa.mm
 fl_color.o:    fl_color_mac.cxx fl_color_win32.cxx
 fl_dnd.o:      fl_dnd_mac.cxx fl_dnd_win32.cxx fl_dnd_x.cxx
 fl_draw_image.o: fl_draw_image_mac.cxx fl_draw_image_win32.cxx
@@ -493,7 +499,8 @@
 fl_read_image.o: fl_read_image_mac.cxx fl_read_image_win32.cxx
 fl_set_fonts.o:        fl_set_fonts_mac.cxx fl_set_fonts_x.cxx \
                fl_set_fonts_xft.cxx fl_set_fonts_win32.cxx
-Fl_Printer.o:  Fl_Quartz_Printer.mm Fl_GDI_Printer.cxx Fl_PostScript.cxx
+Fl_Printer.o: Fl_GDI_Printer.cxx Fl_PostScript.cxx
+Fl_Quartz_Printer.o:   Fl_Quartz_Printer.mm
 fl_arci.o:     ../FL/mac.H ../FL/win32.H
 Fl_arg.o:      ../FL/mac.H ../FL/win32.H
 fl_ask.o:      ../FL/mac.H ../FL/win32.H
Index: src/Fl_cocoa.mm
===================================================================
--- src/Fl_cocoa.mm     (revision 8023)
+++ src/Fl_cocoa.mm     (working copy)
@@ -703,6 +703,16 @@
   return (got_events);
 }

+double fl_MAC_flush_and_wait(double time_to_wait, char in_idle) {
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+  Fl::flush();
+  if (Fl::idle && !in_idle) // 'idle' may have been set within flush()
+    time_to_wait = 0.0;
+  double retval = fl_wait(time_to_wait);
+  [pool release];
+  return retval;
+}
+
 // updates Fl::e_x, Fl::e_y, Fl::e_x_root, and Fl::e_y_root
 static void update_e_xy_and_e_xy_root(NSWindow *nsw)
 {
Index: src/Fl.cxx
===================================================================
--- src/Fl.cxx  (revision 8031)
+++ src/Fl.cxx  (working copy)
@@ -48,10 +48,6 @@
 #include <stdlib.h>
 #include "flstring.h"

-#if defined(__APPLE__)
-#import <Cocoa/Cocoa.h>
-#endif
-
 #if defined(DEBUG) || defined(DEBUG_WATCH)
 #  include <stdio.h>
 #endif // DEBUG || DEBUG_WATCH
@@ -63,6 +59,8 @@
 void fl_cleanup_pens(void);
 void fl_release_dc(HWND,HDC);
 void fl_cleanup_dc_list(void);
+#elif defined(__APPLE__)
+extern double fl_MAC_flush_and_wait(double time_to_wait, char in_idle);
 #endif // WIN32

 //
@@ -420,13 +418,7 @@
     // the idle function may turn off idle, we can then wait:
     if (idle) time_to_wait = 0.0;
   }
-  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-  flush();
-  if (idle && !in_idle) // 'idle' may have been set within flush()
-    time_to_wait = 0.0;
-  double retval = fl_wait(time_to_wait);
-  [pool release];
-  return retval;
+  return fl_MAC_flush_and_wait(time_to_wait, in_idle);

 #else

@@ -1556,8 +1548,7 @@

 #ifdef WIN32
 #  include "Fl_win32.cxx"
-#elif defined(__APPLE__)
-#  include "Fl_cocoa.mm"
+//#elif defined(__APPLE__)
 #endif

 //
Index: makeinclude.in
===================================================================
--- makeinclude.in      (revision 8005)
+++ makeinclude.in      (working copy)
@@ -143,7 +143,7 @@
 .SILENT:

 # Build commands and filename extensions...
-.SUFFIXES:     .0 .1 .3 .6 .c .cxx .h .fl .man .o .z $(EXEEXT)
+.SUFFIXES:     .0 .1 .3 .6 .c .cxx .mm .h .fl .man .o .z $(EXEEXT)

 .o$(EXEEXT):
        echo Linking $...@...
@@ -155,16 +155,13 @@

 .cxx.o:
        echo Compiling $<...
-       @if test `uname` = Darwin -a $< = Fl.cxx ; then \
-               $(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ 
$(CXXFLAGS) -x objective-c++ -c $< -o $@; \
-       elif test `uname` = Darwin -a  $< = Fl_Native_File_Chooser.cxx ; then \
-               $(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ 
$(CXXFLAGS) -x objective-c++ -c $< -o $@; \
-       elif test `uname` = Darwin -a  $< = Fl_Printer.cxx ; then \
-               $(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ 
$(CXXFLAGS) -x objective-c++ -c $< -o $@; \
-       else \
-               $(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ 
$(CXXFLAGS) -c $< -o $@; \
-       fi
+       $(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -c $< 
-o $@
+
+.mm.o:
+       echo Compiling $<...
+       $(CXX) -I.. $(ARCHFLAGS) $(CXXFLAGS) -x objective-c++ -c $< -o $@

+
 .man.0 .man.1 .man.3 .man.6:
        echo Formatting $<...
        rm -f $@



_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to