سؤال

I'm trying to add Mac OS X framework usage to my program, which includes some files with Objective-c++ code.

It DOES work with SET (CMAKE_EXE_LINKER_FLAGS "-framework CoreMedia -framework ... "), but i don't really like this way and it seems just wrong.

That's the CMake part of actual adding, but it doesn't work and i dont really know what i'm missing :( I tried using the

link_directories("${CMAKE_OSX_SYSROOT}/System/Library/Frameworks")
include_directories("${CMAKE_OSX_SYSROOT}/System/Library/Frameworks")

but it didn't help at all. So here's the code:

add_executable(myprogram src/myprogram.cpp)

FIND_LIBRARY(COREMEDIA_LIB NAMES CoreMedia)
FIND_LIBRARY(COREVIDEO_LIB NAMES CoreVideo)
FIND_LIBRARY(FOUNDATION_LIB NAMES Foundation)
FIND_LIBRARY(AVFOUNDATION_LIB NAMES AVFoundation)

target_link_libraries(myprogram ${COREMEDIA_LIB})
target_link_libraries(myprogram ${COREVIDEO_LIB})
target_link_libraries(myprogram ${FOUNDATION_LIB})
target_link_libraries(myprogram ${AVFOUNDATION_LIB})

It produces the cmake errors:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
AVFOUNDATION_LIB
linked by target "myprogram" in directory <some directory containing app>

<... other 3 are here aswell ...>
هل كانت مفيدة؟

المحلول

Ok, got it. I need to specify PATHS variable to ${CMAKE_OSX_SYSROOT}/System/Library. I don't know why but it can't find it in this folder automatically, thought it's a standard folder though...

so call like this:

for example, when i link AVFoundation framework:

add_executable(myprogram)

find_library(SOME_VAR
    NAMES AVFoundation
    PATHS ${CMAKE_OSX_SYSROOT}/System/Library
    PATH_SUFFIXES Frameworks
    NO_DEFAULT_PATH)

and then

target_link_libraries(myprogram "${SOME_VAR}/AVFoundation")

Hope it will help someone.

نصائح أخرى

This is working for me:

IF (APPLE)
   find_library(COREMIDI_LIBRARY CoreMIDI)
   find_library(COREFOUNDATION_LIBRARY CoreFoundation)
   target_link_libraries(myprogram ${COREFOUNDATION_LIBRARY} ${COREMIDI_LIBRARY})
ENDIF (APPLE)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top