cmake_minimum_required (VERSION 3.0)

project (uhttpd)

ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -Os -Wall -Wmissing-declarations --std=gnu99 -g3)

set (CMAKE_MODULE_PATH "${MODULE_PATH}")

set(DISABLE_TARGET_OPTIMIZATION ON)

include (br)

include_directories (${workspaceRoot}/src/3P/uhttpd/)

# uhttpd
add_executable (uhttpd

	${workspaceRoot}/src/3P/uhttpd/main.c
	${workspaceRoot}/src/3P/uhttpd/listen.c
	${workspaceRoot}/src/3P/uhttpd/client.c
	${workspaceRoot}/src/3P/uhttpd/utils.c
	${workspaceRoot}/src/3P/uhttpd/file.c
	${workspaceRoot}/src/3P/uhttpd/auth.c
	${workspaceRoot}/src/3P/uhttpd/cgi.c
	${workspaceRoot}/src/3P/uhttpd/relay.c
	${workspaceRoot}/src/3P/uhttpd/proc.c
	${workspaceRoot}/src/3P/uhttpd/plugin.c
	${workspaceRoot}/src/3P/uhttpd/handler.c
)

if (REST_API_PLUGING)
	add_definitions (-DHAVE_REST_API_PLUGING)
endif ()

IF (UBUS_SUPPORT)
	ADD_DEFINITIONS (-DHAVE_UBUS)
	ADD_LIBRARY (uhttpd_ubus MODULE
		${workspaceRoot}/src/3P/uhttpd/ubus.c
	)
	TARGET_LINK_LIBRARIES (uhttpd_ubus ubus ubox blobmsg_json json-c)
	SET_TARGET_PROPERTIES (uhttpd_ubus PROPERTIES PREFIX "")
	INSTALL (TARGETS uhttpd_ubus LIBRARY DESTINATION local/lib/)
ENDIF ()

target_link_libraries (uhttpd ubox dl json_script blobmsg_json json-c crypt)

install (TARGETS uhttpd DESTINATION local/bin)

file (GLOB headers ${workspaceRoot}/src/3P/uhttpd/*.h)
install (FILES ${headers} DESTINATION include/uhttpd)
