• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1project(lws-minimal-http-server)
2cmake_minimum_required(VERSION 2.8)
3include(CheckCSourceCompiles)
4
5set(SAMP lws-minimal-http-server)
6set(SRCS minimal-http-server.c)
7
8# If we are being built as part of lws, confirm current build config supports
9# reqconfig, else skip building ourselves.
10#
11# If we are being built externally, confirm installed lws was configured to
12# support reqconfig, else error out with a helpful message about the problem.
13#
14MACRO(require_lws_config reqconfig _val result)
15
16	if (DEFINED ${reqconfig})
17	if (${reqconfig})
18		set (rq 1)
19	else()
20		set (rq 0)
21	endif()
22	else()
23		set(rq 0)
24	endif()
25
26	if (${_val} EQUAL ${rq})
27		set(SAME 1)
28	else()
29		set(SAME 0)
30	endif()
31
32	if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME})
33		if (${_val})
34			message("${SAMP}: skipping as lws being built without ${reqconfig}")
35		else()
36			message("${SAMP}: skipping as lws built with ${reqconfig}")
37		endif()
38		set(${result} 0)
39	else()
40		if (LWS_WITH_MINIMAL_EXAMPLES)
41			set(MET ${SAME})
42		else()
43			CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig})
44			if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig})
45				set(HAS_${reqconfig} 0)
46			else()
47				set(HAS_${reqconfig} 1)
48			endif()
49			if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val}))
50				set(MET 1)
51			else()
52				set(MET 0)
53			endif()
54		endif()
55		if (NOT MET)
56			if (${_val})
57				message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}")
58			else()
59				message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project")
60			endif()
61		endif()
62
63	endif()
64ENDMACRO()
65
66
67set(requirements 1)
68require_lws_config(LWS_ROLE_H1 1 requirements)
69require_lws_config(LWS_WITH_SERVER 1 requirements)
70
71if (requirements)
72	add_executable(${SAMP} ${SRCS})
73
74	if (websockets_shared)
75		target_link_libraries(${SAMP} websockets_shared)
76		add_dependencies(${SAMP} websockets_shared)
77	else()
78		target_link_libraries(${SAMP} websockets)
79	endif()
80endif()