• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 2.8)
2include(CheckCSourceCompiles)
3
4set(SAMP lws-minimal-mqtt-client-multi)
5set(SRCS minimal-mqtt-client-multi.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
62	endif()
63ENDMACRO()
64
65
66set(requirements 1)
67require_lws_config(LWS_ROLE_MQTT 1 requirements)
68require_lws_config(LWS_WITH_CLIENT 1 requirements)
69
70if (requirements)
71	add_executable(${SAMP} ${SRCS})
72
73	if (websockets_shared)
74		target_link_libraries(${SAMP} websockets_shared)
75		add_dependencies(${SAMP} websockets_shared)
76	else()
77		target_link_libraries(${SAMP} websockets)
78	endif()
79endif()
80