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