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