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