CMakeLists.txt changes for Building OS X Binaries

Asked by Julio

In order to build stratagus for OS X 10.8.2, I make the following changes to CMakeLists.txt:

751a752,757
> if(MAC_BUNDLE)
> add_definitions(-DMAC_BUNDLE)
> add_definitions(-DMAC_BUNDLE_DATADIR="data")
> endif()
>
>
924a931,935
> if(APPLE AND ENABLE_STATIC)
> set_target_properties(stratagus PROPERTIES LINK_FLAGS "${LINK_FLAGS} -L/opt/local/lib /opt/local/lib/libSDLmain.a /opt/local/lib/libSDL.a -L/opt/local/lib /opt/local/lib/libxcb.a /opt/local/lib/libX11.a /opt/local/lib/libXdmcp.a /opt/local/lib/libXau.a /opt/local/lib/libXext.a /opt/local/lib/libXrandr.a /opt/local/lib/libXrender.a -Wl,-framework,OpenGL -Wl,-framework,Cocoa -Wl,-framework,ApplicationServices -Wl,-framework,Carbon -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,IOKit /opt/local/lib/libmng.a /opt/local/lib/libjpeg.a /opt/local/lib/liblcms.a")
> endif()
>
>
952a964,967
>
> if(APPLE AND ENABLE_STATIC)
> set_target_properties(metaserver PROPERTIES LINK_FLAGS "${LINK_FLAGS} -L/opt/local/lib /opt/local/lib/libSDLmain.a /opt/local/lib/libSDL.a -L/opt/local/lib /opt/local/lib/libxcb.a /opt/local/lib/libX11.a /opt/local/lib/libXdmcp.a /opt/local/lib/libXau.a /opt/local/lib/libXext.a /opt/local/lib/libXrandr.a /opt/local/lib/libXrender.a -Wl,-framework,OpenGL -Wl,-framework,Cocoa -Wl,-framework,ApplicationServices -Wl,-framework,Carbon -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,IOKit /opt/local/lib/libmng.a /opt/local/lib/libjpeg.a /opt/local/lib/liblcms.a")
> endif()

The first (MAC_BUNDLE) just activates code which was already in the source, and should be safe for everyone.

The second/third (if APPLE AND ENABLE_STATIC) adds the libraries I needed to make statically linked binaries. Can't guarantee that this will work for everyone, however, it only affects anyone trying to build it on an APPLE with ENABLE_STATIC=on, so I imagine it's probably safe as well.

I then build my makefiles with the following:

cmake -G "Unix Makefiles" -DENABLE_STATIC=on -DMAC_BUNDLE=on ..
make stratagus

Any chance on getting these added to the branch?

If there's a better way (than editing CMakeLists.txt), I'm all ears.

Question information

Language:
English Edit question
Status:
Answered
For:
Stratagus Edit question
Assignee:
Pali Edit question
Last query:
Last reply:
Revision history for this message
Pali (pali) said :
#1

For first patch. We already have section in CMakeLists.txt:

if(APPLE)
 add_definitions(-DUSE_MAC)
 add_definitions(-D__unix)
endif()

Isnt USE_MAC enought (and if yes, then fix cpp source files)? I do not know that cmake APPLE and cmake MAC_BUNDLE doing... In cmake manual there is no info about MAC_BUNDLE.

Next is problematic. You are using using LINK_FLAGS for adding non-standard library directories (-L flags) and hardcoding linking libraries with full paths. CMake searching for libraries (and returning FULL path!) in find_package(...) commands. I think that you should look at SDL and X11 cmake modules and patch these (if necessery) for static linking. See cmake manual (man cmake) for more info.

Revision history for this message
Julio (artofwar) said :
#2

For first patch.
USE_MAC is sufficient for building Mac binary,

HOWEVER,
If one is to make a "Mac Application Bundle" (see: http://en.wikipedia.org/wiki/Application_bundle) it is necessary to set the MAC_BUNDLE options appropriately so that stratagus can find resources correctly within the bundle.

For flexibility, since one may desire to make a Mac binary but not create a "bundle", it is desirable to have have BOTH options separate.

I happened upon MAC_BUNDLE and MAC_BUNDLE_DATADIR while going through stratagus.cpp in an effort to make a stratagus bundle. Apparently, someone had already added the functionality :)

Revision history for this message
Pali (pali) said :
#3

Hm, seems that cmake has some support for Mac Bundle, see cmake man page: http://linux.die.net/man/1/cmake So somebody with Mac OSX can look at it and write correct cmake support for that...

Can you help with this problem?

Provide an answer of your own, or ask Julio for more information if necessary.

To post a message you must log in.