1# Compile the http content into a source file "pico_fsdata.inc" in a format suitable for the lwip httpd server
2# Pass the target library name library type and the list of httpd content
3function(pico_set_lwip_httpd_content TARGET_LIB TARGET_TYPE)
4    find_package (Python3 REQUIRED COMPONENTS Interpreter)
5    set(HTTPD_CONTENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
6    set(HTTPD_CONTENT_TARGET "${TARGET_LIB}_pico_set_lwip_httpd_content")
7    set(HTTPD_CONTENT_OUTPUT_NAME "pico_fsdata.inc")
8    set(HTTPD_CONTENT_TOOL "${PICO_SDK_PATH}/src/rp2_common/pico_lwip/tools/makefsdata.py")
9    add_custom_target(${HTTPD_CONTENT_TARGET} DEPENDS ${HTTPD_CONTENT_BINARY_DIR}/${HTTPD_CONTENT_OUTPUT_NAME})
10    add_custom_command(
11        OUTPUT ${HTTPD_CONTENT_BINARY_DIR}/${HTTPD_CONTENT_OUTPUT_NAME}
12        DEPENDS ${HTTPD_CONTENT_TOOL} ${ARGN}
13        COMMAND ${CMAKE_COMMAND} -E make_directory ${HTTPD_CONTENT_BINARY_DIR} &&
14            ${Python3_EXECUTABLE} ${HTTPD_CONTENT_TOOL} -i ${ARGN} -o ${HTTPD_CONTENT_BINARY_DIR}/${HTTPD_CONTENT_OUTPUT_NAME}
15        VERBATIM)
16    target_include_directories(${TARGET_LIB} ${TARGET_TYPE}
17        ${HTTPD_CONTENT_BINARY_DIR}
18        )
19    add_dependencies(${TARGET_LIB} ${HTTPD_CONTENT_TARGET})
20endfunction()
21