[CMake] Good sample code for finding and using os x frameworks?

E. Wing ewmailing at gmail.com
Thu Apr 5 18:22:55 EDT 2007


CMake's framework detection mechanism is now complete. Mike already
pointed out how to use FIND_LIBRARY which is all correct. There is a
nuance with include paths which I'll describe here.

You need to decide about your #include usage pattern. Generally, OS X
system frameworks are included as:
#include <Cocoa/Cocoa.h>
#include <OpenAL/al.h>

But portable libraries may recommend doing flat namespaces because not
everybody use the same directory name. For example, the OpenAL spec
doesn't define where headers are located. Linux puts them in
<AL/al.h>, OS X does <OpenAL/al.h>, and Windows doesn't put them in
any directory so it is <al.h>. In theory, somebody else could screw
this up even more and put it in <AL1.1/al.h>. Thus the 'portable'
solution is:
#include "al.h"

CMake is really clever about the two cases, so if you have the usage
first case, you want to do:

FIND_PATH(COCOA_INCLUDE_DIR Cocoa/Cocoa.h)

In the second case you want to do:
FIND_PATH(OPENAL_INCLUDE_DIR al.h)

CMake will set the include paths correctly depending on which style
you specify.

-Eric


More information about the CMake mailing list