GENie icon indicating copy to clipboard operation
GENie copied to clipboard

Linking against non system Mac OS X framework

Open howprice opened this issue 7 years ago • 9 comments

I'm trying to fix up my genie.lua to link against /Library/Frameworks/SDL2.framework for the Mac OS X build.

GENie version 837 command line: $ genie xcode4

I've tried:

configuration "macosx"
    links { "SDL2.framework" }

but this results in location /System/Library/Frameworks/SDL2.framework rather than the desired /Library/Frameworks/SDL2.framework so the project doesn't build.

I've also tried:

configuration "macosx"
    links { "/Library/Frameworks/SDL2.framework" }

but this results in :

[string "premake.xcode.parameters = { }..."]:229: relative paths are not currently supported for frameworks

The framework can be added manually in Xcode -> Build Phases -> Link Binary With Libraries -> + -> Add Other... -> /Library/Frameworks/SDL2.framework but I can't figure out how to achieve this in the script.

Many thanks for any advice. genie.lua.zip

howprice avatar Jun 28 '17 20:06 howprice

You can try this:

configuration "macosx"
	linkoptions { "-F/Library/Frameworks/" }
	links { "SDL2.framework" }

Note: it's not tested, I don't have a Mac OS X

dankan1890 avatar Jun 28 '17 22:06 dankan1890

I've had issues with this as well, with some strange behavior around the ".framework" extension being handled specially behind the scenes in a way that assumed it was a system framework. I resolved it by doing this (edited to match your situation), but I think there's some internal GENie behavior that perhaps needs a look.

      linkoptions {
         "-F/Library/Frameworks",
         "-framework SDL2",
      }

fitzymj avatar Jun 29 '17 03:06 fitzymj

Why not linking SDL as library?

bkaradzic avatar Jun 29 '17 03:06 bkaradzic

@dankan1890 's way still results in a project that is looking in /System/Library/...

@fitzymj 's way results in a project with no reference at all to the SDL2.framework

@bkaradzic - I'm new to Mac and the "The SDL-devel package contains the SDL libraries in the form of a Framework" so I thought that would be the way to go for Xcode. Looks like I might have to try "the UNIX way". Thanks

howprice avatar Jun 29 '17 08:06 howprice

Ah, right. So if you use my way you won't get the nice Xcode display of framework references. But it will compile and link correctly.

Depending on how you're doing distribution, you may need to copy it into your app bundle as well (which doesn't happen automatically for you because it's not a "reference" as far as Xcode is concerned). That would be something like this, as a post-build command:

   local libsPath = "${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Frameworks/"
   local cmds = {
      "rm -rf " .. libsPath .. "SDL2.framework",
      "cp -R /Library/Frameworks/SDL2.framework " .. libsPath,
   }
   postbuildcommands(cmds)

Not the most elegant, but hopefully it unblocks you!

fitzymj avatar Jun 29 '17 14:06 fitzymj

See my scripts for dealing with SDL (just follow that with-sdl) https://github.com/bkaradzic/bgfx/blob/master/scripts/genie.lua#L144

bkaradzic avatar Jun 29 '17 15:06 bkaradzic

@fitzymj Using your technique it fails to build because it can't find SDL.h. Do I have to manually specify an include path too?

@bkaradzic Thanks. Do I have to install SDL to /usr/local/... to build this way? And how is SDL_DIR specified on Mac?

howprice avatar Jun 29 '17 18:06 howprice

OK. I built SDL2 from source and installed, then copied the headers and /usr/local/lib folders into my project folder. This allows the project to build

		configuration "macosx"
			buildoptions { "-std=c++11" }
			includedirs { "../3rdparty/SDL2-2.0.5/include" }
			libdirs { "../3rdparty/SDL2-2.0.5/lib/macosx" }
			links { "SDL2" }

Unfortunately the project doesn't run if I uninstall SDL2: dyld: Library not loaded: /usr/local/lib/libSDL2-2.0.0.dylib. I guess I can work around this by statically linking.

Thanks for your help.

howprice avatar Jun 29 '17 22:06 howprice

@howprice SDL_DIR is set just as environment variable in bash...

On Mac I just install those via brew, and everything just works...

bkaradzic avatar Jun 30 '17 03:06 bkaradzic