# libbinder_headers_base

add_library(libbinder_headers_base INTERFACE)
add_library(android::libbinder_headers_base ALIAS libbinder_headers_base)

set(libbinder_headers_base_INCLUDES
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/include
)
target_include_directories(libbinder_headers_base INTERFACE ${libbinder_headers_base_INCLUDES})

set(libbinder_headers_base_DEPENDENCIES
    android::libbinder_headers_platform_shared
)
target_link_libraries(libbinder_headers_base INTERFACE ${libbinder_headers_base_DEPENDENCIES})


# libbinder_sdk

set(libbinder_sdk_SRCS
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Binder.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/BpBinder.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Debug.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/FdTrigger.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/IInterface.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/IResultReceiver.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Parcel.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/ParcelFileDescriptor.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RecordedTransaction.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcSession.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcServer.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcState.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcTransportRaw.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Stability.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Status.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/TextOutput.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Utils.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/file.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/OS_non_android_linux.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/OS_unix_base.cpp
)
add_library(libbinder_sdk ${libbinder_sdk_SRCS})
add_library(android::libbinder_sdk ALIAS libbinder_sdk)

set(libbinder_sdk_CFLAGS
    -DBINDER_ENABLE_LIBLOG_ASSERT
    -DBINDER_DISABLE_NATIVE_HANDLE
    -DBINDER_DISABLE_BLOB
    -DBINDER_NO_LIBBASE
    -DLIBBINDER_DEFER_BC_REQUEST_FREEZE_NOTIFICATION
    -DLIBBINDER_BPBINDER_DECSTRONG_LAST
    -Wextra
    -Wextra-semi
    -Werror
    -Wzero-as-null-pointer-constant
    -Wunused-result
    -Wexit-time-destructors
    -Wshadow
    -DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION
    -DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION
    -fvisibility=hidden
    -DBUILDING_LIBBINDER
    -DNO_LIBBINDER_BINDER_OBSERVER
)
append_cxx_flags_if_supported(libbinder_sdk_CFLAGS
    -Wreorder-init-list
)
target_compile_options(libbinder_sdk PRIVATE ${libbinder_sdk_CFLAGS})

set(libbinder_sdk_DEPENDENCIES
    android::libbinder_headers_base
    android::liblog_stub
    android::libutils_binder_sdk
)
target_link_libraries(libbinder_sdk ${libbinder_sdk_DEPENDENCIES})


# libbinder_sdk_single_threaded

set(libbinder_sdk_single_threaded_SRCS
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Binder.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/BpBinder.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Debug.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/FdTrigger.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/IInterface.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/IResultReceiver.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Parcel.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/ParcelFileDescriptor.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RecordedTransaction.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcSession.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcServer.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcState.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcTransportRaw.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Stability.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Status.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/TextOutput.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/Utils.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/file.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/OS_non_android_linux.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/OS_unix_base.cpp
)
add_library(libbinder_sdk_single_threaded ${libbinder_sdk_single_threaded_SRCS})
add_library(android::libbinder_sdk_single_threaded ALIAS libbinder_sdk_single_threaded)

set(libbinder_sdk_single_threaded_CFLAGS
    -DBINDER_ENABLE_LIBLOG_ASSERT
    -DBINDER_DISABLE_NATIVE_HANDLE
    -DBINDER_DISABLE_BLOB
    -DBINDER_NO_LIBBASE
    -DLIBBINDER_DEFER_BC_REQUEST_FREEZE_NOTIFICATION
    -DLIBBINDER_BPBINDER_DECSTRONG_LAST
    -Wextra
    -Wextra-semi
    -Werror
    -Wzero-as-null-pointer-constant
    -Wunused-result
    -Wexit-time-destructors
    -Wshadow
    -DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION
    -DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION
    -fvisibility=hidden
    -DBUILDING_LIBBINDER
    -DNO_LIBBINDER_BINDER_OBSERVER
    -DBINDER_RPC_SINGLE_THREADED
)
append_cxx_flags_if_supported(libbinder_sdk_single_threaded_CFLAGS
    -Wreorder-init-list
)
target_compile_options(libbinder_sdk_single_threaded PRIVATE ${libbinder_sdk_single_threaded_CFLAGS})

set(libbinder_sdk_single_threaded_DEPENDENCIES
    android::libbinder_headers_base
    android::liblog_stub
    android::libutils_binder_sdk
)
target_link_libraries(libbinder_sdk_single_threaded ${libbinder_sdk_single_threaded_DEPENDENCIES})


# libbinder_tls_static

set(libbinder_tls_static_SRCS
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcTransportTls.cpp
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/RpcTlsUtils.cpp
)
add_library(libbinder_tls_static ${libbinder_tls_static_SRCS})
add_library(android::libbinder_tls_static ALIAS libbinder_tls_static)

set(libbinder_tls_static_INCLUDES
    ${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/include_tls
)
target_include_directories(libbinder_tls_static PUBLIC ${libbinder_tls_static_INCLUDES})

set(libbinder_tls_static_DEPENDENCIES
    android::libbinder_headers_base
    android::libbinder_sdk
    android::liblog_stub
    crypto
    ssl
)
target_link_libraries(libbinder_tls_static ${libbinder_tls_static_DEPENDENCIES})
