[CMake] Linking against OS X Frameworks

ML mailinglists at MailNewsRSS.com
Fri Aug 7 06:32:53 EDT 2009


Hi Michael,

Thank you for your reply.

>>>> What is the best way to do that exactly? I am in cluding Carbon/ 
>>>> Carbon.h in my source files. but I guess CMAKE needs to know  
>>>> where to fine them too. moving form XCode is harder than I  
>>>> thought it would be.
>>
>>> include_directories (${CMAKE_OSX_SYSROOT}/Developer/Headers/ 
>>> FlatCarbon)
>>>
>>> Then in your code you can do #include <Carbon.h>
>>>
>>> Although I am not really sure this is the "correct" way to do this.
>>>
>>> I think you should be really looking for the "Carbon.framework"  
>>> and then using that..
>>
>> I am getting more confused! This works in XCode for me, it is just  
>> two files.
>>
>> Does anyone have an example CMake file that includes Crbon headers,  
>> links agains the carbon framework, etc? What I am doing is  
>> obviously wrong


> I just tried it with CMake 2.6.3 and as you reported, find_library  
> finds Carbon.framework just fine, but the target_link_libraries  
> command just drops it again. IMHO, what it actually should do  
> (expressed in CMake-code) the following
>
>
> get_filename_component( FRAMEWORK_DIR ${CARBON_LIBRARY} PATH )
> get_filename_component( FRAMEWORK_NAME ${CARBON_LIBRARY} NAME_WE )
>
> set_target_properties( someTarget PROPERTIES
> COMPILE_FLAGS "-F ${FRAMEWORK_DIR}"
> LINK_FLAGS "-F ${FRAMEWORK_DIR} -framework ${FRAMEWORK_NAME}"
> )
>
>
> I.e. it should add the directory containing the framework to the  
> framework search path (such that things like #include <Carbon/ 
> Carbon.h> work) and then add "-framework Carbon" to the link command.
>
>
> Of course, if everything is installed in standard locations, this is  
> unnecessary...

I am running: cmake version 2.6-patch 4

I am confused still. you say if everything is installed in standard  
locations this is unnecessary. Yes, everything is a standard plain  
vanilla OS X install.

So everything you just did above is unnecessary then?

Here is what I have now:

	if (APPLE)
		SET(MOREFILESX_HEADERS source/thirdparty/OSX/MoreFilesX/MoreFilesX.h)
	
		SET(MOREFILESX_SOURCES source/thirdparty/OSX/MoreFilesX/MoreFilesX.c)
		
		FIND_LIBRARY (CARBON_LIBRARY Carbon.framework)
		MARK_AS_ADVANCED (CARBON_LIBRARY)
		
		get_filename_component( FRAMEWORK_DIR ${CARBON_LIBRARY} PATH )
		get_filename_component( FRAMEWORK_NAME ${CARBON_LIBRARY} NAME_WE )
		
		ADD_LIBRARY (MoreFilesX ${MOREFILESX_SOURCES} ${MOREFILESX_HEADERS})
		set_target_properties( MoreFilesX PROPERTIES
		 COMPILE_FLAGS "-F ${FRAMEWORK_DIR}"
		 LINK_FLAGS "-F ${FRAMEWORK_DIR} -framework ${FRAMEWORK_NAME}"
		)
		
	ENDIF (APPLE)

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!

-Jason


More information about the CMake mailing list