简体   繁体   中英

How do we add facebookSDK into a xcode project using cmake?

I am having some difficulties adding facebookSDK.framework into my xcode project using cmake? Here's what i have done up to now. But it doesn't seem to work

set (facebook_sdk_path ${CMAKE_HOME_DIRECTORY}/external/framework/facebook/ios)
message("adding facebookSDK" ${facebook_sdk_path})
target_link_libraries(${Target} "${facebook_sdk_path}/facebookSDK.framework/facebookSDK")

I believe we need to set the framework under "framework search paths" on the project settings, but I am not exactly too sure on how to do this.

found my solution: i used this macro i found from CMake and XCode: "cannot find interface declaration for 'NSObject'"

macro(AddExternalFramework fwname appname libpath)
    find_library(FRAMEWORK_${fwname}
        NAMES ${fwname}
        PATHS ${libpath} 
        NO_DEFAULT_PATH)
    if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
        MESSAGE(ERROR ": Framework ${fwname} not found: ${FRAMEWORK_${fwname}}")
    else()
        TARGET_LINK_LIBRARIES(${appname} ${FRAMEWORK_${fwname}})
        MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
    endif()
endmacro(AddExternalFramework)

I ran into the same issue but Frank's answer didn't work for me. As it was mentioned on the post referenced, calling TARGET_LINK_LIBRARIES messes up the FRAMEWORK_SEARCH_PATHS variable. In my case it finds FacebookSDK.framework but then generates linker errors for the rest of the frameworks included (eg UIKit, Foundation, etc.).

My solution was simply copying FacebookSDK.framework to the XCode frameworks folders. Bear in mind you need to copy it to both iPhoneOS and iPhoneSimulator if you build for device and simulator. Currently, XCode7 and SDK9.0, those folders are:

  • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks
  • /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/System/Library/Frameworks

Adding FacebookSDK.framework as usual works fine then:

SET (OUR_FRAMEWORKS "-framework Foundation -framework UIKit -framework FacebookSDK ...")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM