protobuf_generate_cpp(ADB_APP_PROCESSES_PROTO_SRCS ADB_APP_PROCESSES_PROTO_HDRS
	adb/proto/app_processes.proto)
protobuf_generate_cpp(ADB_KEY_TYPE_PROTO_SRCS ADB_KEY_TYPE_PROTO_HDRS
	adb/proto/key_type.proto)
protobuf_generate_cpp(ADB_KNOWN_HOSTS_PROTO_SRCS ADB_KNOWN_HOSTS_PROTO_HDRS
	adb/proto/adb_known_hosts.proto)
protobuf_generate_cpp(ADB_PAIRING_PROTO_SRCS ADB_PAIRING_PROTO_HDRS
	adb/proto/pairing.proto)

# No fastdeploy because it requires deployagent.inc
set(libadb_SOURCES
	adb/client/adb_client.cpp
	adb/client/adb_install.cpp
	adb/client/adb_wifi.cpp
	adb/client/auth.cpp
	adb/client/bugreport.cpp
	adb/client/commandline.cpp
	adb/client/console.cpp
	adb/client/file_sync_client.cpp
	adb/client/incremental.cpp
	adb/client/incremental_server.cpp
	adb/client/incremental_utils.cpp
	adb/client/line_printer.cpp
	adb/client/main.cpp
	adb/client/pairing/pairing_client.cpp
	adb/client/usb_libusb.cpp
	adb/pairing_auth/aes_128_gcm.cpp
	adb/pairing_auth/pairing_auth.cpp
	adb/pairing_connection/pairing_connection.cpp
	adb/services.cpp
	adb/socket_spec.cpp
	adb/sysdeps_unix.cpp
	adb/sysdeps/errno.cpp
	adb/sysdeps/posix/network.cpp
	${ADB_APP_PROCESSES_PROTO_SRCS} ${ADB_APP_PROCESSES_PROTO_HDRS}
	${ADB_KNOWN_HOSTS_PROTO_SRCS} ${ADB_KNOWN_HOSTS_PROTO_HDRS}
	${ADB_KEY_TYPE_PROTO_SRCS} ${ADB_KEY_TYPE_PROTO_HDRS}
	${ADB_PAIRING_PROTO_SRCS} ${ADB_PAIRING_PROTO_HDRS})

if(APPLE)
	list(APPEND libadb_SOURCES
		adb/client/usb_osx.cpp)
else()
	list(APPEND libadb_SOURCES
		adb/client/usb_linux.cpp)
endif()

add_library(libadb STATIC ${libadb_SOURCES})
target_compile_definitions(libadb PRIVATE -D_GNU_SOURCE)
target_compile_definitions(libadb PUBLIC -DADB_HOST=1)
target_include_directories(libadb PUBLIC
	base/libs/androidfw/include
	boringssl/include
	adb
	adb/crypto/include
	adb/pairing_auth/include
	adb/pairing_connection/include
	adb/tls/include
	core/include
	core/libcrypto_utils/include
	core/libcutils/include
	libbase/include
	libziparchive/include
	native/include)

add_library(libadb_crypto_defaults STATIC
	adb/crypto/key.cpp
	adb/crypto/rsa_2048_key.cpp
	adb/crypto/x509_generator.cpp
	${ADB_KEY_TYPE_PROTO_HDRS})

target_include_directories(libadb_crypto_defaults PUBLIC
	adb
	adb/crypto/include
	boringssl/include
	core/libcrypto_utils/include
	libbase/include)


add_library(libadb_tls_connection_defaults STATIC
	adb/tls/adb_ca_list.cpp
	adb/tls/tls_connection.cpp)

target_include_directories(libadb_tls_connection_defaults PUBLIC
	adb
	adb/tls/include
	boringssl/include
	libbase/include)

add_library(liblog STATIC
	logging/liblog/log_event_list.cpp
	logging/liblog/log_event_write.cpp
	logging/liblog/logger_name.cpp
	logging/liblog/logger_read.cpp
	logging/liblog/logger_write.cpp
	logging/liblog/properties.cpp
	logging/liblog/logprint.cpp)

