From 0d457cda40d3a8dcbbba5b530d3aac048f70cc15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Wed, 21 Oct 2026 10:16:20 -0400 Subject: [PATCH] Fixed no-chain CMake builds for NetX Duo Fixes #475 Defining NX_DISABLE_PACKET_CHAIN in nx_user.h removes packet-link fields, but CMake still compiled MQTT, WebSocket, RTP, and NetX Secure. CMake now detects the setting, disables fragmentation, and excludes components that require packet chaining. It also provides options to select this build or omit all add-ons and NetX Secure. The no-chain tests use the same source set. Cortex-M7 GNU 14.2.1/Ninja builds passed with the macro in nx_user.h and with the CMake option: 793/793 build steps and zero warnings in each. GCC 14.3 host builds passed for the default, no-chain, and add-ons-disabled configurations. Assisted-by: Codex (GPT-6) --- CMakeLists.txt | 53 ++++++++++++++++++++-------- README.md | 2 ++ addons/CMakeLists.txt | 8 +++++ nx_secure/CMakeLists.txt | 2 ++ test/cmake/netxduo/CMakeLists.txt | 8 +++-- test/cmake/netxduo/additionals.cmake | 22 ------------ utility/CMakeLists.txt | 4 +-- 7 files changed, 58 insertions(+), 41 deletions(-) delete mode 100644 test/cmake/netxduo/additionals.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index eb767bbb5..00ad2e21a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,33 @@ endif() option(NXD_ENABLE_FILE_SERVERS "Includes a dependency on FileX to support 'server' protocol handlers" ON) option(NXD_ENABLE_AZURE_IOT "Enable Azure IoT" OFF) +option(NXD_ENABLE_ADDONS "Build NetX Duo add-on modules" ON) +option(NXD_ENABLE_NX_SECURE "Build NetX Secure when packet chaining is enabled" ON) +option(NXD_DISABLE_PACKET_CHAIN "Build without packet chaining" OFF) + +set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc) +if(NOT NX_USER_FILE) + message(STATUS "Using default nx_user.h file") + set(NX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/common/inc/nx_user_sample.h) +else() + message(STATUS "Using custom nx_user.h file from ${NX_USER_FILE}") +endif() +configure_file(${NX_USER_FILE} ${CUSTOM_INC_DIR}/nx_user.h COPYONLY) + +include(CheckCSourceCompiles) +set(NXD_SAVED_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}) +set(CMAKE_REQUIRED_INCLUDES ${CUSTOM_INC_DIR}) +unset(NXD_USER_DISABLE_PACKET_CHAIN CACHE) +check_c_source_compiles("#include \"nx_user.h\" +#ifndef NX_DISABLE_PACKET_CHAIN +#error Packet chaining is enabled +#endif +int main(void) { return 0; }" NXD_USER_DISABLE_PACKET_CHAIN) +set(CMAKE_REQUIRED_INCLUDES ${NXD_SAVED_REQUIRED_INCLUDES}) + +if(NXD_DISABLE_PACKET_CHAIN OR NXD_USER_DISABLE_PACKET_CHAIN) + set(NXD_NO_PACKET_CHAIN ON) +endif() if(NOT DEFINED THREADX_ARCH) message(FATAL_ERROR "Error: THREADX_ARCH not defined") @@ -26,22 +53,26 @@ endif() add_library(${PROJECT_NAME}) add_library("azrtos::${PROJECT_NAME}" ALIAS ${PROJECT_NAME}) +if(NXD_NO_PACKET_CHAIN) + target_compile_definitions(${PROJECT_NAME} PUBLIC NX_DISABLE_FRAGMENTATION) + if(NXD_DISABLE_PACKET_CHAIN AND NOT NXD_USER_DISABLE_PACKET_CHAIN) + target_compile_definitions(${PROJECT_NAME} PUBLIC NX_DISABLE_PACKET_CHAIN) + endif() +endif() + # Define any required dependencies between this library and others target_link_libraries(${PROJECT_NAME} PUBLIC "azrtos::threadx") -if(NXD_ENABLE_FILE_SERVERS) +if(NXD_ENABLE_ADDONS AND NXD_ENABLE_FILE_SERVERS) message(STATUS "NXD_ENABLE_FILE_SERVERS - defined") target_link_libraries(${PROJECT_NAME} PUBLIC "azrtos::filex") endif() -if(NXD_ENABLE_AZURE_IOT) +if(NXD_ENABLE_ADDONS AND NXD_ENABLE_AZURE_IOT) message(STATUS "NXD_ENABLE_AZURE_IOT - defined") target_link_libraries(${PROJECT_NAME} PUBLIC az_iot_hub az_iot_provisioning) endif() -# A place for generated/copied include files (no need to change) -set(CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/custom_inc) - # Pick up the port specific stuff first if(DEFINED NETXDUO_CUSTOM_PORT) add_subdirectory(${NETXDUO_CUSTOM_PORT} netxduo_port) @@ -53,7 +84,9 @@ endif() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/common) # Pick up the apps directory containing the protocol and app-layer components -add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/addons) +if(NXD_ENABLE_ADDONS) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/addons) +endif() # Network security and crypto components add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/crypto_libraries) @@ -65,14 +98,6 @@ add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/utility) # Link layer add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tsn) -# If the user provided an override, copy it to the custom directory -if (NOT NX_USER_FILE) - message(STATUS "Using default nx_user.h file") - set(NX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/common/inc/nx_user_sample.h) -else() - message(STATUS "Using custom nx_user.h file from ${NX_USER_FILE}") -endif() -configure_file(${NX_USER_FILE} ${CUSTOM_INC_DIR}/nx_user.h COPYONLY) target_include_directories(${PROJECT_NAME} PUBLIC ${CUSTOM_INC_DIR} diff --git a/README.md b/README.md index 00a8955bd..86c97b4c0 100755 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ Instruction for building the NetX Duo as static library using Arm GNU Toolchain $ cmake --build ./build ``` + Defining `NX_DISABLE_PACKET_CHAIN` in `nx_user.h` makes CMake omit MQTT, WebSocket, RTP, and NetX Secure, which require packet chaining. CMake also disables IP fragmentation. Set `NXD_DISABLE_PACKET_CHAIN=ON` to select the same configuration without editing `nx_user.h`. Set `NXD_ENABLE_ADDONS=OFF` to omit all add-ons, or `NXD_ENABLE_NX_SECURE=OFF` to omit NetX Secure independently. + ## Licensing License terms for using Eclipse ThreadX are defined in the LICENSE.txt file of this repo. Please refer to this file for all definitive licensing information for all content, incl. the history of this repo. diff --git a/addons/CMakeLists.txt b/addons/CMakeLists.txt index ce6a528e8..680fdfd2b 100644 --- a/addons/CMakeLists.txt +++ b/addons/CMakeLists.txt @@ -74,6 +74,14 @@ if(NOT NXD_ENABLE_FILE_SERVERS) ) endif() +if(NXD_NO_PACKET_CHAIN) + list(REMOVE_ITEM SOURCES + "${CMAKE_CURRENT_LIST_DIR}/mqtt/nxd_mqtt_client.c" + "${CMAKE_CURRENT_LIST_DIR}/websocket/nx_websocket_client.c" + "${CMAKE_CURRENT_LIST_DIR}/rtp/nx_rtp_sender.c" + ) +endif() + target_sources(${PROJECT_NAME} PRIVATE ${SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC diff --git a/nx_secure/CMakeLists.txt b/nx_secure/CMakeLists.txt index f9599ddb0..4ac03d945 100644 --- a/nx_secure/CMakeLists.txt +++ b/nx_secure/CMakeLists.txt @@ -1,3 +1,4 @@ +if(NXD_ENABLE_NX_SECURE AND NOT NXD_NO_PACKET_CHAIN) target_sources(${PROJECT_NAME} PRIVATE # {{BEGIN_TARGET_SOURCES}} @@ -309,6 +310,7 @@ target_sources(${PROJECT_NAME} # {{END_TARGET_SOURCES}} ) +endif() target_include_directories(${PROJECT_NAME} PUBLIC diff --git a/test/cmake/netxduo/CMakeLists.txt b/test/cmake/netxduo/CMakeLists.txt index 11cd23373..e2895c5b0 100644 --- a/test/cmake/netxduo/CMakeLists.txt +++ b/test/cmake/netxduo/CMakeLists.txt @@ -407,13 +407,15 @@ if(MSVC) add_subdirectory(${FILEX_SOURCE_DIR} filex_build) endif() +if(CMAKE_BUILD_TYPE STREQUAL "v4_no_chain_build" OR + CMAKE_BUILD_TYPE STREQUAL "v6_no_chain_build") + set(NXD_DISABLE_PACKET_CHAIN ON) +endif() + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../.. ${PRODUCT}) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/regression regression) if(NOT MSVC AND NOT "$ENV{ENABLE_64}") add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/samples samples) - if(PRODUCT STREQUAL netxduo) - include(additionals.cmake) - endif() endif() # Coverage instrumentation (GCC/Clang only — not supported by MSVC) diff --git a/test/cmake/netxduo/additionals.cmake b/test/cmake/netxduo/additionals.cmake deleted file mode 100644 index 31caa8371..000000000 --- a/test/cmake/netxduo/additionals.cmake +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR) - -# See https://cmake.org/cmake/help/latest/policy/CMP0079.html for more info -cmake_policy(SET CMP0079 NEW) - -target_include_directories(netxduo PUBLIC ${SOURCE_DIR}) - -get_target_property(SOURCES_LIST netxduo SOURCES) -get_target_property(SOURCE_DIR netxduo SOURCE_DIR) - -if("-DNX_DISABLE_PACKET_CHAIN" IN_LIST ${CMAKE_BUILD_TYPE}) - # Remove nx_secure from build - aux_source_directory(${SOURCE_DIR}/nx_secure/src SECURE_SOURCES) - list(REMOVE_ITEM SOURCES_LIST ${SECURE_SOURCES}) - # Remove MQTT from build - list(REMOVE_ITEM SOURCES_LIST ${SOURCE_DIR}/addons/mqtt/nxd_mqtt_client.c) - # Remove WebSocket from build - list(REMOVE_ITEM SOURCES_LIST ${SOURCE_DIR}/addons/websocket/nx_websocket_client.c) - # Remove RTP from build - list(REMOVE_ITEM SOURCES_LIST ${SOURCE_DIR}/addons/rtp/nx_rtp_sender.c) -endif() -set_target_properties(netxduo PROPERTIES SOURCES "${SOURCES_LIST}") diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index 99f6e16e9..7d0df2326 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -1,7 +1,7 @@ # Each protocol handler is listed below. If you want # to disable some / all of these, comment out the block(s) in question -if(NXD_ENABLE_FILE_SERVERS) +if(NXD_ENABLE_FILE_SERVERS AND NXD_ENABLE_ADDONS) target_sources(${PROJECT_NAME} PRIVATE # {{BEGIN_TARGET_SOURCES}} @@ -13,4 +13,4 @@ if(NXD_ENABLE_FILE_SERVERS) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/iperf ) -endif() \ No newline at end of file +endif()