| 1 |
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0") |
| 2 |
include_guard(GLOBAL) |
| 3 |
endif() |
| 4 |
|
| 5 |
if(NOT CMAKE_BUILD_TYPE) |
| 6 |
message(STATUS "CMAKE_BUILD_TYPE not set - defaulting to Debug build.") |
| 7 |
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: ${CMAKE_CONFIGURATION_TYPES}." FORCE) |
| 8 |
endif() |
| 9 |
message (STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
| 10 |
|
| 11 |
set(LWIP_CONTRIB_DIR ${LWIP_DIR}/contrib) |
| 12 |
|
| 13 |
# ARM mbedtls support https://tls.mbed.org/ |
| 14 |
if(NOT DEFINED LWIP_MBEDTLSDIR) |
| 15 |
set(LWIP_MBEDTLSDIR ${LWIP_DIR}/../mbedtls) |
| 16 |
message(STATUS "LWIP_MBEDTLSDIR not set - using default location ${LWIP_MBEDTLSDIR}") |
| 17 |
endif() |
| 18 |
if(EXISTS ${LWIP_MBEDTLSDIR}/CMakeLists.txt) |
| 19 |
set(LWIP_HAVE_MBEDTLS ON BOOL) |
| 20 |
|
| 21 |
# Prevent building MBEDTLS programs and tests |
| 22 |
set(ENABLE_PROGRAMS OFF CACHE BOOL "") |
| 23 |
set(ENABLE_TESTING OFF CACHE BOOL "") |
| 24 |
|
| 25 |
# mbedtls uses cmake. Sweet! |
| 26 |
add_subdirectory(${LWIP_MBEDTLSDIR} mbedtls) |
| 27 |
|
| 28 |
set (LWIP_MBEDTLS_DEFINITIONS |
| 29 |
LWIP_HAVE_MBEDTLS=1 |
| 30 |
) |
| 31 |
set (LWIP_MBEDTLS_INCLUDE_DIRS |
| 32 |
${LWIP_MBEDTLSDIR}/include |
| 33 |
) |
| 34 |
set (LWIP_MBEDTLS_LINK_LIBRARIES |
| 35 |
mbedtls |
| 36 |
mbedcrypto |
| 37 |
mbedx509 |
| 38 |
) |
| 39 |
endif() |
| 40 |
|
| 41 |
set(LWIP_COMPILER_FLAGS_GNU_CLANG |
| 42 |
$<$<CONFIG:Debug>:-Og> |
| 43 |
$<$<CONFIG:Debug>:-g> |
| 44 |
$<$<CONFIG:Release>:-O3> |
| 45 |
-Wall |
| 46 |
-pedantic |
| 47 |
-Werror |
| 48 |
-Wparentheses |
| 49 |
-Wsequence-point |
| 50 |
-Wswitch-default |
| 51 |
-Wextra |
| 52 |
-Wundef |
| 53 |
-Wshadow |
| 54 |
-Wpointer-arith |
| 55 |
-Wcast-qual |
| 56 |
-Wwrite-strings |
| 57 |
$<$<COMPILE_LANGUAGE:C>:-Wold-style-definition> |
| 58 |
-Wcast-align |
| 59 |
$<$<COMPILE_LANGUAGE:C>:-Wmissing-prototypes> |
| 60 |
$<$<COMPILE_LANGUAGE:C>:-Wnested-externs> |
| 61 |
-Wunreachable-code |
| 62 |
-Wuninitialized |
| 63 |
-Wmissing-prototypes |
| 64 |
-Waggregate-return |
| 65 |
-Wlogical-not-parentheses |
| 66 |
) |
| 67 |
|
| 68 |
if (NOT LWIP_HAVE_MBEDTLS) |
| 69 |
list(APPEND LWIP_COMPILER_FLAGS_GNU_CLANG |
| 70 |
-Wredundant-decls |
| 71 |
$<$<COMPILE_LANGUAGE:C>:-Wc++-compat> |
| 72 |
) |
| 73 |
endif() |
| 74 |
|
| 75 |
if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 76 |
list(APPEND LWIP_COMPILER_FLAGS_GNU_CLANG |
| 77 |
-Wlogical-op |
| 78 |
-Wtrampolines |
| 79 |
) |
| 80 |
|
| 81 |
if (NOT LWIP_HAVE_MBEDTLS) |
| 82 |
list(APPEND LWIP_COMPILER_FLAGS_GNU_CLANG |
| 83 |
$<$<COMPILE_LANGUAGE:C>:-Wc90-c99-compat> |
| 84 |
) |
| 85 |
endif() |
| 86 |
|
| 87 |
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9) |
| 88 |
if(LWIP_USE_SANITIZERS) |
| 89 |
list(APPEND LWIP_COMPILER_FLAGS_GNU_CLANG |
| 90 |
-fsanitize=address |
| 91 |
-fsanitize=undefined |
| 92 |
-fno-sanitize=alignment |
| 93 |
-fstack-protector |
| 94 |
-fstack-check |
| 95 |
) |
| 96 |
set(LWIP_SANITIZER_LIBS asan ubsan) |
| 97 |
endif() |
| 98 |
endif() |
| 99 |
|
| 100 |
set(LWIP_COMPILER_FLAGS ${LWIP_COMPILER_FLAGS_GNU_CLANG}) |
| 101 |
endif() |
| 102 |
|
| 103 |
if(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 104 |
list(APPEND LWIP_COMPILER_FLAGS_GNU_CLANG |
| 105 |
-Wdocumentation |
| 106 |
-Wno-documentation-deprecated-sync |
| 107 |
) |
| 108 |
|
| 109 |
if(LWIP_USE_SANITIZERS) |
| 110 |
list(APPEND LWIP_COMPILER_FLAGS_GNU_CLANG |
| 111 |
-fsanitize=address |
| 112 |
-fsanitize=undefined |
| 113 |
-fno-sanitize=alignment |
| 114 |
) |
| 115 |
set(LWIP_SANITIZER_LIBS asan ubsan) |
| 116 |
endif() |
| 117 |
|
| 118 |
set(LWIP_COMPILER_FLAGS ${LWIP_COMPILER_FLAGS_GNU_CLANG}) |
| 119 |
endif() |
| 120 |
|
| 121 |
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") |
| 122 |
set(LWIP_COMPILER_FLAGS |
| 123 |
$<$<CONFIG:Debug>:/Od> |
| 124 |
$<$<CONFIG:Release>:/Ox> |
| 125 |
/W4 |
| 126 |
/WX |
| 127 |
) |
| 128 |
endif() |