Skip to content

Commit bddd630

Browse files
committed
gfxlib2/darwin: initial support for opengl displays using cocoa
1 parent 0ae389f commit bddd630

File tree

7 files changed

+555
-23
lines changed

7 files changed

+555
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.exe
44
*.dll
55
*.so
6+
*.dSYM
67
/fbc
78
/fbc-new
89
/bin/*

makefile

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
# -d DISABLE_STDCXX_PATH tells fbc to not search for some libstdc++/libc++ depending on target platform
129129
# -d BUILD_FB_DEFAULT_CPUTYPE_X86=<FB_CPUTYPE> set default x86 cpu type to one of FB_CPUTYPE
130130
# -d BUILD_FB_DEFAULT_CPUTYPE_ARM=<FB_CPUTYPE> set default arm cpu type to one of FB_CPUTYPE
131-
# -d FBFORKID="name" tells fbc to set a custom value for __FB_BUILD_FORK_ID__
131+
# -d FBFORKID="name" tells fbc to set a custom value for __FB_BUILD_FORK_ID__
132132
#
133133
# internal makefile configuration (but can override):
134134
# libsubdir override the library directory - default is set depending on TARGET
@@ -180,6 +180,7 @@ FBFLAGS := -maxerr 1
180180
AS = $(BUILD_PREFIX)as
181181
AR = $(BUILD_PREFIX)ar
182182
CC = $(BUILD_PREFIX)gcc
183+
OBJC = $(CC) -x objective-c
183184
prefix := /usr/local
184185

185186
# Determine the makefile's directory, this may be a relative path when
@@ -579,9 +580,8 @@ ifeq ($(TARGET_OS),solaris)
579580
endif
580581

581582
ifeq ($(TARGET_OS),darwin)
582-
ALLCFLAGS += -I/opt/X11/include -I/usr/include/ffi
583-
584583
ifdef ENABLE_XQUARTZ
584+
ALLCFLAGS += -I/opt/X11/include
585585
ALLFBCFLAGS += -d ENABLE_XQUARTZ
586586
else
587587
ALLCFLAGS += -DDISABLE_X11
@@ -717,11 +717,14 @@ LIBFBRTMTPIC_C := $(patsubst %,$(libfbmtpicobjdir)/%,$(filter-out $(patsubst $(l
717717
LIBFBGFX_H := $(sort $(foreach i,$(GFXLIB2_DIRS),$(wildcard $(i)/*.h)) $(LIBFB_H))
718718
LIBFBGFX_C := $(sort $(foreach i,$(GFXLIB2_DIRS),$(patsubst $(i)/%.c,$(libfbgfxobjdir)/%.o,$(wildcard $(i)/*.c))))
719719
LIBFBGFX_S := $(sort $(foreach i,$(GFXLIB2_DIRS),$(patsubst $(i)/%.s,$(libfbgfxobjdir)/%.o,$(wildcard $(i)/*.s))))
720+
LIBFBGFX_M := $(sort $(foreach i,$(GFXLIB2_DIRS),$(patsubst $(i)/%.m,$(libfbgfxobjdir)/%.o,$(wildcard $(i)/*.m))))
720721
LIBFBGFXPIC_C := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxpicobjdir)/%,$(LIBFBGFX_C))
722+
LIBFBGFXPIC_M := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxpicobjdir)/%,$(LIBFBGFX_M))
721723
LIBFBGFXMT_C := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtobjdir)/%,$(LIBFBGFX_C))
722724
LIBFBGFXMT_S := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtobjdir)/%,$(LIBFBGFX_S))
725+
LIBFBGFXMT_M := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtobjdir)/%,$(LIBFBGFX_M))
723726
LIBFBGFXMTPIC_C := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtpicobjdir)/%,$(LIBFBGFX_C))
724-
727+
LIBFBGFXMTPIC_M := $(patsubst $(libfbgfxobjdir)/%,$(libfbgfxmtpicobjdir)/%,$(LIBFBGFX_M))
725728

726729
RTL_LIBS := $(libdir)/$(FB_LDSCRIPT)
727730
ifdef ENABLE_NONPIC
@@ -768,6 +771,7 @@ ifndef V
768771
QUIET_FBC = @echo "FBC $@";
769772
QUIET_LINK = @echo "LINK $@";
770773
QUIET_CC = @echo "CC $@";
774+
QUIET_OBJC = @echo "OBJC $@";
771775
QUIET_CPPAS = @echo "CPPAS $@";
772776
QUIET_AS = @echo "AS $@";
773777
QUIET_AR = @echo "AR $@";
@@ -984,29 +988,37 @@ $(LIBFBMTRTPIC_BAS): $(libfbrtmtpicobjdir)/%.o: %.c $(LIBFBRT_BI) | $(libfbrtmtp
984988
.PHONY: gfxlib2
985989
gfxlib2: $(GFX_LIBS)
986990

987-
$(libdir)/libfbgfx.a: $(LIBFBGFX_C) $(LIBFBGFX_S) | $(libdir)
991+
$(libdir)/libfbgfx.a: $(LIBFBGFX_C) $(LIBFBGFX_S) $(LIBFBGFX_M) | $(libdir)
988992
$(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
989993
$(LIBFBGFX_C): $(libfbgfxobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxobjdir)
990994
$(QUIET_CC)$(CC) $(ALLCFLAGS) -c $< -o $@
991995
$(LIBFBGFX_S): $(libfbgfxobjdir)/%.o: %.s $(LIBFBGFX_H) | $(libfbgfxobjdir)
992996
$(QUIET_CPPAS)$(CC) -x assembler-with-cpp $(ALLCFLAGS) -c $< -o $@
997+
$(LIBFBGFX_M): $(libfbgfxobjdir)/%.o: %.m $(LIBFBGFX_H) | $(libfbgfxobjdir)
998+
$(QUIET_OBJC)$(OBJC) $(ALLCFLAGS) $(OBJCFLAGS) -c $< -o $@
993999

994-
$(libdir)/libfbgfxpic.a: $(LIBFBGFXPIC_C) | $(libdir)
1000+
$(libdir)/libfbgfxpic.a: $(LIBFBGFXPIC_C) $(LIBFBGFX_M) | $(libdir)
9951001
$(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
9961002
$(LIBFBGFXPIC_C): $(libfbgfxpicobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxpicobjdir)
9971003
$(QUIET_CC)$(CC) -fPIC $(ALLCFLAGS) -c $< -o $@
1004+
$(LIBFBGFXPIC_M): $(libfbgfxpicobjdir)/%.o: %.m $(LIBFBGFX_H) | $(libfbgfxpicobjdir)
1005+
$(QUIET_OBJC)$(OBJC) -fPIC $(ALLCFLAGS) $(OBJCFLAGS) -c $< -o $@
9981006

999-
$(libdir)/libfbgfxmt.a: $(LIBFBGFXMT_C) $(LIBFBGFXMT_S) | $(libdir)
1007+
$(libdir)/libfbgfxmt.a: $(LIBFBGFXMT_C) $(LIBFBGFXMT_S) $(LIBFBGFX_M) | $(libdir)
10001008
$(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
10011009
$(LIBFBGFXMT_C): $(libfbgfxmtobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxmtobjdir)
10021010
$(QUIET_CC)$(CC) -DENABLE_MT $(ALLCFLAGS) -c $< -o $@
10031011
$(LIBFBGFXMT_S): $(libfbgfxmtobjdir)/%.o: %.s $(LIBFBGFX_H) | $(libfbgfxmtobjdir)
10041012
$(QUIET_CPPAS)$(CC) -x assembler-with-cpp -DENABLE_MT $(ALLCFLAGS) -c $< -o $@
1013+
$(LIBFBGFXMT_M): $(libfbgfxmtobjdir)/%.o: %.m $(LIBFBGFX_H) | $(libfbgfxmtobjdir)
1014+
$(QUIET_OBJC)$(OBJC) -DENABLE_MT $(ALLCFLAGS) $(OBJCFLAGS) -c $< -o $@
10051015

1006-
$(libdir)/libfbgfxmtpic.a: $(LIBFBGFXMTPIC_C) | $(libdir)
1016+
$(libdir)/libfbgfxmtpic.a: $(LIBFBGFXMTPIC_C) $(LIBFBGFX_H) | $(libdir)
10071017
$(QUIET_AR)rm -f $@; $(AR) rcs $@ $^
10081018
$(LIBFBGFXMTPIC_C): $(libfbgfxmtpicobjdir)/%.o: %.c $(LIBFBGFX_H) | $(libfbgfxmtpicobjdir)
10091019
$(QUIET_CC)$(CC) -DENABLE_MT -fPIC $(ALLCFLAGS) -c $< -o $@
1020+
$(LIBFBGFXMTPIC_M): $(libfbgfxmtpicobjdir)/%.o: %.m $(LIBFBGFX_H) | $(libfbgfxmtpicobjdir)
1021+
$(QUIET_OBJC)$(OBJC) -DENABLE_MT -fPIC $(ALLCFLAGS) $(OBJCFLAGS) -c $< -o $@
10101022

10111023
################################################################################
10121024

@@ -1133,7 +1145,7 @@ gitdist:
11331145
# By default FBPACKTARGET will have been set to FBTARGET. FBPACKTARGET
11341146
# can be used to override the default package naming allowing alternate
11351147
# packages to be generated for specific systems while retaining all the
1136-
# properties of an FBTARGET based release.
1148+
# properties of an FBTARGET based release.
11371149
# If FBPACKAGE is defined then FBPACKTARGET has no effect.
11381150
#
11391151
ifndef FBPACKAGE

src/compiler/fbc.bas

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type FBCCTX
8888
'' are multiple lists necessary to allow each module to start fresh
8989
'' with the same input libs)
9090
finallibs as TSTRSET
91+
finalframeworks as TSTRSET
9192
finallibpaths as TSTRSET
9293

9394
outname as zstring * FB_MAXPATHLEN+1
@@ -214,6 +215,7 @@ private sub fbcInit( )
214215
strsetInit( @fbc.excludedlibs, FBC_INITFILES\4 )
215216

216217
strsetInit(@fbc.finallibs, FBC_INITFILES\2)
218+
strsetInit(@fbc.finalframeworks, FBC_INITFILES\2)
217219
strsetInit(@fbc.finallibpaths, FBC_INITFILES\2)
218220

219221
fbGlobalInit()
@@ -1162,9 +1164,9 @@ private function hLinkFiles( ) as integer
11621164
ldcline += hFindLib( "crt0.o" )
11631165
end if
11641166

1165-
case FB_COMPTARGET_LINUX, FB_COMPTARGET_DARWIN, _
1166-
FB_COMPTARGET_FREEBSD, FB_COMPTARGET_OPENBSD, _
1167-
FB_COMPTARGET_NETBSD, FB_COMPTARGET_DRAGONFLY, FB_COMPTARGET_SOLARIS
1167+
case FB_COMPTARGET_LINUX, FB_COMPTARGET_FREEBSD, _,
1168+
FB_COMPTARGET_OPENBSD, FB_COMPTARGET_NETBSD, _,
1169+
FB_COMPTARGET_DRAGONFLY, FB_COMPTARGET_SOLARIS
11681170

11691171
if( fbGetOption( FB_COMPOPT_OUTTYPE ) = FB_OUTTYPE_EXECUTABLE) then
11701172
if( fbGetOption( FB_COMPOPT_PROFILE ) ) then
@@ -1286,6 +1288,15 @@ private function hLinkFiles( ) as integer
12861288
wend
12871289
end scope
12881290

1291+
'' Add frameworks for Darwin
1292+
scope
1293+
dim as TSTRSETITEM ptr i = listGetHead(@fbc.finalframeworks.list)
1294+
while (i)
1295+
ldcline += " -framework " + i->s
1296+
i = listGetNext(i)
1297+
wend
1298+
end scope
1299+
12891300
if (fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_DARWIN) then
12901301
if( fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_JS ) then
12911302
'' End of lib group
@@ -1322,18 +1333,13 @@ private function hLinkFiles( ) as integer
13221333

13231334
end select
13241335

1325-
if( fbGetOption( FB_COMPOPT_TARGET ) = FB_COMPTARGET_DARWIN ) then
1326-
ldcline += " -macosx_version_min 10.4"
1327-
end if
1328-
13291336
'' This is required for 64-bit modules on *nix-y platforms
13301337
'' for the unwind tables to have any effect
13311338
'' Windows doesn't need this option
13321339
select case as const fbGetOption( FB_COMPOPT_TARGET )
13331340
case FB_COMPTARGET_LINUX, FB_COMPTARGET_FREEBSD, _
13341341
FB_COMPTARGET_OPENBSD, FB_COMPTARGET_NETBSD, _
1335-
FB_COMPTARGET_DRAGONFLY, FB_COMPTARGET_SOLARIS, _
1336-
FB_COMPTARGET_DARWIN
1342+
FB_COMPTARGET_DRAGONFLY, FB_COMPTARGET_SOLARIS
13371343
dim as long outtype = fbGetOption( FB_COMPOPT_OUTTYPE )
13381344
if outtype = FB_OUTTYPE_EXECUTABLE OrElse outtype = FB_OUTTYPE_DYNAMICLIB Then
13391345
dim as long cpufamily = fbGetCpuFamily( )
@@ -1404,6 +1410,12 @@ private function hLinkFiles( ) as integer
14041410
end if
14051411
#endif
14061412

1413+
if fbGetOption( FB_COMPOPT_TARGET ) = FB_COMPTARGET_DARWIN then
1414+
dim as string sdkpath = hGet1stOutputLineFromCommand("xcrun --show-sdk-path")
1415+
ldcline += " -L" + sdkpath + "/usr/lib"
1416+
ldcline += " -F" + sdkpath + "/System/Library/Frameworks"
1417+
end if
1418+
14071419
'' invoke ld
14081420
var ld = FBCTOOL_LD
14091421
if( fbGetOption( FB_COMPOPT_TARGET ) = FB_COMPTARGET_JS ) then
@@ -4201,7 +4213,9 @@ private sub hSetDefaultLibPaths( )
42014213
case FB_COMPTARGET_JS
42024214
'' We let emcc handle linking
42034215
case else
4204-
fbcAddLibPathFor( "libgcc.a" )
4216+
if fbGetOption( FB_COMPOPT_TARGET ) <> FB_COMPTARGET_DARWIN then
4217+
fbcAddLibPathFor( "libgcc.a" )
4218+
end if
42054219

42064220
#ifndef DISABLE_STDCXX_PATH
42074221
'' we don't specifically need c++, but for some users that do want to
@@ -4212,6 +4226,8 @@ private sub hSetDefaultLibPaths( )
42124226
fbcAddLibPathFor( "libc++.so" )
42134227
case FB_COMPTARGET_DOS
42144228
fbcAddLibPathFor( "libstdcx.a" )
4229+
case FB_COMPTARGET_DARWIN
4230+
fbcAddLibPathFor( "libc++.dylib" )
42154231
case else
42164232
fbcAddLibPathFor( "libstdc++.so" )
42174233
end select
@@ -4237,6 +4253,10 @@ private sub fbcAddDefLib(byval libname as zstring ptr)
42374253
strsetAdd(@fbc.finallibs, *libname, TRUE)
42384254
end sub
42394255

4256+
private sub fbcAddDefFramework(byref framework as string)
4257+
strsetAdd(@fbc.finalframeworks, framework, TRUE)
4258+
end sub
4259+
42404260
private function hGetFbLibNameSuffix( ) as string
42414261
dim s as string
42424262
if( fbGetOption( FB_COMPOPT_MULTITHREADED ) ) then
@@ -4279,7 +4299,14 @@ private sub hAddDefaultLibs( )
42794299
#endif
42804300

42814301
#if defined(__FB_DARWIN__) and defined(ENABLE_XQUARTZ)
4282-
fbcAddDefLibPAth( "/opt/X11/lib" )
4302+
fbcAddDefLibPath( "/opt/X11/lib" )
4303+
#else
4304+
if fbGetOption( FB_COMPOPT_TARGET ) = FB_COMPTARGET_DARWIN then
4305+
fbcAddDefFramework( "Foundation" )
4306+
fbcAddDefFramework( "AppKit" )
4307+
fbcAddDefFramework( "OpenGL" )
4308+
fbcAddDefFramework( "Cocoa" )
4309+
end if
42834310
#endif
42844311

42854312
#if (not defined(__FB_DARWIN__)) or defined(ENABLE_XQUARTZ)
@@ -4289,7 +4316,6 @@ private sub hAddDefaultLibs( )
42894316
fbcAddDefLib( "Xrandr" )
42904317
fbcAddDefLib( "Xrender" )
42914318
#endif
4292-
42934319
case FB_COMPTARGET_ANDROID
42944320
errReportEx( FB_ERRMSG_GFXLIBNOTSUPPORTEDFORTARGET, "", -1 )
42954321

@@ -4309,7 +4335,6 @@ private sub hAddDefaultLibs( )
43094335
end if
43104336

43114337
case FB_COMPTARGET_DARWIN
4312-
fbcAddDefLib( "gcc" )
43134338
fbcAddDefLib( "System" )
43144339
fbcAddDefLib( "pthread" )
43154340
fbcAddDefLib( "ncurses" )

src/gfxlib2/darwin/fb_gfx_cocoa.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <sys/types.h>
2+
#include "../fb_gfx.h"
3+
4+
extern const GFXDRIVER fb_gfxDriverCocoaOpenGL;
5+
6+
extern void fb_hCocoaLock(void);
7+
extern void fb_hCocoaUnlock(void);
8+
extern void fb_hCocoaWaitVSync(void);
9+
extern int fb_hCocoaGetMouse(int *x, int *y, int *z, int *buttons, int *clip);
10+
extern void fb_hCocoaSetMouse(int x, int y, int cursor, int clip);
11+
extern void fb_hCocoaSetWindowTitle(char *title);
12+
extern int fb_hCocoaSetWindowPos(int x, int y);
13+
extern int *fb_hCocoaFetchModes(int depth, int *size);
14+
extern int fb_hCocoaEnterFullscreen(int *h);
15+
extern int fb_hCocoaScreenInfo(ssize_t *width, ssize_t *height, ssize_t *depth, ssize_t *refresh);

0 commit comments

Comments
 (0)