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