• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.8)
2
3set (CMAKE_CONFIGURATION_TYPES "Debug;Release")
4
5project(lwipunittests C)
6
7if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "GNU")
8    message(FATAL_ERROR "Unit test are currently only working on Linux, Darwin or Hurd")
9endif()
10
11set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
12if (NOT CMAKE_SYSTEM_NAME STREQUAL "GNU")
13    set(LWIP_USE_SANITIZERS true)
14endif()
15include(${LWIP_DIR}/contrib/ports/CMakeCommon.cmake)
16
17if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
18    # check.h causes 'error: token pasting of ',' and __VA_ARGS__ is a GNU extension' with clang 9.0.0
19    list(LWIP_COMPILER_FLAGS APPEND -Wno-gnu-zero-variadic-macro-arguments)
20endif()
21
22set (LWIP_DEFINITIONS -DLWIP_DEBUG -DLWIP_NOASSERT_ON_ERROR)
23set (LWIP_INCLUDE_DIRS
24    "${LWIP_DIR}/test/unit"
25    "${LWIP_DIR}/src/include"
26    "${LWIP_CONTRIB_DIR}/"
27    "${LWIP_CONTRIB_DIR}/ports/unix/port/include"
28    "${CMAKE_CURRENT_SOURCE_DIR}/"
29)
30
31include(${LWIP_CONTRIB_DIR}/ports/unix/Filelists.cmake)
32include(${LWIP_DIR}/src/Filelists.cmake)
33include(${LWIP_DIR}/test/unit/Filelists.cmake)
34
35add_executable(lwip_unittests ${LWIP_TESTFILES})
36target_include_directories(lwip_unittests PRIVATE ${LWIP_INCLUDE_DIRS})
37target_compile_options(lwip_unittests PRIVATE ${LWIP_COMPILER_FLAGS})
38target_compile_definitions(lwip_unittests PRIVATE ${LWIP_DEFINITIONS} ${LWIP_MBEDTLS_DEFINITIONS})
39
40find_library(LIBCHECK check)
41find_library(LIBM m)
42target_link_libraries(lwip_unittests ${LWIP_SANITIZER_LIBS} lwipallapps lwipcore ${LIBCHECK} ${LIBM})
43
44if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
45    # check installed via brew on Darwin doesn't have a separate subunit library (must be statically linked)
46    find_library(LIBSUBUNIT subunit)
47    target_link_libraries(lwip_unittests ${LIBSUBUNIT})
48endif()
49
50if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "GNU")
51    find_library(LIBUTIL util)
52    find_library(LIBPTHREAD pthread)
53    find_library(LIBRT rt)
54    target_link_libraries(lwip_unittests ${LIBUTIL} ${LIBPTHREAD} ${LIBRT})
55endif()
56
57if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
58    # Darwin doesn't have pthreads or POSIX real-time extensions libs
59    find_library(LIBUTIL util)
60    target_link_libraries(lwip_unittests ${LIBUTIL})
61endif()
62