set(PlatformsApple_SRCS
    ASLog.hpp
    ASLog.cpp
    ApplePlatform.h
    ApplePlatform.mm
    AudioConverterDecoder.hpp
    AudioConverterDecoder.cpp
    AudioQueueRenderer.hpp
    AudioQueueRenderer.cpp
    CMSampleBufferSample.hpp
    CocoaHttpClient.h
    CocoaHttpClient.mm
    CocoaHttpRequest.h
    CocoaHttpRequest.mm
    CocoaHttpResponse.h
    CocoaHttpResponse.mm
    DisplayLayerRenderer.h
    DisplayLayerRenderer.mm
    VTDecoder.hpp
    VTDecoder.cpp
    TTVObserver.h
    TTVObserver.mm
    TTVPlayer.h
    TTVPlayer.mm
    TTVPlayerDelegate.h
    TTVPlayerLayer.h
    TTVPlayerLayer.mm
    TTVQuality.h
    TTVQuality.mm
    TTVURLSessionDelegate.h
    TTVURLSessionDelegate.mm
    ${PLAYER_LIB_INC}/platform/ios/IOSPlatform.hpp
)

#iOS only helper classes
set(PlatformsiOS_SRCS
    AVPlayerSink.h
    AVPlayerSink.mm
    TTVAVPlayerObserver.h
    TTVAVPlayerObserver.mm
    TTVLoopbackResourceLoaderDelegate.h
    TTVLoopbackResourceLoaderDelegate.mm
)

if(TARGET_PLATFORM STREQUAL "iPhone" OR TARGET_PLATFORM STREQUAL "AppleTV")
    set(PlatformsApple_SRCS ${PlatformsApple_SRCS} ${PlatformsiOS_SRCS})
endif()

add_library(playercore STATIC ${PlatformsApple_SRCS})
target_link_libraries(playercore mediaplayer)

if(TARGET_PLATFORM STREQUAL "iPhone" OR TARGET_PLATFORM STREQUAL "AppleTV")
    target_link_libraries(playercore gcdwebserver)
    target_link_libraries(playercore z)
endif()

###########################################################################
# Add PlayerCore framework
set(Framework_Sources TTVObserver.mm TTVPlayer.mm TTVPlayerLayer.mm TTVQuality.mm)
set(Framework_Public_Headers Framework/PlayerCore.h TTVObserver.h TTVPlayer.h TTVPlayerDelegate.h TTVPlayerLayer.h TTVQuality.h)
set_property(SOURCE Framework/module.modulemap PROPERTY MACOSX_PACKAGE_LOCATION "Modules")
add_library(PlayerCore SHARED "${Framework_Public_Headers}" "${Framework_Sources}" Framework/module.modulemap)
set_target_properties(PlayerCore PROPERTIES OUTPUT_NAME "PlayerCore")
target_include_directories(PlayerCore PUBLIC .)
target_link_libraries(PlayerCore
    playercore
    "-framework AudioToolbox"
    "-framework AVFoundation"
    "-framework CoreGraphics"
    "-framework CoreMedia"
    "-framework Foundation"
    "-framework QuartzCore"
    "-framework VideoToolbox"
    "-framework CFNetwork"
)
if(TARGET_PLATFORM STREQUAL "iPhone" OR TARGET_PLATFORM STREQUAL "AppleTV")
    target_link_libraries(PlayerCore "-framework UIKit" "-framework MobileCoreServices")
elseif(TARGET_PLATFORM STREQUAL "OSX")
    target_link_libraries(PlayerCore "-framework AppKit" "-framework SystemConfiguration")
endif()

set_target_properties(PlayerCore PROPERTIES
    FRAMEWORK TRUE
    VERSION "${PROJECT_VERSION}"
    SOVERSION "${PROJECT_VERSION}"
    FRAMEWORK_VERSION "A"
    MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Framework/Info.plist"
    MACOSX_FRAMEWORK_BUNDLE_VERSION "${PROJECT_VERSION}"
    MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${PROJECT_VERSION}"
    PUBLIC_HEADER "${Framework_Public_Headers}"
    XCODE_ATTRIBUTE_INSTALL_PATH @executable_path/Frameworks
)
