• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1project(lws-minimal-http-server-eventlib-foreign C)
2cmake_minimum_required(VERSION 2.8.12)
3find_package(libwebsockets CONFIG REQUIRED)
4list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR})
5include(CheckIncludeFile)
6include(CheckCSourceCompiles)
7include(LwsCheckRequirements)
8
9set(SAMP lws-minimal-http-server-eventlib-foreign)
10set(SRCS minimal-http-server-eventlib-foreign.c)
11
12set(requirements 1)
13require_pthreads(requirements)
14require_lws_config(LWS_ROLE_H1 1 requirements)
15require_lws_config(LWS_WITH_SERVER 1 requirements)
16require_lws_config(LWS_WITH_TLS 1 requirements)
17
18CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBUV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBUV)
19CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBEVENT)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEVENT)
20CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBEV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEV)
21CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_GLIB)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_GLIB)
22CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_SDEVENT)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_SDEVENT)
23CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_ULOOP)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_ULOOP)
24
25if (LWS_WITH_LIBUV)
26	find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
27	find_library(LIBUV_LIBRARIES NAMES uv)
28	message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
29	message("libuv libraries: ${LIBUV_LIBRARIES}")
30	include_directories("${LIBUV_INCLUDE_DIRS}")
31	set(extralibs ${extralibs} ${LIBUV_LIBRARIES})
32	list(APPEND SRCS libuv.c)
33endif()
34if (LWS_WITH_LIBEVENT)
35	find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h)
36	find_library(LIBEVENT_LIBRARIES NAMES event)
37	message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}")
38	message("libevent libraries: ${LIBEVENT_LIBRARIES}")
39	include_directories("${LIBEVENT_INCLUDE_DIRS}")
40	set(extralibs ${extralibs} ${LIBEVENT_LIBRARIES})
41	list(APPEND SRCS libevent.c)
42endif()
43if (LWS_WITH_LIBEV)
44	find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
45	find_library(LIBEV_LIBRARIES NAMES ev)
46	message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
47	message("libev libraries: ${LIBEV_LIBRARIES}")
48	include_directories("${LIBEV_INCLUDE_DIRS}")
49	set(extralibs ${extralibs} ${LIBEV_LIBRARIES})
50	list(APPEND SRCS libev.c)
51endif()
52if (LWS_WITH_GLIB)
53	set(LWS_GLIB_INCLUDE_DIRS CACHE PATH "Path to the glib include directory")
54	set(LWS_GLIB_LIBRARIES CACHE PATH "Path to the glib library")
55		include (FindPkgConfig)
56	if (NOT GLIB_FOUND)
57		find_path(GLIB_INCLUDE_DIRS NAMES glib-2.0/glib.h)
58		find_library(GLIB_LIBRARIES NAMES glib-2.0)
59		if(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES)
60			set(GLIB_FOUND 1)
61		endif()
62		if (GLIB_INCLUDE_DIRS)
63			set(GLIB_INCLUDE_DIRS "${GLIB_INCLUDE_DIRS}/glib-2.0")
64		endif()
65	endif()
66	PKG_SEARCH_MODULE(LWS_GLIB2 glib-2.0)
67	if (LWS_GLIB2_FOUND)
68		list(APPEND GLIB_INCLUDE_DIRS "${LWS_GLIB2_INCLUDE_DIRS}")
69	endif()
70	message("glib include dir: ${GLIB_INCLUDE_DIRS}")
71	message("glib libraries: ${GLIB_LIBRARIES}")
72	include_directories("${GLIB_INCLUDE_DIRS}")
73	set(extralibs ${extralibs} ${GLIB_LIBRARIES})
74	list(APPEND SRCS glib.c)
75endif()
76if (LWS_WITH_SDEVENT)
77	find_path(LIBSYSTEMD_INCLUDE_DIRS NAMES systemd/sd-event.h)
78	find_library(LIBSYSTEMD_LIBRARIES NAMES systemd)
79	message("libsystemd include dir: ${LIBSYSTEMD_INCLUDE_DIRS}")
80	message("libsystemd libraries: ${LIBSYSTEMD_LIBRARIES}")
81	include_directories("${LIBSYSTEMD_INCLUDE_DIRS}")
82	set(extralibs ${extralibs} ${LIBSYSTEMD_LIBRARIES})
83	list(APPEND SRCS libsdevent.c)
84endif()
85if (LWS_WITH_ULOOP)
86	find_path(LIBUBOX_INCLUDE_DIRS NAMES libubox/uloop.h)
87	find_library(LIBUBOX_LIBRARIES NAMES ubox)
88	message("libubox include dir: ${LIBUBOX_INCLUDE_DIRS}")
89	message("libubox libraries: ${LIBUBOX_LIBRARIES}")
90	include_directories("${LIBUBOX_INCLUDE_DIRS}")
91	set(extralibs ${extralibs} ${LIBUBOX_LIBRARIES})
92	list(APPEND SRCS uloop.c)
93endif()
94
95message("Extra libs: ${extralibs}")
96
97if (NOT LWS_WITH_LIBUV AND NOT LWS_WITH_LIBEVENT AND NOT LWS_WITH_LIBEV AND NOT LWS_WITH_GLIB AND NOT LWS_WITH_ULOOP)
98	set(requirements 0)
99endif()
100
101if (requirements)
102	add_executable(${SAMP} ${SRCS})
103
104	#
105	# tests are running in the same machine context in parallel so they
106	# compete for the same ports.  Select a base port from which sai
107	# instance we are running in, add another digit at the actual test
108	# according to which subtest it is.  Then there can be no clashes
109	# regardless of how many build and tests in parallel.
110	#
111
112	set(PORT_HSEF_SRV "961")
113	if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "0")
114		set(PORT_HSEF_SRV 962)
115	endif()
116	if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "1")
117		set(PORT_HSEF_SRV 963)
118	endif()
119	if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "2")
120		set(PORT_HSEF_SRV 964)
121	endif()
122	if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "3")
123		set(PORT_HSEF_SRV 965)
124	endif()
125
126	if (websockets_shared)
127		target_link_libraries(${SAMP} websockets_shared ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS})
128		add_dependencies(${SAMP} websockets_shared)
129	else()
130		target_link_libraries(${SAMP} websockets ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS})
131	endif()
132
133	# notice we override the evlib plugin source via LD_LIBRARY_PATH so
134	# we are using the evlibs we just built, if any
135
136	if (LWS_WITH_LIBUV)
137		add_test(NAME hs_evlib_foreign_uv COMMAND lws-minimal-http-server-eventlib-foreign --uv -p ${PORT_HSEF_SRV}1)
138		set_tests_properties(hs_evlib_foreign_uv
139			     PROPERTIES
140			     ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib"
141			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-eventlib-foreign
142			     TIMEOUT 50)
143	endif()
144	if (LWS_WITH_LIBEVENT)
145		add_test(NAME hs_evlib_foreign_event COMMAND lws-minimal-http-server-eventlib-foreign --event -p ${PORT_HSEF_SRV}2)
146		set_tests_properties(hs_evlib_foreign_event
147			     PROPERTIES
148			     ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib"
149			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-eventlib-foreign
150			     TIMEOUT 50)
151	endif()
152	if (LWS_WITH_LIBEV)
153		add_test(NAME hs_evlib_foreign_ev COMMAND lws-minimal-http-server-eventlib-foreign --ev -p ${PORT_HSEF_SRV}3)
154		set_tests_properties(hs_evlib_foreign_ev
155			     PROPERTIES
156			     ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib"
157			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-eventlib-foreign
158			     TIMEOUT 50)
159	endif()
160	if (LWS_WITH_GLIB)
161		add_test(NAME hs_evlib_foreign_glib COMMAND lws-minimal-http-server-eventlib-foreign --glib -p ${PORT_HSEF_SRV}4)
162		set_tests_properties(hs_evlib_foreign_glib
163			     PROPERTIES
164			     ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib"
165			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-eventlib-foreign
166			     TIMEOUT 50)
167	endif()
168	if (LWS_WITH_SDEVENT)
169		add_test(NAME hs_evlib_foreign_sd COMMAND lws-minimal-http-server-eventlib-foreign --sd -p ${PORT_HSEF_SRV}5)
170		set_tests_properties(hs_evlib_foreign_sd
171			     PROPERTIES
172			     ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib"
173			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-eventlib-foreign
174			     TIMEOUT 50)
175	endif()
176	if (LWS_WITH_SDEVENT)
177		add_test(NAME hs_evlib_foreign_uloop COMMAND lws-minimal-http-server-eventlib-foreign --uloop -p ${PORT_HSEF_SRV}5)
178		set_tests_properties(hs_evlib_foreign_uloop
179			     PROPERTIES
180			     ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib"
181			     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-eventlib-foreign
182			     TIMEOUT 50)
183	endif()
184
185endif()
186