Compilation on Mac OS X

From Stellarium Wiki
Revision as of 11:42, 13 September 2009 by Mina (Talk | contribs)
Jump to: navigation, search

This document attempts to describe how to build Stellarium for Macosx from source, most recently 0.10.3. It tries to list all the dependencies and steps. This process ought to improve over time.

IMPORTANT: These instructions currently build Stellarium that is not a universal binary, it is specific to the machine (PPC or Intel) that it was made on. Universal binaries buildable by all is yet a goal for the Macosx port. The built Stellarium is also currently dependent on how and where libraries are installed on your system: if you've got some interesting setup, a build you make with it might not run so good on other macs with less interesting setups.



Before the list of build dependencies, there are some minimum system requirements to follow these instructions:

  1. Mac OS X 10.4, as most recent as possible. As of this writing 2007-12-29, 10.4.11 is available and known to work for both PPC and Intel. Earlier versions might work, but I don't know, and more steps might be needed. Note also that 10.4.7 should be avoided at all costs.
  2. or Mac OS X 10.5. 10.5.1, 10.5.6, 10.5.7 and 10.5.8 are known to work.
  3. Xcode as recent as possible. This author has Xcode 2.4.1 (ppc 10.4) and 3.1.2 (intel 10.5). See [1]. Earlier versions might work, with additional or changed steps.
  4. MacPorts installed. See [2].
  5. (fink is an alternative to MacPorts, but not a favored one, preferably in the default /sw. See [3])

In addition, this author prefers to install Qt and CMake from the .dmg distributions that [4] and [5] provide for these. These packages are always as up to date as possible, where MacPorts and Fink will lag behind the time.s

With MacPorts

If installing Qt and/or CMake from packages, do that first, then

   sudo port install subversion boost libsdl_mixer libsdl freetype jpeg

Or, if you prefer the macports versions of Qt and CMake, this:

   sudo port install subversion cmake boost libsdl_mixer libsdl qt4-mac freetype jpeg libpng

Advantage of this setup is that you use the macports cmake, so you dont have to manually specify include-dirs and paths for qt, sdl and fonts (see below). Be aware that installing Qt4-Mac with macports may take several hours since it will build the package from source.

You may find that certain packages fail to install if you do not have recent enough versions of x11 and xextproto. If you receive an error indicating that you have the wrong version of these you can update them with:

   sudo port -u upgrade outdated

With Fink

From the list of build dependencies, we need to actually *think* about only the following:

  1. Cmake, from [6]
  2. libpng, get this via fink with "fink install libpng3" (you might need "sudo" in front of that)
  3. libjpeg, get this via fink with "fink install libjpeg" (likewise)
  4. libboost, get this via fink with "fink install boost1.33" (1.33 was most current as of this writing)
  5. libsdl, this can also be finked with "fink install sdl-shlibs"
  6. Qt 4.5, go out to [7], look for their open-source downloads of Qt/Mac. This should be installed the default way.
  7. SDL_mixer, if and only if you want audio. This I had to compile especially (get from [[8]]), the fink build had some hidden dependencies (timidity, for instance, wants things in /usr/local...) that I removed with this configure for SDL_mixer:
 CPPFLAGS="-I/sw/include -I/sw/include/ogg" LDFLAGS="-L/sw/lib" ./configure --prefix=/sw --disable-music-midi --disable-music-timidity-midi --disable-music-ogg-shared --disable-music-mp3-shared --enable-music-ogg --enable-music-mp3
  1. subversion, here I found fink's svn not so good for 1.4.3, I had to resort to [9]. Another option is this package by Martin Ott, Developer of CodingMonkeys


Make a directory


And in that directory in your favorite shell, utter the svn command to check out the source:

 svn co stellarium

Now things start to look like the linux instructions some:

 cd stellarium 
 mkdir -p builds/macosx
 cd builds/macosx

The process now differs with Fink and MacPorts (easier with MacPorts)

With Fink

