1# SPDX-License-Identifier: Apache-2.0
2
3cmake_minimum_required(VERSION 3.20.0)
4
5find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6project(sockets_echo_server)
7
8if(CONFIG_NET_SOCKETS_SOCKOPT_TLS AND
9   CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED AND
10   (CONFIG_NET_SAMPLE_PSK_HEADER_FILE STREQUAL "dummy_psk.h"))
11  add_custom_target(development_psk
12    COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------"
13    COMMAND ${CMAKE_COMMAND} -E echo "--- WARNING: Using dummy PSK! Only suitable for        ---"
14    COMMAND ${CMAKE_COMMAND} -E echo "--- development. Set NET_SAMPLE_PSK_HEADER_FILE to use ---"
15    COMMAND ${CMAKE_COMMAND} -E echo "--- own pre-shared key.                                ---"
16    COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------"
17  )
18  add_dependencies(app development_psk)
19endif()
20
21target_sources(                     app PRIVATE src/echo-server.c)
22target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
23target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
24target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE src/vlan.c)
25target_sources_ifdef(CONFIG_NET_L2_IPIP app PRIVATE src/tunnel.c)
26
27if (CONFIG_USB_DEVICE_STACK)
28  target_sources(app PRIVATE src/usb.c)
29endif()
30
31if (CONFIG_USB_DEVICE_STACK_NEXT)
32  target_sources(app PRIVATE src/usb.c)
33  include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
34endif()
35
36include(${ZEPHYR_BASE}/samples/net/common/common.cmake)
37
38set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
39
40foreach(inc_file
41	ca.der
42	server.der
43	server_privkey.der
44	echo-apps-cert.der
45	echo-apps-key.der
46    )
47  generate_inc_file_for_target(
48    app
49    src/${inc_file}
50    ${gen_dir}/${inc_file}.inc
51    )
52endforeach()
53
54if(CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE)
55  zephyr_linker_sources(SECTIONS src/ws_console/sections-rom.ld)
56  target_sources(app PRIVATE src/ws_console/ws.c)
57  generate_inc_file_for_target(app src/ws_console/index.html ${gen_dir}/index.html.gz.inc --gzip)
58  generate_inc_file_for_target(app src/ws_console/style.css ${gen_dir}/style.css.gz.inc --gzip)
59  generate_inc_file_for_target(app src/ws_console/favicon-16x16.png ${gen_dir}/favicon-16x16.png.gz.inc --gzip)
60endif()
61if(CONFIG_NET_SAMPLE_HTTPS_SERVICE)
62  zephyr_linker_section_ifdef(CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE NAME
63			      http_resource_desc_wss_console_service
64			      KVMA RAM_REGION GROUP RODATA_REGION
65			      SUBALIGN Z_LINK_ITERABLE_SUBALIGN)
66endif()
67zephyr_linker_section_ifdef(CONFIG_NET_SAMPLE_WEBSOCKET_CONSOLE NAME
68			    http_resource_desc_ws_console_service
69			    KVMA RAM_REGION GROUP RODATA_REGION
70			    SUBALIGN Z_LINK_ITERABLE_SUBALIGN)
71