modules: hal_nxp: mcux-sdk-ng: Fix cmake variable scope error

The CMakeLists.txt files in folders modules/hal_nxp/mcux/mcux-sdk-ng/*/
are loaded in modules/hal_nxp/mcux/mcux-sdk-ng/CMakeLists.txt using
cmake function `add_subdirectory`.

One issue is, when variables defined in one CMakeLists.txt are needed
by another CMakeLists.txt, then the variables need be exposed to parent
scope. This is not convenient.

Another issue is, to expose variables, the function `set_variable_ifdef`
sets the variables as global variables. The CMake global variables
named `CONFIG_xxx` will be collected by Kconfig, and results in build
fail.

The solution is:
1. Replace `add_subdirectory` with `include`, so that the variables will
be in the same file scope, don't need to expose them.
2. Modify the implementation of `set_variable_ifdef`, don't set
variables as global variables.

Resolves #88135

Signed-off-by: Jason Yu <zejiang.yu@nxp.com>
This commit is contained in:
Jason Yu 2025-04-06 21:01:16 +08:00 committed by Benjamin Cabé
commit 530f9163db
5 changed files with 24 additions and 30 deletions

View file

@ -11,6 +11,12 @@ include(${MCUX_SDK_NG_DIR}/cmake/extension/logging.cmake)
include(${MCUX_SDK_NG_DIR}/cmake/extension/function.cmake)
include(${MCUX_SDK_NG_DIR}/cmake/extension/basic_settings_lite.cmake)
function(set_variable_ifdef feature_toggle variable)
if(${${feature_toggle}})
set(${variable} ON PARENT_SCOPE)
endif()
endfunction()
#specific operation to shared drivers
if((DEFINED CONFIG_FLASH_MCUX_FLEXSPI_XIP) AND (DEFINED CONFIG_FLASH))
zephyr_code_relocate(FILES ${MCUX_SDK_NG_DIR}/drivers/flexspi/fsl_flexspi.c
@ -28,10 +34,10 @@ if((${MCUX_DEVICE} MATCHES "RW61") AND (NOT DEFINED CONFIG_MINIMAL_LIBC))
zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/mcux/mcux-sdk-ng/components/misc_utilities/fsl_memcpy.S)
endif()
add_subdirectory(middleware)
add_subdirectory(components)
add_subdirectory(drivers)
add_subdirectory(device)
include(middleware/middleware.cmake)
include(components/components.cmake)
include(drivers/drivers.cmake)
include(device/device.cmake)
# Expose the driver header include path, so that the shim driver can use them.
get_target_property(MCUXSDK_INCLUDE_DIRS ${MCUX_SDK_PROJECT_NAME} INTERFACE_INCLUDE_DIRECTORIES)

View file

@ -16,7 +16,7 @@ if(${MCUX_DEVICE} MATCHES "RW61")
if(CONFIG_NXP_FW_LOADER)
set(CONFIG_MCUX_COMPONENT_component.mflash_offchip ON)
set(CONFIG_MCUX_COMPONENT_driver.cache_cache64 ON)
set(CONFIG_MCUX_COMPONENT_driver.flexspi ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.flexspi ON)
endif()
endif()

View file

@ -2,12 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
function(set_variable_ifdef feature_toggle variable)
if(${${feature_toggle}})
set(${variable} ON CACHE INTERNAL "global variable")
endif()
endfunction()
# fsl_common driver
zephyr_library_sources(${MCUX_SDK_NG_DIR}/drivers/common/fsl_common.c
${MCUX_SDK_NG_DIR}/drivers/common/fsl_common_arm.c)
@ -190,7 +184,7 @@ endif()
if(CONFIG_SOC_MK82F25615 OR CONFIG_SOC_MK64F12 OR CONFIG_SOC_MK66F18 OR
CONFIG_SOC_MKE14F16 OR CONFIG_SOC_MKE16F16 OR CONFIG_SOC_MKE18F16 OR
CONFIG_SOC_MK22F12)
set(CONFIG_MCUX_COMPONENT_driver.sysmpu ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.sysmpu ON)
endif()
if(CONFIG_SOC_SERIES_MCXW)
@ -215,7 +209,7 @@ if(CONFIG_SOC_SERIES_LPC55XXX)
endif()
if(CONFIG_SOC_SERIES_LPC51U68 OR CONFIG_SOC_SERIES_LPC54XXX OR CONFIG_SOC_SERIES_LPC55XXX)
set(CONFIG_MCUX_COMPONENT_driver.lpc_iocon ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.lpc_iocon ON)
endif()
if(CONFIG_SOC_LPC55S36)
@ -224,11 +218,11 @@ if(CONFIG_SOC_LPC55S36)
endif()
if(CONFIG_SOC_SERIES_IMXRT5XX OR CONFIG_SOC_SERIES_IMXRT6XX)
set(CONFIG_MCUX_COMPONENT_driver.lpc_iopctl ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.lpc_iopctl ON)
endif()
if(CONFIG_SOC_SERIES_RW6XX)
set(CONFIG_MCUX_COMPONENT_driver.ocotp_rw61x ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.ocotp_rw61x ON)
endif()
if(CONFIG_SOC_SERIES_IMXRT10XX)
@ -238,24 +232,24 @@ if(CONFIG_SOC_SERIES_IMXRT10XX)
endif()
if(CONFIG_SOC_SERIES_IMXRT11XX)
set(CONFIG_MCUX_COMPONENT_driver.romapi ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.anadig_pmu ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.pgmc ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.dcdc_2 ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.anatop_ai ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.gpc_xxx_ctrl ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.romapi ON)
set(CONFIG_MCUX_COMPONENT_driver.anadig_pmu ON)
set(CONFIG_MCUX_COMPONENT_driver.pgmc ON)
set(CONFIG_MCUX_COMPONENT_driver.dcdc_2 ON)
set(CONFIG_MCUX_COMPONENT_driver.anatop_ai ON)
set(CONFIG_MCUX_COMPONENT_driver.gpc_xxx_ctrl ON)
set_variable_ifdef(CONFIG_VIDEO_MCUX_MIPI_CSI2RX CONFIG_MCUX_COMPONENT_driver.mipi_csi2rx_soc)
endif()
if(CONFIG_SOC_SERIES_IMXRT118X)
set(CONFIG_MCUX_COMPONENT_driver.ele_base_api ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.anadig_pmu_1 ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.ele_base_api ON)
set(CONFIG_MCUX_COMPONENT_driver.anadig_pmu_1 ON)
set_variable_ifdef(CONFIG_HWINFO_MCUX_SRC_V2 CONFIG_MCUX_COMPONENT_driver.src_3)
set_variable_ifdef(CONFIG_WDT_MCUX_RTWDOG CONFIG_MCUX_COMPONENT_driver.src_3)
endif()
if(CONFIG_SOC_SERIES_MCXA)
set(CONFIG_MCUX_COMPONENT_driver.romapi ON PARENT_SCOPE)
set(CONFIG_MCUX_COMPONENT_driver.romapi ON)
endif()
if(CONFIG_SOC_SERIES_MCXN)

View file

@ -2,12 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
function(set_variable_ifdef feature_toggle variable)
if(${${feature_toggle}})
set(${variable} ON CACHE INTERNAL "global variable")
endif()
endfunction()
if(CONFIG_USB_DEVICE_DRIVER)
zephyr_include_directories(middleware)