| 1 |
Building lwIP |
| 2 |
============= |
| 3 |
|
| 4 |
lwIP uses a CMake based build system. |
| 5 |
|
| 6 |
The CMake files in this project are designed to |
| 7 |
be included into your own CMake files. They are |
| 8 |
mainly variable definitions containing a list of |
| 9 |
source files and predefined static libraries to |
| 10 |
be linked against application code. |
| 11 |
|
| 12 |
1) lwIP sources: |
| 13 |
src/Filelists.cmake provides file lists containing |
| 14 |
the lwIP core library. |
| 15 |
The file also contains two static libraries, lwipcore |
| 16 |
and lwipallapps, where you can link your app against. |
| 17 |
This is the file that is useful to all lwIP users. |
| 18 |
|
| 19 |
2) Example applications: |
| 20 |
contrib/Filelists.cmake provides several file lists |
| 21 |
containing the example applications. |
| 22 |
The file also contains several static libraries |
| 23 |
for these example apps. |
| 24 |
This file is only useful for you, if you can use one |
| 25 |
of the examples in your application, which is normally |
| 26 |
not the case. |
| 27 |
|
| 28 |
3) OS/platform port: |
| 29 |
Usually the OS port needs to be provided by the user. |
| 30 |
If a port to Linux, Windows or MacOS is useful for |
| 31 |
you, you can use |
| 32 |
contrib/ports/{win32, unix}/Filelists.cmake |
| 33 |
that contains file lists and libraries for |
| 34 |
these operating systems. |
| 35 |
|
| 36 |
VARIABLES |
| 37 |
========= |
| 38 |
In all cases, you need to provide two variables. |
| 39 |
|
| 40 |
"LWIP_DIR" pointing to the lwIP directory |
| 41 |
Example: |
| 42 |
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/externals/lwip) |
| 43 |
|
| 44 |
"LWIP_INCLUDE_DIRS" that contains the include base paths |
| 45 |
- for lwIP itself (${LWIP_DIR}/src/include) |
| 46 |
- for lwIP contrib if you use it (${LWIP_DIR}/contrib) |
| 47 |
- to a directory containing an OS port |
| 48 |
- to a directory containing lwipopts.h |
| 49 |
|
| 50 |
Example: |
| 51 |
set (LWIP_INCLUDE_DIRS |
| 52 |
"${LWIP_DIR}/src/include" |
| 53 |
"${LWIP_DIR}/contrib" |
| 54 |
"${LWIP_DIR}/contrib/ports/unix/port/include" |
| 55 |
"${LWIP_DIR}/contrib/examples/example_app" |
| 56 |
) |
| 57 |
|
| 58 |
Putting it all together |
| 59 |
======================= |
| 60 |
To get a working application, your CMake system |
| 61 |
needs to provide the variables described above, e.g. |
| 62 |
set (LWIP_DIR <path to lwip sources>) |
| 63 |
set (LWIP_INCLUDE_DIRS |
| 64 |
"${LWIP_DIR}/src/include" |
| 65 |
"${LWIP_DIR}/contrib" |
| 66 |
"<path to my port>/include" |
| 67 |
"<path to lwipopts.h>" |
| 68 |
) |
| 69 |
|
| 70 |
You may add some defines: |
| 71 |
set (LWIP_DEFINITIONS LWIP_DEBUG=1) |
| 72 |
|
| 73 |
Then include the filelists you need: |
| 74 |
include(${LWIP_DIR}/src/Filelists.cmake) |
| 75 |
include(${LWIP_DIR}/contrib/Filelists.cmake) |
| 76 |
|
| 77 |
Then, declare you executable: |
| 78 |
add_executable(my_app <my source files> <my lwip port files>) |
| 79 |
|
| 80 |
Add lwIP include dirs to your app: |
| 81 |
target_include_directories(my_app PRIVATE ${LWIP_INCLUDE_DIRS}) |
| 82 |
|
| 83 |
Link your app against the lwIP libs from the filelists you need: |
| 84 |
target_link_libraries(my_app lwipcontribapps lwipallapps lwipcore) |
| 85 |
|
| 86 |
Working example |
| 87 |
=============== |
| 88 |
Working build examples can be found in the |
| 89 |
contrib/ports/{win32, unix}/example_app |
| 90 |
subdirectory. |
| 91 |
To use them, create a build directory and call cmake with |
| 92 |
the lwIP root dir: |
| 93 |
|
| 94 |
- mkdir build |
| 95 |
- cd build |
| 96 |
- cmake .. |
| 97 |
- cmake --build . |
| 98 |
|
| 99 |
The CMakeLists.txt will autoselect the correct port |
| 100 |
for your system (supported: Linux, Windows, Darwin). |
| 101 |
|
| 102 |
To configure the example app to your needs, you need to copy the file |
| 103 |
contrib/examples/example_app/lwipcfg.h.example |
| 104 |
to |
| 105 |
contrib/examples/example_app/lwipcfg.h |
| 106 |
and edit to your needs. |
| 107 |
|
| 108 |
Makefile based build system |
| 109 |
=========================== |
| 110 |
lwIP also maintains file lists for Makefile-based |
| 111 |
build systems. Look for Filelists.mk files |
| 112 |
in the source tree. We try to maintain them, |
| 113 |
but lwIP's mainly focused build system is CMake. |
| 114 |
|
| 115 |
MS Visual Studio |
| 116 |
================ |
| 117 |
lwIP also provides basic support for MSVS in the win32 port |
| 118 |
folder under 'msvc'. We try to maintain these files, |
| 119 |
but lwIP's mainly focused build system is CMake. |