target_compile_definitions(liblog PRIVATE
	-DLIBLOG_LOG_TAG=1006 -D_XOPEN_SOURCE=700 -DFAKE_LOG_DEVICE=1)
target_include_directories(liblog PUBLIC
	core/include
	logging/liblog/include
	core/libcutils/include
	libbase/include)

add_library(libcutils STATIC
	core/libcutils/android_get_control_file.cpp
	core/libcutils/ashmem-host.cpp
	core/libcutils/canned_fs_config.cpp
	core/libcutils/config_utils.cpp
	core/libcutils/fs.cpp
	core/libcutils/fs_config.cpp
	core/libcutils/hashmap.cpp
	core/libcutils/iosched_policy.cpp
	core/libcutils/load_file.cpp
	core/libcutils/multiuser.cpp
	core/libcutils/native_handle.cpp
	core/libcutils/properties.cpp
	core/libcutils/record_stream.cpp
	core/libcutils/socket_inaddr_any_server_unix.cpp
	core/libcutils/socket_local_client_unix.cpp
	core/libcutils/socket_local_server_unix.cpp
	core/libcutils/socket_network_client_unix.cpp
	core/libcutils/sockets_unix.cpp
	core/libcutils/sockets.cpp
	core/libcutils/str_parms.cpp
	core/libcutils/strlcpy.c
	core/libcutils/trace-host.cpp
	core/libcutils/threads.cpp)

target_compile_definitions(libcutils PRIVATE -D_GNU_SOURCE)
target_include_directories(libcutils PRIVATE
	logging/liblog/include core/libutils/include)
target_include_directories(libcutils PUBLIC
	core/libcutils/include libbase/include)

add_library(libdiagnoseusb STATIC
	core/diagnose_usb/diagnose_usb.cpp)
target_include_directories(libdiagnoseusb PUBLIC
	core/diagnose_usb/include)

target_include_directories(libdiagnoseusb PUBLIC
	core/include libbase/include)

add_library(libadb_sysdeps STATIC
	adb/sysdeps/env.cpp)
target_include_directories(libadb_sysdeps PUBLIC
	libbase/include
	adb)

add_library(libcrypto STATIC
	core/libcrypto_utils/android_pubkey.cpp)

target_include_directories(libcrypto PUBLIC
	core/libcrypto_utils/include boringssl/include)

add_executable(adb
	  adb/adb.cpp
	  adb/adb_io.cpp
	  adb/adb_listeners.cpp
	  adb/adb_trace.cpp
	  adb/adb_unique_fd.cpp
	  adb/adb_utils.cpp
	  adb/fdevent/fdevent.cpp
	  adb/fdevent/fdevent_poll.cpp
	  adb/fdevent/fdevent_epoll.cpp
	  adb/shell_service_protocol.cpp
	  adb/sockets.cpp
	  adb/socket_spec.cpp
	  adb/transport.cpp
	  adb/transport_fd.cpp
	  adb/client/transport_local.cpp
	  adb/client/transport_usb.cpp
	  adb/types.cpp
	  ${ADB_KEY_TYPE_PROTO_HDRS})

target_include_directories(adb PRIVATE
	core/include libbase/include adb
	core/libcrypto_utils/include boringssl/include)
target_link_libraries(adb
	libadb
	libadb_crypto_defaults
	libadb_tls_connection_defaults
	libbase
	libcrypto
	libadb_sysdeps
	libcutils
	libdiagnoseusb
	liblog
	libzip
	crypto
	ssl
	${PROTOBUF_LIBRARIES}
	PkgConfig::libbrotlicommon
	PkgConfig::libbrotlidec
	PkgConfig::libbrotlienc
	PkgConfig::liblz4
	Threads::Threads
	PkgConfig::libusb-1.0
	z
	PkgConfig::libzstd)

if(APPLE)
	target_link_libraries(adb
		"-framework CoreFoundation"
		"-framework IOKit")
endif()
