Browse Source

cmake: move script mode handling from package helper to extensions.cmake

Move Zephyr CMake script mode handling from package_helper.cmake into
extensions.cmake.

This ensures that all Zephyr CMake script which includes
extensions.cmake will have the same functions stubbed or mocked and thus
does not need to replicate this behavior.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
pull/79568/head
Torsten Rasmussen 9 months ago committed by Carles Cufí
parent
commit
daac2d55ab
  1. 36
      cmake/modules/extensions.cmake
  2. 25
      cmake/package_helper.cmake

36
cmake/modules/extensions.cmake

@ -38,6 +38,7 @@ include(CheckCXXCompilerFlag) @@ -38,6 +38,7 @@ include(CheckCXXCompilerFlag)
# 7.1 llext_* configuration functions
# 7.2 add_llext_* build control functions
# 7.3 llext helper functions
# 8. Script mode handling
########################################################
# 1. Zephyr-aware extensions
@ -5759,3 +5760,38 @@ function(llext_filter_zephyr_flags filter flags outvar) @@ -5759,3 +5760,38 @@ function(llext_filter_zephyr_flags filter flags outvar)
set(${outvar} ${zephyr_filtered_flags} PARENT_SCOPE)
endfunction()
########################################################
# 8. Script mode handling
########################################################
#
# Certain features are not available when CMake is used in script mode.
# For example custom targets, and thus features related to custom targets, such
# as target properties are not available in script mode.
#
# This section defines behavior for functions whose default implementation does
# not work correctly in script mode.
#
# The script mode function can be a simple stub or a more complex solution
# depending on the exact use of the function in script mode.
#
# Current Zephyr CMake scripts which includes `extensions.cmake` in script mode
# are: package_helper.cmake, verify-toolchain.cmake
#
if(CMAKE_SCRIPT_MODE_FILE)
# add_custom_target and set_target_properties are not supported in script mode.
# However, Zephyr CMake functions like `zephyr_get()`, `zephyr_create_scope()`,
# llext functions creates or relies on custom CMake targets.
function(add_custom_target)
# This silence the error: 'add_custom_target command is not scriptable'
endfunction()
function(set_target_properties)
# This silence the error: 'set_target_properties command is not scriptable'
endfunction()
function(zephyr_set variable)
# This silence the error: zephyr_set(... SCOPE <scope>) doesn't exists.
endfunction()
endif()

25
cmake/package_helper.cmake

@ -44,20 +44,6 @@ @@ -44,20 +44,6 @@
cmake_minimum_required(VERSION 3.20.5)
# add_custom_target and set_target_properties are not supported in script mode.
# However, several Zephyr CMake modules create custom target for user convenience
# like menuconfig, boards, shields, etc.
# As we are not generating a build system with this tool, only running part of
# the modules, then we simply override those functions to allow running those
# modules.
function(add_custom_target)
# This silence the error: 'add_custom_target command is not scriptable'
endfunction()
function(set_target_properties)
# This silence the error: 'set_target_properties command is not scriptable'
endfunction()
# Find last `-B` and `-S` instances.
foreach(i RANGE ${CMAKE_ARGC})
if(CMAKE_ARGV${i} MATCHES "^-B(.*)")
@ -111,16 +97,5 @@ if(NOT DEFINED MODULES) @@ -111,16 +97,5 @@ if(NOT DEFINED MODULES)
)
endif()
# Loading Zephyr CMake extension commands, which allows us to overload Zephyr
# scoping rules.
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS extensions)
# Zephyr scoping creates custom targets for handling of properties.
# However, custom targets cannot be used in CMake script mode.
# Therefore disable zephyr_set(... SCOPE ...) in package helper as it is not needed.
function(zephyr_set variable)
# This silence the error: zephyr_set(... SCOPE <scope>) doesn't exists.
endfunction()
string(REPLACE ";" "," MODULES "${MODULES}")
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS zephyr_default:${MODULES})

Loading…
Cancel
Save