summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 8514351b98a3c1540ac454c22dbd2e8230ef2f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
cmake_minimum_required(VERSION 2.6)

PROJECT(uhttpd C)

INCLUDE (CheckFunctionExists)

SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 -Os -Wall -Werror -Wmissing-declarations --std=gnu99 -g3)

OPTION(TLS_SUPPORT "TLS support" ON)
OPTION(LUA_SUPPORT "Lua support" ON)
OPTION(UBUS_SUPPORT "ubus support" ON)

IF(APPLE)
  INCLUDE_DIRECTORIES(/opt/local/include)
  LINK_DIRECTORIES(/opt/local/lib)
ENDIF()

FIND_LIBRARY(LIBS crypt)
IF(LIBS STREQUAL "LIBS-NOTFOUND")
	SET(LIBS "")
ENDIF()

SET(SOURCES main.c listen.c client.c utils.c file.c auth.c cgi.c relay.c proc.c plugin.c handler.c)
IF(TLS_SUPPORT)
	SET(SOURCES ${SOURCES} tls.c)
	ADD_DEFINITIONS(-DHAVE_TLS)
ENDIF()

CHECK_FUNCTION_EXISTS(getspnam HAVE_SHADOW)
IF(HAVE_SHADOW)
    ADD_DEFINITIONS(-DHAVE_SHADOW)
ENDIF()

ADD_EXECUTABLE(uhttpd ${SOURCES})
FIND_LIBRARY(libjson NAMES json-c json)
TARGET_LINK_LIBRARIES(uhttpd ubox dl json_script blobmsg_json ${libjson} ${LIBS})

SET(PLUGINS "")
IF(LUA_SUPPORT)
	FIND_PROGRAM(PKG_CONFIG pkg-config)

	IF(NOT LUA_CFLAGS AND PKG_CONFIG)
		EXECUTE_PROCESS(
			COMMAND pkg-config --silence-errors --cflags lua5.1
			OUTPUT_VARIABLE LUA_CFLAGS
			OUTPUT_STRIP_TRAILING_WHITESPACE
		)
	ENDIF()

	IF(NOT LUA_LIBS AND PKG_CONFIG)
		EXECUTE_PROCESS(
			COMMAND pkg-config --silence-errors --libs lua5.1
			OUTPUT_VARIABLE LUA_LIBS
			OUTPUT_STRIP_TRAILING_WHITESPACE
		)
	ENDIF()

	IF(NOT LUA_LIBS)
		SET(LUA_LIBS "lua")
	ENDIF()

	SET(PLUGINS ${PLUGINS} uhttpd_lua)
	ADD_DEFINITIONS(-DHAVE_LUA ${LUA_CFLAGS})
	ADD_LIBRARY(uhttpd_lua MODULE lua.c)
	TARGET_LINK_LIBRARIES(uhttpd_lua ${LUA_LIBS} m dl)
ENDIF()

IF(UBUS_SUPPORT)
	SET(PLUGINS ${PLUGINS} uhttpd_ubus)
	ADD_DEFINITIONS(-DHAVE_UBUS)
	ADD_LIBRARY(uhttpd_ubus MODULE ubus.c)
	TARGET_LINK_LIBRARIES(uhttpd_ubus ubus ubox blobmsg_json ${libjson})
ENDIF()

IF(PLUGINS)
	SET_TARGET_PROPERTIES(${PLUGINS} PROPERTIES
		PREFIX ""
	)
ENDIF()

INSTALL(TARGETS uhttpd ${PLUGINS}
	RUNTIME DESTINATION bin
	LIBRARY DESTINATION lib
)