Reputation: 1949
I have written a small helloworld program that needs the Cocoa framework. I'd like to know how to add a framework in CMake. All the information I have found is out-of-date. I have CMake 2.8.1 on Snow Leopard.
Upvotes: 23
Views: 30043
Reputation: 22245
Supports public and private frameworks
macro( target_link_framework TARGET NAME )
find_library( FRAMEWORK_${NAME}
NAMES ${NAME}
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks PrivateFrameworks
CMAKE_FIND_FRAMEWORK only
NO_DEFAULT_PATH )
if( ${FRAMEWORK_${NAME}} STREQUAL FRAMEWORK_${NAME}-NOTFOUND)
message( ERROR ": Framework ${NAME} not found" )
else()
target_link_libraries( ${TARGET} PUBLIC "${FRAMEWORK_${NAME}}" )
message( STATUS "Framework ${NAME} found at ${FRAMEWORK_${NAME}}" )
endif()
endmacro( target_link_framework )
Upvotes: 0
Reputation: 5310
another solution: https://stackoverflow.com/a/18330634/2482283
target_link_libraries(program "-framework Cocoa")
Upvotes: 15
Reputation: 752
Can you just use find_library
like this: find_library(COCOA_LIBRARY Cocoa)
?
Then use ${COCOA_LIBRARY}
in your target_link_libraries
. Possibly setting the CMAKE_FIND_FRAMEWORK
variable to ONLY
.
Also, refer to this article: How to use existing OSX frameworks.
Upvotes: 32