Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include(CheckCXXCompilerFlag)
# 1.2. zephyr_library_*
# 1.2.1 zephyr_interface_library_*
# 1.3. generate_inc_*
# 1.3.1 generate_config_*
# 1.4. board_*
# 1.5. Misc.
# 2. Kconfig-aware extensions
Expand Down Expand Up @@ -739,6 +740,79 @@ function(generate_inc_file_for_target
generate_inc_file_for_gen_target(${target} ${source_file} ${generated_file} ${generated_target_name} ${ARGN})
endfunction()

# 1.3.1 generate_config_*

# These functions are needed if a configuration file is generated
# from a user supplied yaml file.
#
function(generate_config_file
source_file # The yaml source file to be converted to config data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake indent is 2 spaces, also the functions are not documented like this in CMake and it goes in the bit above, see https://github.com/zephyrproject-rtos/zephyr/blob/main/cmake/modules/extensions.cmake#L1615 for an example

generated_file # The generated file
yaml_to_config_script # Script that generates the config
)
add_custom_command(
OUTPUT ${generated_file}
COMMAND
${PYTHON_EXECUTABLE}
${yaml_to_config_script}
${ARGN} # Extra arguments are passed to the script
< ${source_file}
> ${generated_file}
DEPENDS ${source_file}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endfunction()

function(generate_config_file_for_gen_target
target # The cmake target that depends on the generated file
source_file # The yaml source file to be converted to config data
generated_file # The generated file
gen_target # The generated file target we depend on
yaml_to_config_script # Script that generates the config
# Any additional arguments are passed on to script
)

generate_config_file(${source_file} ${generated_file} ${yaml_to_config_script} ${ARGN})

# Ensure 'generated_file' is generated before 'target' by creating a
# dependency between the two targets

add_dependencies(${target} ${gen_target})
endfunction()

function(generate_config_file_for_target
target # The cmake target that depends on the generated file
source_file # The yaml source file to be converted to config data
generated_file # The generated file
yaml_to_config_script # Script that generates the config
# Any additional arguments are passed on to script
)

# Ensure 'generated_file' is generated before 'target' by creating a
# 'custom_target' for it and setting up a dependency between the two
# targets

# But first create a unique name for the custom target
generate_unique_target_name_from_filename(${generated_file} generated_target_name)

add_custom_target(${generated_target_name} DEPENDS ${generated_file})
generate_config_file_for_gen_target(${target} ${source_file} ${generated_file}
${generated_target_name} ${yaml_to_config_script} ${ARGN})
endfunction()

function(network_generate_config_file_for_target
target # The cmake target that depends on the generated file
source_file # The yaml source file to be converted to config data
)

set(generated_file ${ZEPHYR_BINARY_DIR}/include/generated/network_config.inc)
set(yaml_to_config_script ${ZEPHYR_BASE}/scripts/net/net-yaml-config.py)
set(yaml_schema_file ${ZEPHYR_BASE}/scripts/schemas/network-configuration-schema.yml)

generate_config_file_for_target(${target} ${source_file} ${generated_file}
${yaml_to_config_script} ${yaml_schema_file})
endfunction()

# 1.4. board_*
#
# This section is for extensions related to Zephyr board handling.
Expand Down