I just had a hard time building a simple SDL application using CMake and Macports on Mac OS X. On Linux things are really simple – you ask for SDL, pkg-config returns the right configuration and everything works. Not on OS X.
Using a typical CMake-configuration
project(mygame)
find_package(PkgConfig)
pkg_check_modules(SDL sdl)
include_directories(${SDL_INCLUDE_DIRS})
add_executable(mygame
main.cpp
)
target_link_libraries(mygame ${SDL_LIBRARIES})
I execute CMake using
cmake -DCMAKE_EXE_LINKER_FLAGS=”-L/opt/local/lib” -DCMAKE_CXX_FLAGS=”-I/opt/local/include” ../src/
and run “make”. This doesn’t work. It turns out you have to link with the Cocoa framework. So obvious, right?
cmake -DCMAKE_EXE_LINKER_FLAGS=”-L/opt/local/lib -framework Cocoa” -DCMAKE_CXX_FLAGS=”-I/opt/local/include” ../src/