cmake_minimum_required(VERSION 3.8)

include(GNUInstallDirs)

#############################################
# audio_client
#############################################
add_library(audio_client SHARED
	audio_if.c
)

add_executable(halplay halplay.c)
add_executable(halpatch hal_patch.c)
add_executable(hal_dump hal_dump.c)
target_compile_options(audio_client PRIVATE -fPIC -Werror)
target_compile_options(halplay PRIVATE -D_GNU_SOURCE
	-Werror -Wno-error=incompatible-pointer-types -Wno-deprecated-declarations -funwind-tables -fasynchronous-unwind-tables -fPIC -g)
target_compile_options(halpatch PRIVATE -D_GNU_SOURCE
	-Werror -Wno-error=incompatible-pointer-types -Wno-deprecated-declarations -funwind-tables -fasynchronous-unwind-tables -fPIC -g)
target_compile_options(hal_dump PRIVATE -D_GNU_SOURCE
	-Werror -Wno-error=incompatible-pointer-types -Wno-deprecated-declarations -funwind-tables -fasynchronous-unwind-tables -fPIC -g)
target_include_directories(audio_client PRIVATE
	${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/audio_hal
    ${PROJECT_SOURCE_DIR}/../android_prebuild/usr/include/)

target_include_directories(halplay PRIVATE
	${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/../android_prebuild/usr/include/)
target_include_directories(halpatch PRIVATE
	${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/../android_prebuild/usr/include/)
target_include_directories(hal_dump PRIVATE
	${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/../android_prebuild/usr/include/)

target_link_options(audio_client PRIVATE "-Wl,-soname,libaudio_client.so")
target_link_libraries(halplay audio_client -L${PROJECT_SOURCE_DIR}/../android_prebuild/usr/lib/
	 -llog -ldl -lstdc++ -lm)
target_link_libraries(halpatch audio_client -L${PROJECT_SOURCE_DIR}/../android_prebuild/usr/lib/
	 -llog -ldl -lstdc++)
target_link_libraries(hal_dump audio_client -L${PROJECT_SOURCE_DIR}/../android_prebuild/usr/lib/
	 -llog -ldl -lstdc++)

install(TARGETS audio_client
	LIBRARY DESTINATION "lib")
install(TARGETS halplay
	RUNTIME DESTINATION "bin")
install(TARGETS halpatch
	RUNTIME DESTINATION "bin")
install(TARGETS hal_dump
	RUNTIME DESTINATION "bin")
install(FILES audio_if.h
	DESTINATION include)
