1project(lws-minimal-raw-proxy-fallback)
2cmake_minimum_required(VERSION 2.8)
3include(CheckCSourceCompiles)
4
5set(SAMP lws-minimal-raw-proxy-fallback)
6set(SRCS minimal-raw-proxy-fallback.c)
7
8# NOTE... if you are building this standalone, you must point LWS_PLUGINS_DIR
9# to the lws plugins dir so it can pick up the plugin source.  Eg,
10# cmake . -DLWS_PLUGINS_DIR=~/libwebsockets/plugins
11
12# If we are being built as part of lws, confirm current build config supports
13# reqconfig, else skip building ourselves.
14#
15# If we are being built externally, confirm installed lws was configured to
16# support reqconfig, else error out with a helpful message about the problem.
17#
18MACRO(require_lws_config reqconfig _val result)
19
20	if (DEFINED ${reqconfig})
21	if (${reqconfig})
22		set (rq 1)
23	else()
24		set (rq 0)
25	endif()
26	else()
27		set(rq 0)
28	endif()
29
30	if (${_val} EQUAL ${rq})
31		set(SAME 1)
32	else()
33		set(SAME 0)
34	endif()
35
36	if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME})
37		if (${_val})
38			message("${SAMP}: skipping as lws being built without ${reqconfig}")
39		else()
40			message("${SAMP}: skipping as lws built with ${reqconfig}")
41		endif()
42		set(${result} 0)
43	else()
44		if (LWS_WITH_MINIMAL_EXAMPLES)
45			set(MET ${SAME})
46		else()
47			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})
48			if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig})
49				set(HAS_${reqconfig} 0)
50			else()
51				set(HAS_${reqconfig} 1)
52			endif()
53			if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val}))
54				set(MET 1)
55			else()
56				set(MET 0)
57			endif()
58		endif()
59		if (NOT MET)
60			if (${_val})
61				message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}")
62			else()
63				message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project")
64			endif()
65		endif()
66	endif()
67ENDMACRO()
68
69set(requirements 1)
70require_lws_config(LWS_ROLE_RAW_PROXY 1 requirements)
71
72if (requirements)
73	add_executable(${SAMP} ${SRCS})
74
75	if (LWS_PLUGINS_DIR)
76		include_directories(${LWS_PLUGINS_DIR})
77	endif()
78
79	if (websockets_shared)
80		target_link_libraries(${SAMP} websockets_shared)
81		add_dependencies(${SAMP} websockets_shared)
82	else()
83		target_link_libraries(${SAMP} websockets)
84	endif()
85endif()
86