1#
2# Copyright 2020, Data61
3# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4# ABN 41 687 119 230.
5#
6# This software may be distributed and modified according to the terms of
7# the BSD 2-Clause license. Note that NO WARRANTY is provided.
8# See "LICENSE_BSD2.txt" for details.
9#
10# @TAG(DATA61_BSD)
11#
12
13cmake_minimum_required(VERSION 3.8.2)
14project(liblwip C)
15
16set(configure_string "")
17
18config_option(LibLwip LIB_LWIP "Build LwIP" DEFAULT OFF)
19mark_as_advanced(LibLwip)
20add_config_library(lwip "${configure_string}")
21if(LibLwip)
22    set(projects_dir "${CMAKE_CURRENT_LIST_DIR}/../..")
23    find_file(LWIP_PATH lwip PATHS ${projects_dir} CMAKE_FIND_ROOT_PATH_BOTH)
24    mark_as_advanced(FORCE LWIP_PATH)
25    if("${LWIP_PATH}" STREQUAL "LWIP_PATH-NOTFOUND")
26        message(FATAL_ERROR "Failed to find lwIP. Consider cmake -DLWIP_PATH=/path/to/lwip")
27    endif()
28
29    get_property(compile_options DIRECTORY PROPERTY COMPILE_OPTIONS)
30    separate_arguments(cmake_c_flags_sep NATIVE_COMMAND "${CMAKE_C_FLAGS}")
31    list(APPEND compile_options "${cmake_c_flags_sep}")
32
33    add_custom_target(get_muslc)
34    add_dependencies(get_muslc muslc)
35
36    file(
37        GLOB
38            sources
39            ${LWIP_PATH}/src/*/*.c
40            ${LWIP_PATH}/src/core/ipv4/*.c
41            ${LWIP_PATH}/src/apps/snmp/*.c
42    )
43
44    add_library(lwip STATIC EXCLUDE_FROM_ALL ${sources})
45
46    target_include_directories(
47        lwip
48        PUBLIC
49            ${LWIP_PATH}/src/include
50            # Include the header files in this directory which contain header configs
51            include include/lwip
52    )
53
54    target_link_libraries(lwip muslc liblwip_config)
55
56    target_compile_options(lwip PRIVATE ${compile_options})
57endif()
58