[osx build/linking]

- Remove the need for client apps to explicitly link with all dependent libs and frameworks
- Don't require redistributing libEGL/libGLES if not used, by linking them with '-weak-l' option
- Change examples build scripts accordingly
This commit is contained in:
Martin Fouilleul 2023-02-21 17:09:26 +01:00
parent 94373d12ae
commit 3b26c92c85
7 changed files with 23 additions and 33 deletions

View File

@ -63,8 +63,15 @@ if [ $target = 'lib' ] ; then
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_c.o $CFLAGS $FLAGS $INCLUDES $SRCDIR/milepost.c $CC $DEBUG_FLAGS -c -o $BINDIR/milepost_c.o $CFLAGS $FLAGS $INCLUDES $SRCDIR/milepost.c
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_objc.o $FLAGS $INCLUDES $SRCDIR/milepost.m $CC $DEBUG_FLAGS -c -o $BINDIR/milepost_objc.o $FLAGS $INCLUDES $SRCDIR/milepost.m
# build the static library # build dynamic library
libtool -static -o $BINDIR/libmilepost.a $BINDIR/milepost_c.o $BINDIR/milepost_objc.o ld -dylib -o $BINDIR/libmilepost.dylib $BINDIR/milepost_c.o $BINDIR/milepost_objc.o -lc -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore -L$BINDIR -weak-lEGL -weak-lGLESv2
# change dependent libs path to @rpath.
install_name_tool -change "./libEGL.dylib" '@rpath/libEGL.dylib' $BINDIR/libmilepost.dylib
install_name_tool -change "./libGLESv2.dylib" '@rpath/libGLESv2.dylib' $BINDIR/libmilepost.dylib
# add executable path to rpath. Client executable can still add its own rpaths if needed, e.g. @executable_path/libs/ etc.
install_name_tool -add_rpath "@executable_path" $BINDIR/libmilepost.dylib
else else
# additional targets # additional targets

View File

@ -5,12 +5,7 @@ RESDIR=../../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore -L$BINDIR -lEGL -lGLESv2" LIBS="-L$BINDIR -lmilepost"
FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG -Wl,-dead_strip" FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG"
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_canvas main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_canvas main.c
# change dynamic libraries install name
#TODO: this shouldn't be needed for apps using only metal backend...
install_name_tool -change "./libEGL.dylib" "@loader_path/libEGL.dylib" $BINDIR/example_canvas
install_name_tool -change "./libGLESv2.dylib" "@loader_path/libGLESv2.dylib" $BINDIR/example_canvas

View File

@ -5,7 +5,7 @@ RESDIR=../../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$SRCDIR/graphics" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$SRCDIR/graphics"
LIBS="-L$BINDIR -lmilepost -framework Cocoa -framework Carbon -framework Metal -framework QuartzCore" LIBS="-L$BINDIR -lmilepost"
FLAGS="-O2 -mmacos-version-min=10.15.4" FLAGS="-O2 -mmacos-version-min=10.15.4"
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/perf_text main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/perf_text main.c

View File

@ -3,13 +3,10 @@
BINDIR=../../bin BINDIR=../../bin
RESDIR=../../resources RESDIR=../../resources
SRCDIR=../../src SRCDIR=../../src
EXTDIR=../../ext
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$SRCDIR/../ext/angle_headers" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$EXTDIR"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore -lGLESv2 -lEGL" LIBS="-L$BINDIR -lmilepost"
FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG" FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG"
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_gles_triangle main.c clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_gles_triangle main.c
# change dynamic libraries install name
install_name_tool -change "./libEGL.dylib" "@loader_path/libEGL.dylib" $BINDIR/example_gles_triangle
install_name_tool -change "./libGLESv2.dylib" "@loader_path/libGLESv2.dylib" $BINDIR/example_gles_triangle

View File

@ -12,8 +12,7 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include<math.h> #include<math.h>
#include<GLES3/gl32.h> #define MG_INCLUDE_GL_API 1
#include"milepost.h" #include"milepost.h"
#define LOG_SUBSYSTEM "Main" #define LOG_SUBSYSTEM "Main"
@ -70,6 +69,7 @@ int main()
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GLES); mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GLES);
mg_surface_prepare(surface);
//NOTE: init shader and gl state //NOTE: init shader and gl state
GLuint vao; GLuint vao;

View File

@ -5,16 +5,11 @@ RESDIR=../../resources
SRCDIR=../../src SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app" INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore -L$BINDIR -lEGL -lGLESv2" LIBS="-L$BINDIR -lmilepost -framework Foundation -framework Metal"
FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG -Wl,-dead_strip" FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG"
xcrun -sdk macosx metal -c -o shader.air shader.metal xcrun -sdk macosx metal -c -o shader.air shader.metal
xcrun -sdk macosx metallib -o shader.metallib shader.air xcrun -sdk macosx metallib -o shader.metallib shader.air
cp shader.metallib $BINDIR/triangle_shader.metallib cp shader.metallib $BINDIR/triangle_shader.metallib
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_metal_triangle main.m clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_metal_triangle main.m
# change dynamic libraries install name
#TODO: this shouldn't be needed for apps using only metal backend...
install_name_tool -change "./libEGL.dylib" "@loader_path/libEGL.dylib" $BINDIR/example_metal_triangle
install_name_tool -change "./libGLESv2.dylib" "@loader_path/libGLESv2.dylib" $BINDIR/example_metal_triangle

View File

@ -7,24 +7,20 @@ Overview
[/] error on bad option macro combinations [/] error on bad option macro combinations
[/] write doc about backend option macros [/] write doc about backend option macros
[?] could have an internal, per-platform mp_layer struct that handles resizing/hiding etc...
-> avoid duplication of frame/hiding and duplication of egl code.
[/] EGL surfaces: See how we can isolate platform-specific stuff and just deal with one egl impl...
[ ] Check that we can make GLES and GL surfaces co-exist in the app [ ] Check that we can make GLES and GL surfaces co-exist in the app
[ ] Allow controlling surface overlaying
[/] Allow selecting version of GL/GLES context when creating surface [/] Allow selecting version of GL/GLES context when creating surface
- pass/set attributes when creating surface? - pass/set attributes when creating surface?
[/] Automatic surface resizing [/] Automatic surface resizing
[!] Make linking with libEGL optional, even if EGL backend is compiled in milepost? [.] Make linking with libEGL optional, even if EGL backend is compiled in milepost?
- use dead_strip_dylib on osx?
- use /DELAYLOAD:lib on windows? - use /DELAYLOAD:lib on windows?
[.] Remove the need for client apps to link with all dependent libs explicitly
[!] Bundle examples with their own resources?? (e.g. avoiding clashes in metal libs files in bin directory) [!] Bundle examples with their own resources?? (e.g. avoiding clashes in metal libs files in bin directory)
[!] Sort out gles contents scaling for high dpi on osx [!] Allow controlling surface overlaying
[!] Sort out contents scaling for high dpi on osx
[!] win32 surfaces: only register surface child window once? [!] win32 surfaces: only register surface child window once?
[!] Fix canvas shader precision issue on OSX [!] Fix canvas shader precision issue on OSX
[!] Fix canvas perf issue on OSX [!] Fix canvas perf issue on OSX