cmake_minimum_required(VERSION 3.0)

project (uci)

set (CMAKE_MODULE_PATH "${MODULE_PATH}")

set(DISABLE_TARGET_OPTIMIZATION ON)

include (br)

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

ADD_DEFINITIONS (-Werror --std=gnu99 -Wmissing-declarations)

CONFIGURE_FILE ($ENV{SRC_DIR}/src/3P/uci/uci_config.h.in $ENV{SRC_DIR}/src/3P/uci/uci_config.h)

# uci library
file (
	GLOB_RECURSE
	lib_source_files
	
	$ENV{SRC_DIR}/src/3P/uci/libuci.c
	$ENV{SRC_DIR}/src/3P/uci/file.c
	$ENV{SRC_DIR}/src/3P/uci/util.c
	$ENV{SRC_DIR}/src/3P/uci/delta.c
	$ENV{SRC_DIR}/src/3P/uci/parse.c
	$ENV{SRC_DIR}/src/3P/uci/blob.c
)

# Library
add_library (uci SHARED ${lib_source_files})
target_link_libraries (uci LINK_PUBLIC ubox)

target_include_directories (uci PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

install (TARGETS uci LIBRARY DESTINATION local/lib)

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


# cmd line tool.
add_executable (uci_cli $ENV{SRC_DIR}/src/3P/uci/cli.c)
set_target_properties (uci_cli PROPERTIES OUTPUT_NAME uci)
target_link_libraries (uci_cli LINK_PUBLIC uci ubox blobmsg_json)

install (TARGETS uci_cli RUNTIME DESTINATION ../sbin)
