File: CMakeLists.txt

package info (click to toggle)
libwebsockets 4.3.5-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 31,404 kB
  • sloc: ansic: 194,409; javascript: 1,550; sh: 1,387; cpp: 505; java: 461; perl: 405; xml: 118; makefile: 76; awk: 5
file content (392 lines) | stat: -rw-r--r-- 12,354 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#
# libwebsockets - small server side websockets and web server implementation
#
# Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#

include_directories(.)

macro(add_subdir_include_dirs arg1)
	add_subdirectory(${arg1})
	list(APPEND LWS_LIB_BUILD_INC_PATHS ${_CMAKE_INC_LIST}) 
endmacro()

set(LWS_LIB_INCLUDES "")

#
# Plat specific build items
#

if (LWS_PLAT_FREERTOS)
	add_subdir_include_dirs(plat/freertos)
	if (ESP_PLATFORM)
		list(APPEND LWS_ESP_IDF_DIRS
		    $ENV{IDF_PATH}/components/freertos/include
		    $ENV{IDF_PATH}/components/esp_hw_support/include/soc/
		    $ENV{IDF_PATH}/components/esp_common/include
		    $ENV{IDF_PATH}/components/esp_timer/include
		    $ENV{IDF_PATH}/components/soc/include
		    $ENV{IDF_PATH}/components/soc/src/esp32/include
		    $ENV{IDF_PATH}/components/lwip/port/esp32/include
		    $ENV{IDF_PATH}/components/lwip/lwip/src/include
		    $ENV{IDF_PATH}/components/lwip/port/esp32/include
		    ${CMAKE_BINARY_DIR}/config
		    $ENV{IDF_PATH}/components/esp_rom/include
		    $ENV{IDF_PATH}/components/esp_system/include
		    $ENV{IDF_PATH}/components/lwip/include/apps/sntp
		    $ENV{IDF_PATH}/components/soc/soc/esp32/include
		    $ENV{IDF_PATH}/components/heap/include
		    $ENV{IDF_PATH}/components/mbedtls/mbedtls/include
		    $ENV{IDF_PATH}/components/mbedtls/port/include
		    $ENV{IDF_PATH}/components/esp_wifi/include
		    $ENV{IDF_PATH}/components/esp_event/include
		    $ENV{IDF_PATH}/components/esp_netif/include
		    $ENV{IDF_PATH}/components/esp_eth/include
		    $ENV{IDF_PATH}/components/driver/include
		    $ENV{IDF_PATH}/components/soc/soc/include
		    $ENV{IDF_PATH}/components/tcpip_adapter/include
		    $ENV{IDF_PATH}/components/lwip/include/apps
		    $ENV{IDF_PATH}/components/nvs_flash/include
		    $ENV{IDF_PATH}/components/esp32/include
		    $ENV{IDF_PATH}/components/spi_flash/include
		    $ENV{IDF_PATH}/components/mdns/include
		    $ENV{IDF_PATH}/components/lwip/lwip/src/include/lwip
		    $ENV{IDF_PATH}/components/lwip/lwip/src/include
		    $ENV{IDF_PATH}/components/lwip/lwip/src/include/lwip
		    $ENV{IDF_PATH}/components/newlib/platform_include )

		    include_directories(${LWS_ESP_IDF_DIRS})

		    list(APPEND CMAKE_REQUIRED_INCLUDES ${LWS_ESP_IDF_DIRS})
	endif()

	
else()
	if (LWS_PLAT_OPTEE)
		add_subdir_include_dirs(plat/optee)
	else()
		if (WIN32)
			add_subdir_include_dirs(plat/windows)
		else()
			add_subdir_include_dirs(plat/unix)
		endif()
	endif()
endif()

if (LIB_LIST)
	set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST} ${CMAKE_REQUIRED_LIBRARIES})
endif()

if (LWS_WITH_ZLIB)
	if (LWS_WITH_BUNDLED_ZLIB)
		if (WIN32)
			# it's trying to delete internal zlib entry
			LIST(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0 )
		endif()
	endif()
endif()


# ideally we want to use pipe2()

