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
26 changes: 26 additions & 0 deletions cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,26 @@
target_sources(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${source} ${ARGN})
endfunction()

#
# Use this function to add source files to a zephyr library in a module.
# This should be used with zephyr_library_amend() and ensures that same sources
# are added only once and in the right order.
#
function(zephyr_library_sources_amend source)
get_target_property(CURRENT_SOURCES ${ZEPHYR_CURRENT_LIBRARY} SOURCES)
get_filename_component(sourcex ${source} NAME)
list(FIND CURRENT_SOURCES ${sourcex} _index)
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on how these source files are added to the target, they can be absolute.

Also consider some existing library

zephyr_library_sources(
  subdir/sensor_x.c
)

You can't amend your own sensor_x.c as it won't match with any entry in the sources list.

Copy link
Member Author

Choose a reason for hiding this comment

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

Depending on how these source files are added to the target, they can be absolute.

thats why I compare with the file name component, not the full path.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant for CURRENT_SOURCES.

Copy link
Member Author

Choose a reason for hiding this comment

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

i see what you mean

if(_index EQUAL -1)
# Source file not found, add it
target_sources(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${source} ${ARGN})
else()
# replace the source file with the new one
list(REMOVE_AT CURRENT_SOURCES ${_index})
set_target_properties(${ZEPHYR_CURRENT_LIBRARY} PROPERTIES SOURCES "${CURRENT_SOURCES}")
target_sources(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${source} ${ARGN})
endif()
endfunction()

function(zephyr_library_include_directories)
target_include_directories(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${ARGN})
endfunction()
Expand Down Expand Up @@ -563,7 +583,7 @@
string(MD5 uniqueness "${ARGV}")
set(lib_name options_interface_lib_${uniqueness})

if (NOT TARGET ${lib_name})

Check failure on line 586 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:586 CMakeStyle
# Create the unique target only if it doesn't exist.
add_library( ${lib_name} INTERFACE)
target_compile_options(${lib_name} INTERFACE ${item} ${ARGN})
Expand Down Expand Up @@ -758,7 +778,7 @@

set(TYPES "FLASH" "DEBUG" "SIM" "ROBOT")
function(_board_check_runner_type type) # private helper
if (NOT "${type}" IN_LIST TYPES)

Check failure on line 781 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:781 CMakeStyle
message(FATAL_ERROR "invalid type ${type}; should be one of: ${TYPES}")
endif()
endfunction()
Expand All @@ -779,7 +799,7 @@
# the name of a runner.
function(board_set_runner type runner)
_board_check_runner_type(${type})
if (DEFINED BOARD_${type}_RUNNER)

Check failure on line 802 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:802 CMakeStyle
message(STATUS "overriding ${type} runner ${BOARD_${type}_RUNNER}; it's now ${runner}")
endif()
set(BOARD_${type}_RUNNER ${runner} PARENT_SCOPE)
Expand Down Expand Up @@ -1335,7 +1355,7 @@

# Clear destination files if this is the first time the function is called.
get_property(cleared GLOBAL PROPERTY snippet_files_cleared)
if (NOT DEFINED cleared)

Check failure on line 1358 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:1358 CMakeStyle
file(WRITE ${sections_path} "")
file(WRITE ${rom_sections_path} "")
file(WRITE ${ram_sections_path} "")
Expand All @@ -1356,7 +1376,7 @@
endif()

# Choose destination file, based on the <location> argument.
if ("${location}" STREQUAL "SECTIONS")

Check failure on line 1379 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:1379 CMakeStyle
set(snippet_path "${sections_path}")
elseif("${location}" STREQUAL "ROM_SECTIONS")
set(snippet_path "${rom_sections_path}")
Expand Down Expand Up @@ -1430,7 +1450,7 @@

# Remove line from other snippet file, if already used
get_property(old_path GLOBAL PROPERTY "snippet_files_used_${relpath}")
if (DEFINED old_path)

Check failure on line 1453 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:1453 CMakeStyle
file(STRINGS ${old_path} lines)
list(FILTER lines EXCLUDE REGEX ${relpath})
string(REPLACE ";" "\n;" lines "${lines}") # Add newline to each line.
Expand Down Expand Up @@ -1573,7 +1593,7 @@
OUTPUT_QUIET
RESULT_VARIABLE dtc_check_ret
)
if (dtc_check_ret EQUAL 0)

Check failure on line 1596 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:1596 CMakeStyle
set(${ok} 1 PARENT_SCOPE)
else()
set(${ok} 0 PARENT_SCOPE)
Expand Down Expand Up @@ -2069,6 +2089,12 @@
endif()
endfunction()

function(zephyr_library_sources_amend_ifdef feature_toggle source)
if(${${feature_toggle}})
zephyr_library_sources_amend(${source} ${ARGN})
endif()
endfunction()

function(zephyr_sources_ifdef feature_toggle)
if(${${feature_toggle}})
zephyr_sources(${ARGN})
Expand Down Expand Up @@ -3088,7 +3114,7 @@

zephyr_check_flags_exclusive(${CMAKE_CURRENT_FUNCTION} ZEPHYR_STRING SANITIZE ESCAPE)

if (NOT ZEPHYR_STRING_UNPARSED_ARGUMENTS)

Check failure on line 3117 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:3117 CMakeStyle
message(FATAL_ERROR "Function zephyr_string() called without a return variable")
endif()

Expand Down Expand Up @@ -3552,7 +3578,7 @@
endfunction()

function(zephyr_variable_set_too_late variable access value current_list_file)
if (access STREQUAL "MODIFIED_ACCESS")

Check failure on line 3581 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:3581 CMakeStyle
message(WARNING
"
**********************************************************************
Expand Down Expand Up @@ -3758,7 +3784,7 @@
endif()

string(GENEX_STRIP "${arg_list}" arg_list_no_genexes)
if (NOT "${arg_list}" STREQUAL "${arg_list_no_genexes}")

Check failure on line 3787 in cmake/modules/extensions.cmake

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CMakeStyle

cmake/modules/extensions.cmake:3787 CMakeStyle
if (convert_path)
message(FATAL_ERROR "build_info: generator expressions unsupported on PATH entries")
endif()
Expand Down
Loading