diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index f66af3c1c4048c2..19ddd9739815c8f 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -3357,7 +3357,12 @@ function(zephyr_get_scoped output scope variable) message(FATAL_ERROR "zephyr_get_scoped(): scope ${scope} doesn't exists.") endif() - get_property(value TARGET ${scope}_scope PROPERTY ${variable}) + if(CMAKE_SCRIPT_MODE_FILE) + set(kind SOURCE) + else() + set(kind TARGET) + endif() + get_property(value ${kind} ${scope}_scope PROPERTY ${variable}) set(${output} "${value}" PARENT_SCOPE) endfunction() @@ -3388,7 +3393,12 @@ function(zephyr_set variable) set(property_args APPEND) endif() - set_property(TARGET ${SET_VAR_SCOPE}_scope ${property_args} + if(CMAKE_SCRIPT_MODE_FILE) + set(kind SOURCE) + else() + set(kind TARGET) + endif() + set_property(${kind} ${SET_VAR_SCOPE}_scope ${property_args} PROPERTY ${variable} ${SET_VAR_UNPARSED_ARGUMENTS} ) endfunction() @@ -5909,10 +5919,6 @@ if(CMAKE_SCRIPT_MODE_FILE) # This silence the error: 'set_target_properties command is not scriptable' endfunction() - function(zephyr_set variable) - # This silence the error: zephyr_set(... SCOPE ) doesn't exists. - endfunction() - # Build info creates a custom target for handling of build info. # build_info is not needed in script mode but still called by Zephyr CMake # modules. Therefore disable build_info(...) in when including @@ -5921,4 +5927,27 @@ if(CMAKE_SCRIPT_MODE_FILE) # This silence the error: 'YAML context 'build_info' does not exist.' # 'Remember to create a YAML context' endfunction() + + # Script mode version, using SOURCE properties + function(zephyr_create_scope scope) + zephyr_exists_scope(scope_exists ${scope}) + if(scope_exists) + message(FATAL_ERROR "zephyr_create_scope(${scope}) already exists.") + endif() + + set_property(SOURCE ${scope}_scope PROPERTY ZEPHYR_SCOPE TRUE) + endfunction() + + # Script mode version, using SOURCE properties + macro(zephyr_exists_scope output scope) + get_property(zephyr_exists_scope_value SOURCE ${scope}_scope PROPERTY ZEPHYR_SCOPE) + if(DEFINED zephyr_exists_scope_value) + unset(zephyr_exists_scope_value) + set(${output} TRUE) + else() + set(${output} FALSE) + endif() + endmacro() + + # zephyr_get_scoped and zephyr_set support script mode as well endif()