From 2918437bb8a7a042702208109586c2939ce02227 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 17 Apr 2025 10:36:18 -0700 Subject: [PATCH] [build] enable `-Wundef` for MTD, FTD, and Radio builds (#11418) This commit adds the `-Wundef` compiler flag to the OpenThread core, CLI, and NCP builds when configured for MTD, FTD, or Radio types. This flag helps ensure that no undefined macros are used within the source code, protecting against potential typos in conditional compilation checks (`#if` checks). --- CMakeLists.txt | 6 ++++++ src/cli/ftd.cmake | 1 + src/cli/mtd.cmake | 1 + src/cli/radio.cmake | 1 + src/core/config/misc.h | 27 +++++++++++++++++++++++++++ src/core/ftd.cmake | 1 + src/core/mtd.cmake | 1 + src/core/radio.cmake | 1 + src/ncp/ftd.cmake | 1 + src/ncp/mtd.cmake | 1 + src/ncp/ncp_config.h | 9 +++++++++ 11 files changed, 50 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71eb77ead..f4500181d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,15 +122,21 @@ list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include) if(OT_PLATFORM STREQUAL "posix") target_include_directories(ot-config INTERFACE ${PROJECT_SOURCE_DIR}/src/posix/platform) target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_POSIX=1) + target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_NEXUS=0) add_subdirectory("${PROJECT_SOURCE_DIR}/src/posix/platform") elseif(OT_PLATFORM STREQUAL "external") + target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_POSIX=0) + target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_NEXUS=0) # skip in this case elseif(OT_PLATFORM STREQUAL "nexus") if (OT_APP_CLI OR OT_APP_NCP OR OT_APP_RCP) message(FATAL_ERROR "no app (cli/ncp/rcp) should be enabled with nexus simulation platform") endif() target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_NEXUS=1) + target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_POSIX=0) else() + target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_POSIX=0) + target_compile_definitions(ot-config INTERFACE OPENTHREAD_PLATFORM_NEXUS=0) target_include_directories(ot-config INTERFACE ${PROJECT_SOURCE_DIR}/examples/platforms/${OT_PLATFORM}) add_subdirectory("${PROJECT_SOURCE_DIR}/examples/platforms/${OT_PLATFORM}") endif() diff --git a/src/cli/ftd.cmake b/src/cli/ftd.cmake index 7b6f08a00..ce9966207 100644 --- a/src/cli/ftd.cmake +++ b/src/cli/ftd.cmake @@ -37,6 +37,7 @@ target_compile_definitions(openthread-cli-ftd target_compile_options(openthread-cli-ftd PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-cli-ftd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/cli/mtd.cmake b/src/cli/mtd.cmake index 733bfaaa9..f5f035f73 100644 --- a/src/cli/mtd.cmake +++ b/src/cli/mtd.cmake @@ -37,6 +37,7 @@ target_compile_definitions(openthread-cli-mtd target_compile_options(openthread-cli-mtd PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-cli-mtd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/cli/radio.cmake b/src/cli/radio.cmake index 47652d2c6..709a84ca8 100644 --- a/src/cli/radio.cmake +++ b/src/cli/radio.cmake @@ -38,6 +38,7 @@ target_compile_definitions(openthread-cli-radio target_compile_options(openthread-cli-radio PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-cli-radio PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/core/config/misc.h b/src/core/config/misc.h index f7e986830..fe5aaa62f 100644 --- a/src/core/config/misc.h +++ b/src/core/config/misc.h @@ -381,6 +381,15 @@ #define OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH "tmp" #endif +/** + * @def OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE + * + * Define to 1 to enable support reset to bootloader mode. + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE 0 +#endif + /** * @def OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE * @@ -590,6 +599,24 @@ #define OPENTHREAD_CONFIG_PLATFORM_LOG_CRASH_DUMP_ENABLE 0 #endif +/** + * @def OPENTHREAD_ENABLE_VENDOR_EXTENSION + * + * Define to 1 to enable vendor extension support. + */ +#ifndef OPENTHREAD_ENABLE_VENDOR_EXTENSION +#define OPENTHREAD_ENABLE_VENDOR_EXTENSION 0 +#endif + +/** + * @def OPENTHREAD_EXAMPLES_SIMULATION + * + * Define 1 to to enable simulation example support. + */ +#ifndef OPENTHREAD_EXAMPLES_SIMULATION +#define OPENTHREAD_EXAMPLES_SIMULATION 0 +#endif + /** * @} */ diff --git a/src/core/ftd.cmake b/src/core/ftd.cmake index 074c4362c..2e16087cd 100644 --- a/src/core/ftd.cmake +++ b/src/core/ftd.cmake @@ -36,6 +36,7 @@ target_compile_definitions(openthread-ftd PRIVATE target_compile_options(openthread-ftd PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-ftd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/core/mtd.cmake b/src/core/mtd.cmake index ae8d9e3ef..ebef0d3b4 100644 --- a/src/core/mtd.cmake +++ b/src/core/mtd.cmake @@ -36,6 +36,7 @@ target_compile_definitions(openthread-mtd PRIVATE target_compile_options(openthread-mtd PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-mtd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/core/radio.cmake b/src/core/radio.cmake index a41605202..001e54b8b 100644 --- a/src/core/radio.cmake +++ b/src/core/radio.cmake @@ -37,6 +37,7 @@ target_compile_definitions(openthread-radio PRIVATE target_compile_options(openthread-radio PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-radio PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/ncp/ftd.cmake b/src/ncp/ftd.cmake index 7255815f8..2b2a1c5d6 100644 --- a/src/ncp/ftd.cmake +++ b/src/ncp/ftd.cmake @@ -37,6 +37,7 @@ target_compile_definitions(openthread-ncp-ftd PRIVATE target_compile_options(openthread-ncp-ftd PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-ncp-ftd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/ncp/mtd.cmake b/src/ncp/mtd.cmake index b30a5759b..fb2955326 100644 --- a/src/ncp/mtd.cmake +++ b/src/ncp/mtd.cmake @@ -37,6 +37,7 @@ target_compile_definitions(openthread-ncp-mtd PRIVATE target_compile_options(openthread-ncp-mtd PRIVATE ${OT_CFLAGS} + -Wundef ) target_include_directories(openthread-ncp-mtd PUBLIC ${OT_PUBLIC_INCLUDES} PRIVATE ${COMMON_INCLUDES}) diff --git a/src/ncp/ncp_config.h b/src/ncp/ncp_config.h index 8fd34e07d..c60ee716f 100644 --- a/src/ncp/ncp_config.h +++ b/src/ncp/ncp_config.h @@ -207,4 +207,13 @@ #define OPENTHREAD_ENABLE_NCP_VENDOR_HOOK 0 #endif +/** + * @def OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER + * + * Define to 1 to enable NCP spinel encrypter. + */ +#ifndef OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER +#define OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER 0 +#endif + #endif // CONFIG_NCP_H_