CHECK_C_SOURCE_COMPILES("
	#ifndef _GNU_SOURCE
	#define _GNU_SOURCE
	#endif
	#include <unistd.h>
	int main(void) {
		int fd[2];
		return pipe2(fd, 0);
	}" LWS_HAVE_PIPE2)

# tcp keepalive needs this on linux to work practically... but it only exists
# after kernel 2.6.37

CHECK_C_SOURCE_COMPILES("#include <netinet/tcp.h>\nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT)
set(LWS_PUBLIC_INCLUDES "")
if (LWS_WITH_TLS)
	add_subdir_include_dirs(tls)
endif()

# Generate the lws_config.h that includes all the private compilation settings.
configure_file(
       "${PROJECT_SOURCE_DIR}/cmake/lws_config_private.h.in"
       "${PROJECT_BINARY_DIR}/lws_config_private.h")

add_subdir_include_dirs(core)
add_subdir_include_dirs(misc)
add_subdir_include_dirs(system)

if (LWS_WITH_DRIVERS)
	add_subdir_include_dirs(drivers)
endif()

if (LWS_WITH_NETWORK)
	add_subdir_include_dirs(core-net)
	if (LWS_WITH_ABSTRACT)
		add_subdir_include_dirs(abstract)
	endif()
	add_subdir_include_dirs(roles)
endif()

if (LWS_WITH_JOSE)
	add_subdir_include_dirs(jose)
endif()
if (LWS_WITH_COSE)
	add_subdir_include_dirs(cose)
endif()


if (LWS_WITH_SECURE_STREAMS)
	add_subdir_include_dirs(secure-streams)
endif()

add_subdir_include_dirs(event-libs)

if (LWS_WITH_STATIC)
    if (LWS_STATIC_PIC)
        set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    endif()

	add_library(websockets STATIC ${SOURCES})# ${HDR_PUBLIC})
	set_target_properties(websockets PROPERTIES LINKER_LANGUAGE C)
	list(APPEND LWS_LIBRARIES websockets)
	target_include_directories(websockets INTERFACE
		$<INSTALL_INTERFACE:${LWS_INSTALL_INCLUDE_DIR}>
		$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
		$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../include>
	)
	target_include_directories(websockets PRIVATE ${LWS_LIB_BUILD_INC_PATHS})
	target_compile_definitions(websockets PRIVATE LWS_BUILDING_STATIC)
	target_include_directories(websockets PUBLIC ${LWS_PUBLIC_INCLUDES})
	set(LWS_PUBLIC_INCLUDES ${LWS_PUBLIC_INCLUDES} PARENT_SCOPE)

	if (WIN32)
		# Windows uses the same .lib ending for static libraries and shared
		# library linker files, so rename the static library.
		set_target_properties(websockets
			PROPERTIES
			OUTPUT_NAME websockets_static)
	endif()
	
endif()

if (LWS_WITH_SHARED)
	if (NOT RESOURCES)
		set(RESOURCES "")
	endif()
	
	add_library(websockets_shared SHARED ${SOURCES} ${RESOURCES})# ${HDR_PUBLIC})
	set_target_properties(websockets_shared PROPERTIES LINKER_LANGUAGE C)
	list(APPEND LWS_LIBRARIES websockets_shared)
	target_include_directories(websockets_shared INTERFACE
		$<INSTALL_INTERFACE:${LWS_INSTALL_INCLUDE_DIR}>
		$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
		$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../include>
	)
	target_include_directories(websockets_shared PRIVATE ${LWS_LIB_BUILD_INC_PATHS})
	target_compile_definitions(websockets_shared PRIVATE LWS_BUILDING_SHARED)
	target_include_directories(websockets_shared PUBLIC ${LWS_PUBLIC_INCLUDES})
	set(LWS_PUBLIC_INCLUDES ${LWS_PUBLIC_INCLUDES} PARENT_SCOPE)

	# We want the shared lib to be named "libwebsockets"
	# not "libwebsocket_shared".
	set_target_properties(websockets_shared
		PROPERTIES
		OUTPUT_NAME websockets)

	if (WIN32)
		# Compile as DLL (export function declarations)
		set_property(
			TARGET websockets_shared
			PROPERTY COMPILE_DEFINITIONS
			LWS_DLL
			LWS_INTERNAL)
	endif()

	if (APPLE)
		set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
	endif()

	if (UNIX AND LWS_WITH_PLUGINS_API)
		set (CMAKE_POSITION_INDEPENDENT_CODE ON)
		if (NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR
		   (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") OR
		   (${CMAKE_SYSTEM_NAME} MATCHES "QNX")))
		   if (LWS_WITH_SHARED)
				target_link_libraries(websockets_shared dl)
			endif()
		endif()
	endif()

endif()

#
# expose the library private include dirs to plugins, test apps etc that are
# part of the lib build but different targets 
#

if (LWS_WITH_SHARED)
	get_target_property(LWS_LIB_INCLUDES websockets_shared INCLUDE_DIRECTORIES)
else()
	get_target_property(LWS_LIB_INCLUDES websockets INCLUDE_DIRECTORIES)
endif()


# Set the so version of the lib.
# Equivalent to LDFLAGS=-version-info x:x:x

if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
	foreach(lib ${LWS_LIBRARIES})
		set_target_properties(${lib}
			PROPERTIES
			SOVERSION ${SOVERSION})
	endforeach()
endif()


# Setup the linking for all libs.
foreach (lib ${LWS_LIBRARIES})
	target_link_libraries(${lib} ${LIB_LIST})
endforeach()

#
# These will be available to parent projects including libwebsockets
# using add_subdirectory()
#
set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
if (LWS_WITH_STATIC)
	set(LIBWEBSOCKETS_LIBRARIES_STATIC websockets CACHE STRING "Libwebsocket static library")
endif()
if (LWS_WITH_SHARED)
	set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
endif()

# Install libs and headers.
install(TARGETS ${LWS_LIBRARIES}
		EXPORT LibwebsocketsTargets
		LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT core
		ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT core
		RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT core # Windows DLLs
		PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
		
	#set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries" PARENT_SCOPE)
set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files" PARENT_SCOPE)


if (UNIX OR MINGW)

# figure out pkfcfg required libs here

set(lws_requires "")
if (LWS_HAVE_LIBCAP)
	if (NOT lws_requires STREQUAL "")
		set(lws_requires "${lws_requires},libcap")
	else()
		set(lws_requires "libcap")
	endif()
endif()


# Generate and install pkgconfig.
# (This is not indented, because the tabs will be part of the output)
file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib${LIB_SUFFIX}
includedir=\${prefix}/include

Name: libwebsockets
Description: Websockets server and client library
Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}

Libs: -L\${libdir} -lwebsockets
Cflags: -I\${includedir}
"
)
if (NOT ${lws_requires} STREQUAL "")
        file(APPEND "${PROJECT_BINARY_DIR}/libwebsockets.pc" "Requires: ${lws_requires}")
endif()


	install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
		DESTINATION lib${LIB_SUFFIX}/pkgconfig)

