Imported Upstream version 3.2.0
[platform/upstream/libwebsockets.git] / minimal-examples / dbus-client / minimal-dbus-client / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2 include(CheckCSourceCompiles)
3 include(CheckLibraryExists)
4
5 set(SAMP lws-minimal-dbus-client)
6 set(SRCS minimal-dbus-client.c)
7
8 if (NOT LWS_WITH_MINIMAL_EXAMPLES)
9         CHECK_LIBRARY_EXISTS(dbus-1 dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS)
10         if (NOT LWS_HAVE_LIBDBUS)
11                 message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc")
12         endif()
13
14         if (NOT LWS_DBUS_LIB)
15                 set(LWS_DBUS_LIB "dbus-1")
16         endif()
17
18         if (NOT LWS_DBUS_INCLUDE1)
19                 # look in fedora and debian / ubuntu place
20                 if (EXISTS "/usr/include/dbus-1.0")
21                         set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0")
22                 else()
23                         message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are")
24                 endif()
25         endif()
26
27         if (NOT LWS_DBUS_INCLUDE2)
28                 # look in fedora... debian / ubuntu has the ARCH in the path...
29                 if (EXISTS "/usr/lib64/dbus-1.0/include")
30                         set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include")
31                 else()
32                         message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system")
33                 endif()
34         endif()
35
36         set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2})
37
38         if (NOT LWS_DBUS_INCLUDE1 OR NOT LWS_DBUS_INCLUDE2)
39                 message(FATAL_ERROR "To build with libdbus, LWS_DBUS_INCLUDE1/2 must be given. See lib/roles/dbus/README.md")
40         endif()
41
42 endif()
43
44 # If we are being built as part of lws, confirm current build config supports
45 # reqconfig, else skip building ourselves.
46 #
47 # If we are being built externally, confirm installed lws was configured to
48 # support reqconfig, else error out with a helpful message about the problem.
49 #
50 MACRO(require_lws_config reqconfig _val result)
51
52         if (DEFINED ${reqconfig})
53         if (${reqconfig})
54                 set (rq 1)
55         else()
56                 set (rq 0)
57         endif()
58         else()
59                 set(rq 0)
60         endif()
61
62         if (${_val} EQUAL ${rq})
63                 set(SAME 1)
64         else()
65                 set(SAME 0)
66         endif()
67
68         if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME})
69                 if (${_val})
70                         message("${SAMP}: skipping as lws being built without ${reqconfig}")
71                 else()
72                         message("${SAMP}: skipping as lws built with ${reqconfig}")
73                 endif()
74                 set(${result} 0)
75         else()
76                 if (LWS_WITH_MINIMAL_EXAMPLES)
77                         set(MET ${SAME})
78                 else()
79                         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})
80                         if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig})
81                                 set(HAS_${reqconfig} 0)
82                         else()
83                                 set(HAS_${reqconfig} 1)
84                         endif()
85                         if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val}))
86                                 set(MET 1)
87                         else()
88                                 set(MET 0)
89                         endif()
90                 endif()
91                 if (NOT MET)
92                         if (${_val})
93                                 message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}")
94                         else()
95                                 message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project")
96                         endif()
97                 endif()
98
99         endif()
100 ENDMACRO()
101
102
103 set(requirements 1)
104 require_lws_config(LWS_ROLE_DBUS 1 requirements)
105 require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
106
107 if (requirements)
108         add_executable(${SAMP} ${SRCS})
109         
110         include_directories("${LWS_DBUS_INCLUDE1}")
111         include_directories("${LWS_DBUS_INCLUDE2}")
112         list(APPEND LIB_LIST dbus-1)
113
114         if (websockets_shared)
115                 target_link_libraries(${SAMP} websockets_shared)
116                 add_dependencies(${SAMP} websockets_shared ${LWS_DBUS_LIB})
117         else()
118                 target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB})
119         endif()
120 endif()