[CMake] Linking against OS X Frameworks

Michael Jackson mike.jackson at bluequartz.net
Fri Aug 7 14:57:13 EDT 2009


On Aug 7, 2009, at 9:30 AM, Bill Hoffman wrote:

> ML wrote:
>> Hi Michael,
>> I still get the same compile errors as before. But works using  
>> Xcode for me.
>> Is there another resource as I can't find an example of these basic  
>> things on the wiki. Even Google searching is not really turning up  
>> much. I did find:http://www.vtk.org/Wiki/CMake:HowToUseExistingOSXFrameworks 
>>  which is how I structured my first example but alas nothing. Even  
>> for this list I few people replied with ideas none that seem to work.
>> I would appreciate pointers!
>
> Folks, CMake is framework aware.   You don't need to add the -F  
> stuff. You can either use a full path to a framework in  
> include_directories or
> in target_link_libraries.   Find_library will also find frameworks.
>
> The following will work:
>
> find_library(CARBON NAMES Carbon)
> add_executable(foo foo.cxx)
> target_link_libraries(foo ${CARBON})
>
> -Bill

Not to beat a dead horse BUT I think there is a slight problem that am  
coming up against and I am sure there is simple line in the cmake file  
that I am missing:

project (MoreFilesX)
cmake_minimum_required(VERSION 2.6)
SET(MOREFILESX_HEADERS MoreFilesX.h)
SET(MOREFILESX_SOURCES MoreFilesX.c)
FIND_LIBRARY(CARBON_LIBRARY NAMES Carbon)
SET(EXTRA_LIBS ${CARBON_LIBRARY} )
ADD_LIBRARY (MoreFilesX ${MOREFILESX_SOURCES} ${MOREFILESX_HEADERS})
target_link_libraries(MoreFilesX ${EXTRA_LIBS})

This on its own will not allow a compilation of the source files. I  
had to add

CMAKE_C_FLAGS  -isysroot /Developer/SDKs/MacOSX10.4u.sdk

to the CMakeCache in order to generate a good Unix Makefile and/or  
Xcode project. So I must be missing something because CMake looks for  
and sets the CMAKE_OSX_SYSROOT variable on start up. My question is  
why wouldn't cmake add the -isysroot flags to the compiler command?

Mike Jackson


More information about the CMake mailing list