Supermodel icon indicating copy to clipboard operation
Supermodel copied to clipboard

Compiling with NET_BOARD on macOS

Open GregoireLD opened this issue 2 years ago ā€¢ 18 comments

Hi

I successfully build and ran Supermodel on my M1 Arm Mac. Yet, when I tried to build it again with NET_BOARD enabled, I got an error referring to <SDL2_net/SDL_net.h> not being found.

both SDL_net and SDL2 are installed using brew.

Am I missing something here ? let me know if I can run or check anything you need.

GregoireLD avatar Nov 04 '22 20:11 GregoireLD

It works fine for me on M1 and x86 Macs with v2.01 of the SDL_net framework (built from source from: https://libsdl.org/projects/old/SDL_net/#source )

What version does homebrew include? It maybe still has the headers in "SDL_net/SDL*" not "SDL2_net/SDL*" [I purposely haven't tried the homebrew version of SDL_net as I don't want it to interfere with my already working fine installations].

If it helps, I've previously shared a precompiled versions of supermodel and the SDL_net framework (for M1 and x86) on the Supermodel forums (search for thread "Supermodel macOS Binaries for latest SVN release (r865)" ).

TheBrinkOfTomorrow avatar Nov 04 '22 21:11 TheBrinkOfTomorrow

Question for you mac guys. Are you using the new3d engine? What is the performance like?

dukeeeey avatar Nov 04 '22 21:11 dukeeeey

Question for you mac guys. Are you using the new3d engine? What is the performance like?

I just replied to your post on the forum. :-)

I'll paste it here....

_new3d engine has never worked on macOS / OS X as far back as I've been building/running it. I've assumed that it's just that Apple's [long since deprecated] OpenGL implementation is missing necessary features required for the new3d engine. [I'm sure the M1 GPU is more than sufficient to run it well..]

I just built cloned and built the latest code fromGithub, and here's the info output and the error I get with "-new3d - quad-rendering" - and the graphics are mostly corrupted/missing... same as my previous post... there's no difference on an x86 machine versus Apple Silicon.

TheBrinkOfTomorrow avatar Nov 04 '22 21:11 TheBrinkOfTomorrow

Try without quad rendering. The texture2dlod issue should be fixed

dukeeeey avatar Nov 04 '22 21:11 dukeeeey

Try without quad rendering. The texture2dlod issue should be fixed

You're right, sorry. It works perfectly without "-quad-rendering"

I hadn't tried in almost a year... seems to be fine (my test is always the first minute of scud race plus).

TheBrinkOfTomorrow avatar Nov 04 '22 21:11 TheBrinkOfTomorrow

Great thanks:)

dukeeeey avatar Nov 04 '22 21:11 dukeeeey

Great thanks:)

šŸ‘ Intel Mac with iGPU (UHD 630) works fine too.

