premake / premake/premake-core

Question: What is the 'correct' way to add Frameworks for gmake projects on macos

Open
#196 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

gmake question
Dominant language
C
Stars
3.6k
Forks
654
Avg merge
1d 1h
Merged PRs (30d)
13

Description

Summary

I was wondering what the 'correct' way would be to include non-system *.framework files on macos in Premake5, with the ultimate goal of using gmake with clang or gnu compiler.

My assumptions about compiling with frameworks

Correct me if I'm wrong, but as far as I've been able to find out, when compiling a program with a non-system framework under clang or gcc/g++ you need to:

  1. specify what name of framework to use: -framework <FRAMEWORK NAME>
  2. specify location of framework(s) to use: -F <PATH TO FRAMEWORK>

So for example, if I'm compiling a program using SDL2, where SDL2.framework is located at /Library/Frameworks/ then I would add -framework SDL2 -F /Library/Frameworks to my compile string.

From some experimentation - see snippet: https://gist.github.com/JohannesMP/6ff3463482ebbdc82c2e - I've established that, at least on my machine, step 2. is required and not including it causes the compiler to not be able to find the header file in the framework when compiling the object files, and also results in an error when linking them.


Question regarding Premake5

When using Premake, I've seen some projects only do the following:

...
configuration "macosx"
    links {"OpenGL.framework","CoreFoundation.framework","SDL2.framework"}
...

But, at least when using gmake, this seems to create a make file that does not include step 2. above, and so I get the same error as I did in my snippet above (lines 15 and 27)

To be able to account for this I've so far done the following:

...
configuration "macosx"
    links {"OpenGL.framework","CoreFoundation.framework","SDL2.framework"}    
configuration {"macosx", "gmake"}
    buildoptions {"-F /Library/Frameworks"}
    linkoptions {"-F /Library/Frameworks"}
...

However that has the problem of not being portable - for example some users don't have their frameworks located in the global frameworks directory and instead have it in their user directory, ie ~/Library/Frameworks. Furthermore if I try to include both locations, there is a good chance that one of them may not yet exist on a user's machine (they're not created by default) and so they may get an error when running make:

ld: warning: directory not found for option '-F/Users/Jo/Library/Frameworks'

So instead of using buildoptions and linkoptions, is there a better, portable way to include frameworks in Premake5?

Alternatively, is there some global configuration that I am missing on my mac that would make it so that I don't need to include the -F /Path/To/Framework compile/link flag? It seems that it's not required for system frameworks, at least those located in /System/Library/Frameworks.

For reference, here are the premake5.lua file and the c file for a simple SDL2 'hello window' program that I've been using for testing: https://gist.github.com/JohannesMP/9a9b5263c127103f1861#file-premake5-lua-L24-L26 - The highlighted lines are what my question is about.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced premake5.lua and C test program, then inspect the generated gmake files and the macOS framework handling in Premake5. Reproduce the SDL2.framework case with the shown build and link options. Done means establishing and documenting a portable approach for non-system framework search paths without requiring nonexistent directories.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua, macos
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.