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