file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
"prefix=\"${CMAKE_INSTALL_PREFIX}\"
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib${LIB_SUFFIX}
includedir=\${prefix}/include

Name: libwebsockets_static
Description: Websockets server and client static library
Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}

Libs: -L\${libdir} -l:libwebsockets${CMAKE_STATIC_LIBRARY_SUFFIX}
Libs.private:
Cflags: -I\${includedir}
"
)

if (NOT ${lws_requires} STREQUAL "")
        file(APPEND "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" "Requires: ${lws_requires}")
endif()


	install(FILES "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
		DESTINATION lib${LIB_SUFFIX}/pkgconfig)

endif(UNIX OR MINGW)


# Keep explicit parent scope exports at end
#

export_to_parent_intermediate()
if (DEFINED LWS_PLAT_UNIX)
	set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE)
	if (ILLUMOS)
		add_definitions("-D__illumos__")
	endif()
endif()
set(LWS_HAVE_MBEDTLS_NET_SOCKETS ${LWS_HAVE_MBEDTLS_NET_SOCKETS} PARENT_SCOPE)
set(LWS_HAVE_MBEDTLS_SSL_NEW_SESSION_TICKET ${LWS_HAVE_MBEDTLS_SSL_NEW_SESSION_TICKET} PARENT_SCOPE)
set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols ${LWS_HAVE_mbedtls_ssl_conf_alpn_protocols} PARENT_SCOPE)
set(TEST_SERVER_SSL_KEY "${TEST_SERVER_SSL_KEY}" PARENT_SCOPE)
set(TEST_SERVER_SSL_CERT "${TEST_SERVER_SSL_CERT}" PARENT_SCOPE)
set(TEST_SERVER_DATA ${TEST_SERVER_DATA} PARENT_SCOPE)
set(LWS_HAVE_PIPE2 ${LWS_HAVE_PIPE2} PARENT_SCOPE)
set(LWS_LIBRARIES ${LWS_LIBRARIES} PARENT_SCOPE)
if (DEFINED WIN32_HELPERS_PATH)
	set(WIN32_HELPERS_PATH ${WIN32_HELPERS_PATH} PARENT_SCOPE)
endif()
if (DEFINED HDR_PRIVATE)
set(HDR_PRIVATE ${HDR_PRIVATE} PARENT_SCOPE)
endif()
if (DEFINED ZLIB_FOUND)
	set(ZLIB_FOUND ${ZLIB_FOUND} PARENT_SCOPE)
endif()
if (DEFINED LIB_LIST_AT_END)
set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE)
endif()
set(USE_WOLFSSL ${USE_WOLFSSL} PARENT_SCOPE)
set(LWS_DEPS_LIB_PATHS ${LWS_DEPS_LIB_PATHS} PARENT_SCOPE)