• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# libwebsockets - small server side websockets and web server implementation
3#
4# Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com>
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to
8# deal in the Software without restriction, including without limitation the
9# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10# sell copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22# IN THE SOFTWARE.
23#
24
25include_directories(.)
26
27if (DEFINED LIB_LIST_AT_END)
28link_libraries(${LIB_LIST_AT_END})
29endif()
30
31if ((LWS_WITH_PLUGINS AND LWS_WITH_SHARED) OR LWS_WITH_PLUGINS_BUILTIN)
32
33	#
34	# Either build the plugins as separate dynamic libs (LWS_WITH_PLUGINS)
35	# or build into the main lws library (LWS_WITH_PLUGINS_BUILTIN)
36	#
37
38	macro(create_plugin PLUGIN_NAME PLUGIN_INCLUDE MAIN_SRC S2 S3)
39
40		if (NOT LWS_WITH_PLUGINS_BUILTIN)
41			set(PLUGIN_SRCS ${MAIN_SRC})
42
43			if ("${S2}" STREQUAL "")
44			else()
45				list(APPEND PLUGIN_SRCS ${S2})
46			endif()
47			if ("${S3}" STREQUAL "")
48			else()
49				list(APPEND PLUGIN_SRCS ${S3})
50			endif()
51
52			if (WIN32)
53				list(APPEND PLUGIN_SRCS
54					${WIN32_HELPERS_PATH}/getopt.c
55					${WIN32_HELPERS_PATH}/getopt_long.c
56					${WIN32_HELPERS_PATH}/gettimeofday.c
57				)
58
59				list(APPEND PLUGIN_HDR
60					${WIN32_HELPERS_PATH}/getopt.h
61					${WIN32_HELPERS_PATH}/gettimeofday.h
62				)
63			endif(WIN32)
64
65			source_group("Headers Private"   FILES ${PLUGIN_HDR})
66			source_group("Sources"   FILES ${PLUGIN_SRCS})
67			add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
68			target_link_libraries(${PLUGIN_NAME} websockets_shared)
69			add_dependencies(${PLUGIN_NAME} websockets_shared)
70
71			# doesn't work inside macro :-O
72			# target_compile_definitions(${PLUGIN_NAME} PRIVATE LWS_BUILDING_SHARED)
73			target_include_directories(${PLUGIN_NAME} PRIVATE ${PLUGIN_INCLUDE}
74									  ${LWS_LIB_BUILD_INC_PATHS})
75			set_property(TARGET ${PLUGIN_NAME}
76				     PROPERTY COMPILE_DEFINITIONS
77				     INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
78			)
79
80			set(CMAKE_POSITION_INDEPENDENT_CODE ON)
81			list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
82		else()
83			# let's just build the things into the lib
84
85			message("Building in plugin ${PLUGIN_NAME}")
86
87			if ("${PLUGIN_INCLUDE}" STREQUAL "")
88			else()
89				list(APPEND LWS_LIB_BUILD_INC_PATHS ../plugins/${PLUGIN_INCLUDE})
90			endif()
91
92			if ("${MAIN_SRC}" STREQUAL "")
93			else()
94				foreach(A ${MAIN_SRC})
95					list(APPEND SOURCES ../plugins/${A})
96				endforeach()
97			endif()
98			if ("${S2}" STREQUAL "")
99			else()
100				foreach(A ${S2})
101					list(APPEND SOURCES ../plugins/${A})
102				endforeach()
103			endif()
104			if ("${S3}" STREQUAL "")
105			else()
106				foreach(A ${S3})
107					list(APPEND SOURCES ../plugins/${A})
108				endforeach()
109			endif()
110
111		endif(NOT LWS_WITH_PLUGINS_BUILTIN)
112	endmacro()
113
114if (LWS_ROLE_WS)
115		create_plugin(protocol_dumb_increment ""
116			      "protocol_dumb_increment.c" "" "")
117		if (NOT LWS_WITH_PLUGINS_BUILTIN)
118			target_compile_definitions(protocol_dumb_increment PRIVATE LWS_BUILDING_SHARED)
119		endif()
120
121		create_plugin(protocol_lws_mirror ""
122			      "protocol_lws_mirror.c" "" "")
123		if (NOT LWS_WITH_PLUGINS_BUILTIN)
124			target_compile_definitions(protocol_lws_mirror PRIVATE LWS_BUILDING_SHARED)
125		endif()
126
127		create_plugin(protocol_lws_status ""
128			      "protocol_lws_status.c" "" "")
129		if (NOT LWS_WITH_PLUGINS_BUILTIN)
130			target_compile_definitions(protocol_lws_status PRIVATE LWS_BUILDING_SHARED)
131		endif()
132
133		if (NOT WIN32)
134			create_plugin(protocol_lws_raw_test ""
135			      "protocol_lws_raw_test.c" "" "")
136			if (NOT LWS_WITH_PLUGINS_BUILTIN)
137				target_compile_definitions(protocol_lws_raw_test PRIVATE LWS_BUILDING_SHARED)
138			endif()
139
140
141		      if (UNIX AND LWS_HAVE_PTHREAD_H)
142				create_plugin(protocol_deaddrop ""
143				      "deaddrop/protocol_lws_deaddrop.c" "" "")
144				if (NOT LWS_WITH_PLUGINS_BUILTIN)
145					target_compile_definitions(protocol_deaddrop PRIVATE LWS_BUILDING_SHARED)
146				endif()
147			endif()
148		endif()
149
150	if (LWS_WITH_SYS_METRICS)
151			create_plugin(protocol_lws_openmetrics_export ""
152				      "protocol_lws_openmetrics_export.c" "" "")
153			if (NOT LWS_WITH_PLUGINS_BUILTIN)
154				target_compile_definitions(protocol_lws_openmetrics_export PRIVATE LWS_BUILDING_SHARED)
155			endif()
156	endif()
157
158	if (NOT LWS_WITHOUT_CLIENT)
159			create_plugin(protocol_client_loopback_test ""
160        	                      "protocol_client_loopback_test.c" "" "")
161			if (NOT LWS_WITH_PLUGINS_BUILTIN)
162				target_compile_definitions(protocol_client_loopback_test PRIVATE LWS_BUILDING_SHARED)
163			endif()
164
165	endif()
166
167endif(LWS_ROLE_WS)
168
169	create_plugin(protocol_post_demo ""
170		      "protocol_post_demo.c" "" "")
171	if (NOT LWS_WITH_PLUGINS_BUILTIN)
172		target_compile_definitions(protocol_post_demo PRIVATE LWS_BUILDING_SHARED)
173	endif()
174
175
176if (LWS_ROLE_RAW_PROXY)
177	create_plugin(protocol_lws_raw_proxy ""
178		      "raw-proxy/protocol_lws_raw_proxy.c" "" "")
179	if (NOT LWS_WITH_PLUGINS_BUILTIN)
180		target_compile_definitions(protocol_lws_raw_proxy PRIVATE LWS_BUILDING_SHARED)
181	endif()
182
183endif()
184
185if (LWS_WITH_FTS)
186	create_plugin(protocol_fulltext_demo ""
187		      "protocol_fulltext_demo.c" "" "")
188	if (NOT LWS_WITH_PLUGINS_BUILTIN)
189		target_compile_definitions(protocol_fulltext_demo PRIVATE LWS_BUILDING_SHARED)
190	endif()
191
192endif()
193
194
195if (LWS_WITH_SSL)
196	create_plugin(protocol_lws_ssh_base "ssh-base/include"
197		      "ssh-base/sshd.c;ssh-base/telnet.c;ssh-base/kex-25519.c" "ssh-base/crypto/chacha.c;ssh-base/crypto/ed25519.c;ssh-base/crypto/fe25519.c;ssh-base/crypto/ge25519.c;ssh-base/crypto/poly1305.c;ssh-base/crypto/sc25519.c;ssh-base/crypto/smult_curve25519_ref.c" "")
198	if (NOT LWS_WITH_PLUGINS_BUILTIN)
199		target_compile_definitions(protocol_lws_ssh_base PRIVATE LWS_BUILDING_SHARED)
200	endif()
201
202	create_plugin(protocol_lws_sshd_demo "ssh-base/include" "protocol_lws_sshd_demo.c" "" "")
203	if (NOT LWS_WITH_PLUGINS_BUILTIN)
204		target_compile_definitions(protocol_lws_sshd_demo PRIVATE LWS_BUILDING_SHARED)
205	endif()
206
207	include_directories("${PROJECT_SOURCE_DIR}/plugins/ssh-base/include")
208endif()
209
210
211
212if (LWS_WITH_ACME)
213	create_plugin(protocol_lws_acme_client ""
214		      "acme-client/protocol_lws_acme_client.c" "" "")
215	if (NOT LWS_WITH_PLUGINS_BUILTIN)
216		target_compile_definitions(protocol_lws_acme_client PRIVATE LWS_BUILDING_SHARED)
217	endif()
218endif()
219
220endif((LWS_WITH_PLUGINS AND LWS_WITH_SHARED) OR LWS_WITH_PLUGINS_BUILTIN)
221
222
223# plugins
224
225if (LWS_WITH_PLUGINS AND NOT LWS_WITH_PLUGINS_BUILTIN)
226
227	install(TARGETS ${PLUGINS_LIST}
228		PERMISSIONS  OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
229		DESTINATION share/libwebsockets-test-server/plugins
230		COMPONENT plugins)
231
232	if (NOT WIN32)
233		install(FILES deaddrop/assets/index.html;deaddrop/assets/deaddrop.js;deaddrop/assets/deaddrop.css;deaddrop/assets/drop.svg
234			DESTINATION share/libwebsockets-test-server/deaddrop
235			COMPONENT plugins)
236	endif()
237
238
239endif()
240
241export_to_parent_intermediate()
242
243