cmake_minimum_required (VERSION 3.0)

project (uhttpd-rest-api-plugin)

set (CMAKE_MODULE_PATH "${MODULE_PATH}")
set (CMAKE_CXX_STANDARD 11)

include (br)

include_directories (${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/)

file (
	GLOB_RECURSE
	source_files

	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/plugin.c
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/uhttp-server.cpp
	# core
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-reason.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-parameter.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/http-header.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/uri-transform.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/web-controller.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/web-connection.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-connection.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/core/ubus-reason.cpp
	# rest
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/ubus.cpp	
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-controller.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/rest/rest-connection.cpp
	#etag-rest
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-controller.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/etag-rest/etag-rest-connection.cpp
	# notification
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-controller.cpp
	${workspaceRoot}/src/plugins/uhttpd/uhttpd-rest-api/notification/notification-connection.cpp
	)

add_library (rest-api-plugin SHARED ${source_files})

target_link_libraries (rest-api-plugin
	LINK_PUBLIC
	ubus
	ubox
	blobmsg_json
	json-c
	fmt
	ubus-cpp
)

set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")

set_target_properties (rest-api-plugin PROPERTIES PREFIX "uhttpd_")

target_include_directories (rest-api-plugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

install (TARGETS rest-api-plugin LIBRARY DESTINATION local/bin/plugins/)
