CMakeLists.txt 2.1 KB

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