Now the moment of truth: the cmake command (i'm in bash!):

 SDL_INCLUDE_DIR=/sw/include/SDL cmake -G "Unix Makefiles"  ../..

This says: set the environment variable SDL_INCLUDE_DIR to /sw/include/SDL, use the "Unix Makefiles" generator of cmake. If it doesn't find Qt, you should maybe append the path to Qt to your shell path:

 export PATH=/usr/local/Trolltech/Qt-4.5.0/bin:$PATH

It will think about that for a bit, and then complain:

 CMake Error: Error in cmake code at
 MESSAGE Could not find the FreeType2 library and header files.
 Current CMake stack: /Users/Shared/stellarium/stellarium/CMakeLists.txt;/usr/share/cmake-2.4/Modules/CMakeCInformation.cmake;/usr/share/cmake-2.4/Modules/CMakeCXXInformation.cmake;/Users/Shared/stellarium/stellarium/cmake/FindFreeType2.cmake

This is all right: cmake never seems to be able to correctly find freetype2 here on the mac. You are still in builds/macosx. In this directory now there should be a CMakeCache.txt file. Either edit that file, and find the line:


and change it to read:




For Macports or fink, respectively.

Or use

 ccmake .

To accomplish the same thing somewhat more conveniently.

Now utter the same cmake command a second time, and it should think some more, and end up with:

 -- Configuring done
 -- Generating done
 -- Build files have been written to: /Users/Shared/stellarium/stellarium/builds/macosx

Now we can perform the build itself, two steps:

 make install
 make macosx_bundle

Now up in /Users/Shared/stellarium, you ought to see a, ready to run!

With MacPorts

Type the following command in your terminal window

 cmake -G "Unix Makefiles"  ../..

This says: use the "Unix Makefiles" generator of cmake. It should say

 -- Configuring done
 -- Generating done
 -- Build files have been written to: /Users/Shared/stellarium/stellarium/builds/macosx

If you installed Qt using macports, then you may see an error reporting tha "Qt qmake" could not be found. This seems to be because Macports installs qmake with the file name 'qmake-mac'. You can resolve the error by creating a symlink:

cd to /opt/local/bin (or wherever you have told macports to install to).


   sudo ln -s qmake-mac qmake

change back to your build/macosx directory and try cmake again as above, it should now find qmake.

Then perform the build itself, three steps:

 make install
 make macosx_bundle

Now up in /Users/Shared/stellarium, you ought to see a in /Users/Shared/stellarium, ready to run!


The macosx_bundle target includes a perl script that makes use of otool and install_name_tool to:

  1. read the link dependencies of
  2. copy those dependencies into the app (.frameworks and .dylibs)
  3. recurse on those copied-in dependencies, stopping at a point where system libraries are called for

This seems to work for making a relocatable Making a universal build from here is a matter of taking an intel and a ppc and merging them appropriately.

I've found that making a universal app directly via cmake to not work, even the better mac-supporting 2.6. Any insights appreciated!

To get CMake to do all the packaging and linking above (to take better advantage of cmake 2.6), we need to re-arrange the CMAke properties a bit across all the ports, and this is a somewhat larger undertaking.


You can check to see if the source code has been updated on the server at any time by going in a terminal window to


And entering the command

 svn -u status

Any file that it mentions is either changed locally, or changed on the server (svn help status for details of the output of this command). Unless you are working on the source code yourself, anything mentioned is an update. You can update from this directory also with

 svn update

IMPORTANT: you should delete or move aside the old /Users/Shared/stellarium/ before each new build.

Why Not Xcode?

Cmake has an Xcode generator (as opposed to "Unix Makefiles"), as of CMake 2.4.7, or perhaps xcode 2.5, this seems to be working better. One wants to choose the macosx_bundle target, and build it. This author prefers the unix makefiles, but now happily it's just a matter of preference.

Getting a universal build out of Xcode depends entirely on having universal libraries for all the dependencies.

Cmake generally has made this whole compilation process on the mac both more repeatable, and more like the other platforms (or, at least, more like the unix and such...). This is a Good Thing.


All kinds of things might go wrong!

  1. if the cmake or the build complains about a missing library, it might need installation. Start with fink.
  2. if the compilation breaks on some code, it may be that the developers are in the middle of something, and come back in a svn revision or so.
  3. anything else I haven't remembered or encountered!

Loadable Module Support

I was able to get loadable module support working, and have submitted patches for the CMakeLists.txt files in StellaGui and HelloStelModule. These build straightforwardly:

  1. edit the top-level CMakeLists.txt file to point to where your real stellarium source and build directories are.
  2. make builds/macosx and cd to it
  3. run cmake and make:
 cmake -G "Unix Makefiles"  ../..
 make install

and you should have StellaGui or HelloStelModule as a directory in builds/macosx, which you can copy to ~/Library/Preferences/Stellarium/modules/ (you may have to make that directory).

To Do

  • make the build a universal binary (somehow...)
  • Build an iPhone/iPod Touch port
  •  ???
Personal tools
in this wiki
other languages