I've been using the following macro:

macro(ADD_FRAMEWORK fwname appname)
  find_library(FRAMEWORK_${fwname}
    NAMES ${fwname}
    PATHS ${CMAKE_OSX_SYSROOT}/System/Library
    PATH_SUFFIXES Frameworks
    NO_DEFAULT_PATH)
  if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
    MESSAGE(ERROR ": Framework ${fwname} not found")
  else()
    TARGET_LINK_LIBRARIES(${appname} "${FRAMEWORK_${fwname}}/${fwname}")
    MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
  endif()
endmacro(ADD_FRAMEWORK)

Originally sourced from here:
http://stackoverflow.com/questions/12547624/cant-link-macos-frameworks-with-cmake

To successfully include standard Apple frameworks in my iOS Xcode projects
generated by CMake as shown below:

ADD_FRAMEWORK( AVFoundation hello_world )
ADD_FRAMEWORK( OpenGLES hello_world )

When I try this approach to include custom (i.e., non-Apple) frameworks, I
can't seem to get it to work.
For example, the following macro is modified to accept a custom path
location, but results in the NOTFOUND error shown below.

# Macro definition for framework at custom path location
macro(ADD_MYFRAMEWORK fwname appname fwpath)
  find_library(FRAMEWORK_${fwname}
    NAMES ${fwname}
    PATHS ${fwpath}
    NO_DEFAULT_PATH)
  if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
    MESSAGE(ERROR ": Framework ${fwname} not found")
  else()
    TARGET_LINK_LIBRARIES(${appname} "${FRAMEWORK_${fwname}}/${fwname}")
    MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
  endif()
endmacro(ADD_MYFRAMEWORK)

# Try to include my builds of opencv2.framework and GPUImage.framework
ADD_MYFRAMEWORK( opencv2 hello_world $ENV{OPENCV_FRAMEWORK} )
ADD_MYFRAMEWORK( GPUImage hello_world $ENV{GPUIMAGE} )

The above code produces the following errors when I run cmake:

calling ADD_MYFRAMEWORK with opencv2 hello_world /tmp/frameworks/
ERROR: Framework opencv2 not found
calling ADD_MYFRAMEWORK with GPUImage hello_world /tmp/frameworks/
ERROR: Framework GPUImage not found

What would be the best (or any) strategy for adding these frameworks to my
XCode generator project?  I'm new to CMake,
so any pointers (perhaps obvious) that might help me resolve this would be
welcome.

For comparison, the structure of a standard Apple OpenGLES framework that
is detected by the original ADD_FRAMEWORK macro,
and the "custom" opencv2 framework that isn't detected by the modified
ADD_MYFRAMEWORK macro are shown below.
The opencv2.framework does work when included in a standard XCode project,
but I suspect the lack of dylib files and/or the Headers,
or Versions folders are throwing off the find_library framework support.
I've tried adding a symbolic link to the library with an explicit
dylib extension (i.e., opencv2.dylib -> opencv2), but that didn't help.

I've also tried setting the CMAKE_FRAMEWORK_PATH explicitly above the macro
without any luck, i.e.,

set(CMAKE_FRAMEWORK_PATH $ENV{OPENCV_FRAMEWORK})

where the variable points to the /tmp/frameworks folder shown below.

# Non-working framework layout:
/tmp/frameworks/opencv2.framework/
├── Headers -> Versions/Current/Headers
├── Resources -> Versions/Current/Resources
├── Versions
│   ├── A
│   │   ├── Headers
│   │   │   ├── calib3d
│   │   │   │   └── calib3d.hpp
<<<<<<< snip >>>>>>>>
│   │   │   └── world
│   │   │       └── world.hpp
│   │   ├── Resources
│   │   │   └── Info.plist
│   │   └── opencv2
│   └── Current -> A
└── opencv2 -> Versions/Current/opencv2

The opencv2.framework/opencv2 links to
opencv2.framework/Versions/Current/opencv2, which has the following format:

lipo -info /tmp/frameworks/opencv2.framework/opencv2
Architectures in the fat file: /tmp/frameworks/opencv2.framework/opencv2
are: (cputype (16777228) cpusubtype (0)) armv7 armv7s i386 x86_64

# Working framework layout:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/OpenGLES.framework/
├── GLEngine.bundle
│   └── GLEngine
├── Headers
│   ├── EAGL.h
│   ├── EAGLDrawable.h
│   ├── ES1
│   │   ├── gl.h
│   │   └── glext.h
│   ├── ES2
│   │   ├── gl.h
│   │   └── glext.h
│   └── ES3
│       ├── gl.h
│       └── glext.h
├── OpenGLES
├── libCLRendererStubs.dylib
├── libCVMSPluginSupport.dylib
├── libCoreFSCache.dylib
├── libCoreVMClient.dylib
├── libGFXShared.dylib
├── libGLImage.dylib
├── libGLProgrammability.dylib
├── libGLVMPlugin.dylib
├── libLLVMContainer.dylib
└── module.map

The dylib files have the following format:
lipo -info
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/OpenGLES.framework/libGLImage.dylib
Architectures in the fat file:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/OpenGLES.framework/libGLImage.dylib
are: (cputype (16777228) cpusubtype (0)) armv7 armv7s
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to