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.
How to add a framework to CMake
Asked Answered
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.
How does this guarantee that the Cocoa framework version of the library is included as opposed to a regular unix style library? –
Theseus
another solution: https://mcmap.net/q/584913/-why-i-cannot-link-the-mac-framework-file-with-cmake
target_link_libraries(program "-framework Cocoa")
Create a Macro: target_link_framework
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 )
© 2022 - 2024 — McMap. All rights reserved.