cmake_minimum_required (VERSION 3.0)

project (libubox)

set (CMAKE_MODULE_PATH "${MODULE_PATH}")

set(DISABLE_TARGET_OPTIMIZATION ON)

include (br)

ADD_DEFINITIONS(-DJSONC)

include_directories ($ENV{SRC_DIR}/src/3P/libubox/)

file (
	GLOB_RECURSE
	source_files
	
	$ENV{SRC_DIR}/src/3P/libubox/avl.c
	$ENV{SRC_DIR}/src/3P/libubox/avl-cmp.c
	$ENV{SRC_DIR}/src/3P/libubox/blob.c
	$ENV{SRC_DIR}/src/3P/libubox/blobmsg.c
	$ENV{SRC_DIR}/src/3P/libubox/uloop.c
	$ENV{SRC_DIR}/src/3P/libubox/usock.c
	$ENV{SRC_DIR}/src/3P/libubox/ustream.c
	$ENV{SRC_DIR}/src/3P/libubox/ustream-fd.c
	$ENV{SRC_DIR}/src/3P/libubox/vlist.c
	$ENV{SRC_DIR}/src/3P/libubox/utils.c
	$ENV{SRC_DIR}/src/3P/libubox/safe_list.c
	$ENV{SRC_DIR}/src/3P/libubox/runqueue.c
	$ENV{SRC_DIR}/src/3P/libubox/md5.c
	$ENV{SRC_DIR}/src/3P/libubox/kvlist.c
	$ENV{SRC_DIR}/src/3P/libubox/ulog.c 
	$ENV{SRC_DIR}/src/3Plibubox/base64.c
	)

add_library (ubox SHARED ${source_files})
target_link_libraries (ubox 
	LINK_PUBLIC
	json-c
	rt
	pthread
	)

target_include_directories (ubox PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})


file (GLOB ubox_headers $ENV{SRC_DIR}/src/3P/libubox/*.h)
install (FILES ${ubox_headers} DESTINATION include/libubox)

add_library (json_script SHARED $ENV{SRC_DIR}/src/3P/libubox/json_script.c)
target_link_libraries (json_script ubox)

add_library (blobmsg_json SHARED $ENV{SRC_DIR}/src/3P/libubox/blobmsg_json.c)
target_link_libraries (blobmsg_json json-c)

add_executable (jshn $ENV{SRC_DIR}/src/3P/libubox/jshn.c)
target_link_libraries (jshn ubox blobmsg_json json-c)

install (TARGETS ubox json_script blobmsg_json
	LIBRARY DESTINATION ../lib
)

install (TARGETS jshn RUNTIME DESTINATION bin)

install (FILES $ENV{SRC_DIR}/src/3P/libubox/sh/jshn.sh 
	 DESTINATION share/libubox)