(I'll update my prior forum posts to reflect this - i.e. use new3d, not legacy3d).

TheBrinkOfTomorrow avatar Nov 04 '22 21:11 TheBrinkOfTomorrow

It works fine for me on M1 and x86 Macs with v2.01 of the SDL_net framework (built from source from: https://libsdl.org/projects/old/SDL_net/#source )

If seems to be sdl_net 1.2.8 and sdl2_net 2.2.0 that got installed using brew. I purposefully try to avoid manually managing libraries and dependancies whenever I can.

Could it be that the current build process doesn't check the brew m1 path for libraries ? I might be clueless on this one

GregoireLD avatar Nov 04 '22 21:11 GregoireLD

FWIW, M1 Brew installed SDL_net in : /opt/homebrew/Cellar/sdl_net/1.2.8_1/include/SDL/SDL_net.h and SDL2_net in : /opt/homebrew/Cellar/sdl2_net/2.2.0/include/SDL2/SDL_net.h

GregoireLD avatar Nov 04 '22 21:11 GregoireLD

try changing #include <SDL2_net/SDL_net.h> to #include <SDL2/SDL_net.h> in this file https://github.com/trzy/Supermodel/blob/master/Src/OSD/SDL/SDLIncludes.h#L42

ToBul avatar Nov 04 '22 22:11 ToBul

same error : Src/OSD/SDL/SDLIncludes.h:42:10: fatal error: 'SDL2/SDL_net.h' file not found #include <SDL2/SDL_net.h>

weirdly enough, SDL_net doesn't seem to be included in the same folder as the rest of SDL.

One more info, It seems like at some point in the past I manually installed SDL2, which now resides in the Framework folder, as it should by default. That could mean, had I installed it using brew, it wouldn't have found the base SDL2 either (since brewed SDL2 is installed in /opt/homebrew/Cellar/sdl2/2.24.1/include/SDL2/ )

I will try removing my old SDL2 Framework if it goes as I think it does.

GregoireLD avatar Nov 04 '22 22:11 GregoireLD

Long story short, it does, it only seem to work with manually installed versions of SDL2.

Would it be suitable to add brew path as a suitable library path to allow managing SDL using brew instead of manually ?

GregoireLD avatar Nov 04 '22 22:11 GregoireLD

Thanks for the food for thought ToBul.

I fiddled around the makefile and SDLIncludes.h, and finally came up with a way to compile using standard brew SDL2 and SDL_net.

I added support for it with very little changes, and I use a USE_BREW=1 makefile parameter to enable it, without it the compiling process stays unchanged (I chose to use a flag so the people already seasoned to compiling it won't have to change anything).

May I try making a PR to add support for brew ? or should someone more experienced do it ?

It would make possible to compile Supermodel with just a brew install sdl2 sdl_net taking care of the requirements, and brew taking care of subsequent SDL updates.

I will provide my changes here for reference : In Makefiles/Makefile.OSX replacing 58 to 62 with :

ifeq ($(strip $(USE_BREW)),1)
	SDL_CFLAGS = -I$(shell brew --prefix)/include
	SDL_LIBS = -L$(shell brew --prefix)/lib -lSDL2 -framework AGL -framework OpenGL -framework GLUT -framework Cocoa
	ifeq ($(strip $(NET_BOARD)),1)
		SDL_LIBS += -lSDL2_net
	endif
else
	SDL_CFLAGS =
	SDL_LIBS = -framework SDL2 -framework AGL -framework OpenGL -framework GLUT -framework Cocoa
	ifeq ($(strip $(NET_BOARD)),1)
		SDL_LIBS += -framework SDL2_net
	endif
endif

In Makefiles/Rules.inc, insert at line 68 :

# If using Brew version of SDL, need to define USE_BREW
ifeq ($(strip $(USE_BREW)),1)
	SUPERMODEL_BUILD_FLAGS += -DUSE_BREW
endif

In Src/OSD/SDL/SDLIncludes.h, the line 42 is replaced with :

#ifdef USE_BREW
#include <SDL2/SDL_net.h>
#else
#include <SDL2_net/SDL_net.h>
#endif

GregoireLD avatar Nov 05 '22 01:11 GregoireLD

Sidenote regarding performances, so far it's pretty flawless on my MacBook M1 Max, I'm even using my Bluetooth xbox controller. Everything is awesome if you ask me. And regarding the "New3DEngine", I can confirm it was enabled by default in the config file, and no problem so far.

GregoireLD avatar Nov 05 '22 02:11 GregoireLD

Having flashbacks to using MacOS as my daily driver at Apple šŸ˜± So the issue is that Brew, as usual, is screwing everything up?

Could we devise a solution that does not involve a new Makefile flag? Iā€™m trying to think. Does Make have a way to test if a directory exists? It can execute shell commands, including sdl2-config. Can we use the output of that to parse out whether SDL2 or SDL2_net is the directory?

We could then either pass that in as a macro or drop the folder from the include for MacOS only and instead add the path to the compiler include path.

trzy avatar Nov 05 '22 03:11 trzy

Using brew also makes building with GitHub actions easier.

ToBul avatar Nov 05 '22 03:11 ToBul

I don't know how I feel about it, but I tested things in the line of trzy, finding a way to check if a suitable installation of brew was present automatically, instead of relying on a makefile parameter.

It tests if brew is present, and if SDL2 and SDL_net are installed using brew, if all conditions are met, it sets the USE_BREW flag, if not it runs as before.

it might not be (is not) the prettiest thing but I devised a way, yet it feels clumsy, so if someone have a better idea : to add in Makefiles/Makefile.OSX , before the SDL section at line 53

#
# Brew Tests
#

USE_BREW = 0
BREW_IS_INSTALLED = $(shell which brew >> /dev/null 2>&1 && echo 1 || echo 0)
ifeq ($(BREW_IS_INSTALLED),1)
	BREW_SDL = $(shell brew list | grep ^sdl2$$ | wc -l | xargs)
	ifeq ($(BREW_SDL),1)
		BREW_SDLNET = $(shell brew list | grep ^sdl_net$$ | wc -l | xargs)
		ifeq ($(BREW_SDLNET),1)
			USE_BREW = 1
		endif
	endif
endif

GregoireLD avatar Nov 05 '22 05:11 GregoireLD

I went ahead and made a fork and a PR with that, you can drop or deny it if you think it's a bad idea, or change it, I won't take offense, I'm pretty new to contributing on GitHub, and although I hope I followed the right process, I'm aware I might be completely wrong :-)

GregoireLD avatar Nov 05 '22 12:11 GregoireLD