| 1 |
cmake_minimum_required(VERSION 3.8) |
| 2 |
|
| 3 |
set (CMAKE_CONFIGURATION_TYPES "Debug;Release") |
| 4 |
|
| 5 |
project(lwipunittests C) |
| 6 |
|
| 7 |
if (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") |
| 9 |
endif() |
| 10 |
|
| 11 |
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) |
| 12 |
if (NOT CMAKE_SYSTEM_NAME STREQUAL "GNU") |
| 13 |
set(LWIP_USE_SANITIZERS true) |
| 14 |
endif() |
| 15 |
include(${LWIP_DIR}/contrib/ports/CMakeCommon.cmake) |
| 16 |
|
| 17 |
if(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) |
| 20 |
endif() |
| 21 |
|
| 22 |
set (LWIP_DEFINITIONS -DLWIP_DEBUG -DLWIP_NOASSERT_ON_ERROR) |
| 23 |
set (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 |
|
| 31 |
include(${LWIP_CONTRIB_DIR}/ports/unix/Filelists.cmake) |
| 32 |
include(${LWIP_DIR}/src/Filelists.cmake) |
| 33 |
include(${LWIP_DIR}/test/unit/Filelists.cmake) |
| 34 |
|
| 35 |
add_executable(lwip_unittests ${LWIP_TESTFILES}) |
| 36 |
target_include_directories(lwip_unittests PRIVATE ${LWIP_INCLUDE_DIRS}) |
| 37 |
target_compile_options(lwip_unittests PRIVATE ${LWIP_COMPILER_FLAGS}) |
| 38 |
target_compile_definitions(lwip_unittests PRIVATE ${LWIP_DEFINITIONS} ${LWIP_MBEDTLS_DEFINITIONS}) |
| 39 |
|
| 40 |
find_library(LIBCHECK check) |
| 41 |
find_library(LIBM m) |
| 42 |
target_link_libraries(lwip_unittests ${LWIP_SANITIZER_LIBS} lwipallapps lwipcore ${LIBCHECK} ${LIBM}) |
| 43 |
|
| 44 |
if (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}) |
| 48 |
endif() |
| 49 |
|
| 50 |
if (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}) |
| 55 |
endif() |
| 56 |
|
| 57 |
if (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}) |
| 61 |
endif() |