Imported Upstream version 3.2.0
[platform/upstream/libwebsockets.git] / minimal-examples / crypto / minimal-crypto-jwe / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2 include(CheckCSourceCompiles)
3
4 set(SAMP lws-crypto-jwe)
5 set(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 #
13 MACRO(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()
62 ENDMACRO()
63
64 set(requirements 1)
65 require_lws_config(LWS_WITH_JOSE 1 requirements)
66
67 if (requirements)
68
69         add_executable(${SAMP} ${SRCS})
70
71         if (websockets_shared)
72                 target_link_libraries(${SAMP} websockets_shared)
73                 add_dependencies(${SAMP} websockets_shared)
74         else()
75                 target_link_libraries(${SAMP} websockets)
76         endif()
77 endif()