[PATCH] CMake support for the STM32 lwIP addition

Robin Mueller robin.mueller.m at gmail.com
Tue Apr 27 17:55:26 UTC 2021


This patch adds full CMake support for the lwIP support.
It can be easily extended to other architectures as well.

More information can also be found in the README, which also specifies
how to build with CMake. The waf build system still needs to be adapted
to perform the same function.
---
 CMakeLists.txt                                | 76 +++++++++++++++++++
 README.md                                     |  9 +++
 cmake/PortSelect.cmake                        | 12 +++
 lwip/CMakeLists.txt                           |  2 +
 lwip/ports/CMakeLists.txt                     |  2 +
 lwip/ports/drivers/CMakeLists.txt             | 20 +++++
 lwip/ports/drivers/stm32h7/CMakeLists.txt     | 14 ++++
 .../drivers/stm32h7/include/CMakeLists.txt    |  7 ++
 lwip/ports/drivers/tms570/CMakeLists.txt      |  4 +
 lwip/ports/os/CMakeLists.txt                  |  1 +
 lwip/ports/os/rtems/CMakeLists.txt            |  9 +++
 lwip/ports/os/rtems/arch/CMakeLists.txt       |  4 +
 lwip/src/CMakeLists.txt                       |  4 +
 lwip/src/api/CMakeLists.txt                   | 11 +++
 lwip/src/core/CMakeLists.txt                  | 28 +++++++
 lwip/src/core/ipv4/CMakeLists.txt             | 10 +++
 lwip/src/core/ipv6/CMakeLists.txt             | 11 +++
 lwip/src/include/CMakeLists.txt               |  7 ++
 lwip/src/netif/CMakeLists.txt                 | 10 +++
 19 files changed, 241 insertions(+)
 create mode 100644 CMakeLists.txt
 create mode 100644 cmake/PortSelect.cmake
 create mode 100644 lwip/CMakeLists.txt
 create mode 100644 lwip/ports/CMakeLists.txt
 create mode 100644 lwip/ports/drivers/CMakeLists.txt
 create mode 100644 lwip/ports/drivers/stm32h7/CMakeLists.txt
 create mode 100644 lwip/ports/drivers/stm32h7/include/CMakeLists.txt
 create mode 100644 lwip/ports/drivers/tms570/CMakeLists.txt
 create mode 100644 lwip/ports/os/CMakeLists.txt
 create mode 100644 lwip/ports/os/rtems/CMakeLists.txt
 create mode 100644 lwip/ports/os/rtems/arch/CMakeLists.txt
 create mode 100644 lwip/src/CMakeLists.txt
 create mode 100644 lwip/src/api/CMakeLists.txt
 create mode 100644 lwip/src/core/CMakeLists.txt
 create mode 100644 lwip/src/core/ipv4/CMakeLists.txt
 create mode 100644 lwip/src/core/ipv6/CMakeLists.txt
 create mode 100644 lwip/src/include/CMakeLists.txt
 create mode 100644 lwip/src/netif/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..59cc7e9
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,76 @@
+#################################################################################
+# CMake support for RTEMS lwIP
+#
+# Author: R.Mueller
+#################################################################################
+cmake_minimum_required(VERSION 3.13)
+
+#################################################################################
+# lwIP options
+#################################################################################
+
+option(LWIP_GENERATE_SECTIONS "Generate function and data sections" ON)
+if(LWIP_GENERATE_SECTIONS)
+    option(LWIP_REMOVE_UNUSED_CODE "Remove unused sections" ON)
+endif()
+
+option(LWIP_ADD_IPV6 "Compile IPv6 sourcces" ON)
+
+#################################################################################
+# Port select
+#################################################################################
+
+if(NOT RTEMS_BSP)
+    message(
+        FATAL_ERROR "RTEMS BSP variable not set. "
+        "Please make sure to pass it with -DRTEMS_BSP=<arch/bsp>"
+   )
+endif()
+
+set(LWIP_CMAKE_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+include("${LWIP_CMAKE_CONFIG_DIR}/PortSelect.cmake")
+
+rtems_lwip_port_select(${RTEMS_BSP})
+
+set(LIB_LWIP_NAME lwip)
+add_library(${LIB_LWIP_NAME})
+
+add_subdirectory(lwip)
+
+# The user needs to supply the lwipopts.h file. The user can do this by supplying the
+# path of this file in the LWIP_CONFIG_PATH variable
+if(NOT LWIP_CONFIG_PATH)
+	message(WARNING "lwIP configuration include path LWIP_CONFIG_PATH not set!")
+endif()
+
+if(IS_ABSOLUTE ${LWIP_CONFIG_PATH})
+	set(LWIP_CONFIG_PATH_ABS "${LWIP_CONFIG_PATH}")
+else()
+	get_filename_component(LWIP_CONFIG_PATH_ABS
+		${LWIP_CONFIG_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR}
+	)
+endif()
+
+if(CMAKE_VERBOSE)
+	message(STATUS "lwIP configuration path: ${LWIP_CONFIG_PATH}")
+endif()
+
+target_include_directories(${LIB_LWIP_NAME} PRIVATE
+	${LWIP_CONFIG_PATH_ABS}
+)
+
+# Remove unused sections
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    if(LWIP_GENERATE_SECTIONS)
+        target_compile_options(${LIB_LWIP_NAME} PRIVATE
+            "-ffunction-sections"
+            "-fdata-sections"
+        )
+    endif()
+
+    if(LWIP_REMOVE_UNUSED_CODE)
+        target_link_options(${LIB_LWIP_NAME} PRIVATE
+            "Wl,--gc-sections"
+        )
+    endif()
+endif()
diff --git a/README.md b/README.md
index e789219..e4b0060 100644
--- a/README.md
+++ b/README.md
@@ -19,5 +19,14 @@ and then pass the include path to the build system.
 
 # Compiling with CMake
 
+It is recommended to add this repository as a submodule. After that, you can use
+`add_subdirectory` to add the repository and then link against the `lwip` target.
+
+Following steps have to be taken by the application `CMakeLists.txt` for this to work:
+
+ 1. The CMake variable `RTEMS_BSP` has to be set to the used BSP
+ 2. The CMake variable `LWIP_CONFIG_PATH` needs to be set to the path including the `lwipopts.h`
+    configuration file which is provided by the user.
+
 # Compiling with waf
 
diff --git a/cmake/PortSelect.cmake b/cmake/PortSelect.cmake
new file mode 100644
index 0000000..3f440f8
--- /dev/null
+++ b/cmake/PortSelect.cmake
@@ -0,0 +1,12 @@
+function(rtems_lwip_port_select RTEMS_BSP)
+    if(RTEMS_BSP MATCHES "arm/nucleo-h743zi" OR RTEMS_BSP MATCHES "arm/stm32h7")
+        set(RTEMS_LWIP_ADD_STM32H7_DRV ON CACHE INTERNAL "Add STM32H7 lwIP drivers")
+        if(RTEMS_BSP MATCHES "arm/nucleo-h743zi")
+            set(RTEMS_LWIP_NUCLEO_H743ZI_VARIANT ON CACHE INTERNAL "Nucleo-H743ZI board variant")
+        endif()
+    endif()
+
+    if(RTEMS_BSP MATCHES "arm/tms570")
+        set(RTEMS_LWIP_ADD_TMS_570_DRV ON CACHE INTERNAL "Add TMS570 lwIP drivers")
+    endif()
+endfunction()
diff --git a/lwip/CMakeLists.txt b/lwip/CMakeLists.txt
new file mode 100644
index 0000000..69cffec
--- /dev/null
+++ b/lwip/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(ports)
+add_subdirectory(src)
diff --git a/lwip/ports/CMakeLists.txt b/lwip/ports/CMakeLists.txt
new file mode 100644
index 0000000..ecb2e95
--- /dev/null
+++ b/lwip/ports/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(os)
+add_subdirectory(drivers)
diff --git a/lwip/ports/drivers/CMakeLists.txt b/lwip/ports/drivers/CMakeLists.txt
new file mode 100644
index 0000000..d060385
--- /dev/null
+++ b/lwip/ports/drivers/CMakeLists.txt
@@ -0,0 +1,20 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+    rtems_lwip.c
+)
+
+if(RTEMS_LWIP_ADD_TMS_570_DRV)
+    add_subdirectory(tms570)
+endif()
+
+if(RTEMS_LWIP_ADD_STM32H7_DRV)
+    option(RTEMS_LWIP_NUCLEO_H743ZI_VARIANT OFF "Can be set for Nucleo H743 ZI board variant")
+    add_subdirectory(stm32h7)
+endif()
+
+target_include_directories(${LIB_LWIP_NAME} PRIVATE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+target_include_directories(${LIB_LWIP_NAME} INTERFACE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
diff --git a/lwip/ports/drivers/stm32h7/CMakeLists.txt b/lwip/ports/drivers/stm32h7/CMakeLists.txt
new file mode 100644
index 0000000..b977008
--- /dev/null
+++ b/lwip/ports/drivers/stm32h7/CMakeLists.txt
@@ -0,0 +1,14 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+    lan8742.c
+    app_dhcp.c
+    app_ethernet.c
+    ethernetif.c
+)
+
+if(RTEMS_LWIP_NUCLEO_H743ZI_VARIANT)
+    target_compile_definitions(${LIB_LWIP_NAME} PRIVATE
+        NUCLEO_H743ZI=1
+    )
+endif()
+
+add_subdirectory(include)
\ No newline at end of file
diff --git a/lwip/ports/drivers/stm32h7/include/CMakeLists.txt b/lwip/ports/drivers/stm32h7/include/CMakeLists.txt
new file mode 100644
index 0000000..9601437
--- /dev/null
+++ b/lwip/ports/drivers/stm32h7/include/CMakeLists.txt
@@ -0,0 +1,7 @@
+target_include_directories(${LIB_LWIP_NAME} PRIVATE
+    lwip_port
+)
+
+target_include_directories(${LIB_LWIP_NAME} INTERFACE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
diff --git a/lwip/ports/drivers/tms570/CMakeLists.txt b/lwip/ports/drivers/tms570/CMakeLists.txt
new file mode 100644
index 0000000..bf237b5
--- /dev/null
+++ b/lwip/ports/drivers/tms570/CMakeLists.txt
@@ -0,0 +1,4 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+    tms570_netif.c
+    phy_dp83848h.c
+)
diff --git a/lwip/ports/os/CMakeLists.txt b/lwip/ports/os/CMakeLists.txt
new file mode 100644
index 0000000..8fb3d8e
--- /dev/null
+++ b/lwip/ports/os/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(rtems)
diff --git a/lwip/ports/os/rtems/CMakeLists.txt b/lwip/ports/os/rtems/CMakeLists.txt
new file mode 100644
index 0000000..0a3e451
--- /dev/null
+++ b/lwip/ports/os/rtems/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_subdirectory(arch)
+
+target_include_directories(${LIB_LWIP_NAME} PRIVATE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+target_include_directories(${LIB_LWIP_NAME} INTERFACE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
diff --git a/lwip/ports/os/rtems/arch/CMakeLists.txt b/lwip/ports/os/rtems/arch/CMakeLists.txt
new file mode 100644
index 0000000..8d30c51
--- /dev/null
+++ b/lwip/ports/os/rtems/arch/CMakeLists.txt
@@ -0,0 +1,4 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+    sys_arch.c
+)
+
diff --git a/lwip/src/CMakeLists.txt b/lwip/src/CMakeLists.txt
new file mode 100644
index 0000000..32c2a14
--- /dev/null
+++ b/lwip/src/CMakeLists.txt
@@ -0,0 +1,4 @@
+add_subdirectory(api)
+add_subdirectory(core)
+add_subdirectory(netif)
+add_subdirectory(include)
diff --git a/lwip/src/api/CMakeLists.txt b/lwip/src/api/CMakeLists.txt
new file mode 100644
index 0000000..7150ade
--- /dev/null
+++ b/lwip/src/api/CMakeLists.txt
@@ -0,0 +1,11 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+	api_lib.c
+	api_msg.c
+	err.c
+	if_api.c
+	netbuf.c
+	netdb.c
+	netifapi.c
+	sockets.c
+	tcpip.c
+)
diff --git a/lwip/src/core/CMakeLists.txt b/lwip/src/core/CMakeLists.txt
new file mode 100644
index 0000000..f7f17a7
--- /dev/null
+++ b/lwip/src/core/CMakeLists.txt
@@ -0,0 +1,28 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+	altcp_alloc.c
+	altcp_tcp.c
+	altcp.c
+	def.c
+	dns.c
+	inet_chksum.c
+	init.c
+	ip.c
+	mem.c
+	memp.c
+	netif.c
+	pbuf.c
+	raw.c
+	stats.c
+	sys.c
+	tcp_in.c
+	tcp_out.c
+	tcp.c
+	timeouts.c
+	udp.c
+)
+
+add_subdirectory(ipv4)
+
+if(LWIP_ADD_IPV6)
+    add_subdirectory(ipv6)
+endif()
diff --git a/lwip/src/core/ipv4/CMakeLists.txt b/lwip/src/core/ipv4/CMakeLists.txt
new file mode 100644
index 0000000..a47fa5d
--- /dev/null
+++ b/lwip/src/core/ipv4/CMakeLists.txt
@@ -0,0 +1,10 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+	autoip.c
+	dhcp.c
+	etharp.c
+	icmp.c
+	igmp.c
+	ip4_addr.c
+	ip4_frag.c
+	ip4.c
+)
diff --git a/lwip/src/core/ipv6/CMakeLists.txt b/lwip/src/core/ipv6/CMakeLists.txt
new file mode 100644
index 0000000..391a05b
--- /dev/null
+++ b/lwip/src/core/ipv6/CMakeLists.txt
@@ -0,0 +1,11 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+	ethip6.c
+	dhcp6.c
+	icmp6.c
+	inet6.c
+	ip6_addr.c
+	ip6_frag.c
+	ip6.c
+	mld6.c
+	nd6.c
+)
diff --git a/lwip/src/include/CMakeLists.txt b/lwip/src/include/CMakeLists.txt
new file mode 100644
index 0000000..a009324
--- /dev/null
+++ b/lwip/src/include/CMakeLists.txt
@@ -0,0 +1,7 @@
+target_include_directories(${LIB_LWIP_NAME} PRIVATE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+target_include_directories(${LIB_LWIP_NAME} INTERFACE
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
diff --git a/lwip/src/netif/CMakeLists.txt b/lwip/src/netif/CMakeLists.txt
new file mode 100644
index 0000000..47f7242
--- /dev/null
+++ b/lwip/src/netif/CMakeLists.txt
@@ -0,0 +1,10 @@
+target_sources(${LIB_LWIP_NAME} PRIVATE
+	bridgeif_fdb.c
+	bridgeif.c
+	ethernet.c
+	lowpan6_ble.c
+	lowpan6_common.c
+	lowpan6.c
+	slipif.c
+	zepif.c
+)
-- 
2.27.0



More information about the devel mailing list