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