1# SPDX-License-Identifier: Apache-2.0 2 3cmake_minimum_required(VERSION 3.20.0) 4 5find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 6find_package(Python REQUIRED COMPONENTS Interpreter) 7 8project(http_server) 9 10if(CONFIG_NET_SOCKETS_SOCKOPT_TLS AND 11 CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED AND 12 (CONFIG_NET_SAMPLE_PSK_HEADER_FILE STREQUAL "dummy_psk.h")) 13 add_custom_target(development_psk 14 COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------" 15 COMMAND ${CMAKE_COMMAND} -E echo "--- WARNING: Using dummy PSK! Only suitable for ---" 16 COMMAND ${CMAKE_COMMAND} -E echo "--- development. Set NET_SAMPLE_PSK_HEADER_FILE to use ---" 17 COMMAND ${CMAKE_COMMAND} -E echo "--- own pre-shared key. ---" 18 COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------" 19 ) 20 add_dependencies(app development_psk) 21endif() 22 23set(CERTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/certs) 24 25add_custom_target(sample_ca_cert 26 WORKING_DIRECTORY ${CERTS_DIR} 27 COMMAND sh gen_ca_cert.sh 28 COMMENT "Generating sample CA certificate" 29) 30 31add_custom_target(sample_server_cert 32 WORKING_DIRECTORY ${CERTS_DIR} 33 COMMAND sh gen_server_cert.sh 34 COMMENT "Generating sample server certificate" 35) 36 37option(INCLUDE_HTML_CONTENT "Include the HTML content" ON) 38 39target_sources(app PRIVATE src/main.c) 40 41set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) 42 43target_sources_ifdef(CONFIG_NET_SAMPLE_WEBSOCKET_SERVICE app PRIVATE src/ws.c) 44target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c) 45 46target_link_libraries(app PRIVATE zephyr_interface zephyr) 47 48zephyr_linker_sources(SECTIONS sections-rom.ld) 49zephyr_linker_section_ifdef(CONFIG_NET_SAMPLE_HTTPS_SERVICE NAME 50 http_resource_desc_test_https_service 51 KVMA RAM_REGION GROUP RODATA_REGION 52 SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN}) 53zephyr_linker_section_ifdef(CONFIG_NET_SAMPLE_HTTP_SERVICE NAME 54 http_resource_desc_test_http_service 55 KVMA RAM_REGION GROUP RODATA_REGION 56 SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN}) 57 58foreach(web_resource 59 index.html 60 main.js 61 ) 62 generate_inc_file_for_target( 63 app 64 src/static_web_resources/${web_resource} 65 ${gen_dir}/${web_resource}.gz.inc 66 --gzip 67 ) 68endforeach() 69 70foreach(inc_file 71 server_cert.der 72 server_privkey.der 73 ) 74 generate_inc_file_for_target( 75 app 76 src/certs/${inc_file} 77 ${gen_dir}/${inc_file}.inc 78 ) 79endforeach() 80