diff --git a/CMakeLists.txt b/CMakeLists.txt index fcea2d054eb..f9246ace5b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -712,9 +712,12 @@ foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY}) if(NOT source_list AND NOT ${lib_imported} ) - message(WARNING - "No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build." - ) + get_property(allow_empty TARGET ${zephyr_lib} PROPERTY ALLOW_EMPTY) + if(NOT "${allow_empty}") + message(WARNING + "No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build." + ) + endif() target_sources(${zephyr_lib} PRIVATE ${ZEPHYR_BASE}/misc/empty_file.c) set_property(TARGET ${zephyr_lib} PROPERTY EXCLUDE_FROM_ALL TRUE) list(REMOVE_ITEM ZEPHYR_LIBS_PROPERTY ${zephyr_lib}) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index eaf768478e3..452749c502c 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -565,6 +565,31 @@ function(zephyr_library_app_memory partition) "-l" $ "${partition}") endfunction() +# Configure a Zephyr library specific property. +# +# Usage: +# zephyr_library_property( ) +# +# Current Zephyr library specific properties that are supported: +# ALLOW_EMPTY : Allow a Zephyr library to be empty. +# An empty Zephyr library will generate a CMake +# configure time warning unless `ALLOW_EMPTY` is TRUE. +function(zephyr_library_property) + set(single_args "ALLOW_EMPTY") + cmake_parse_arguments(LIB_PROP "" "${single_args}" "" ${ARGN}) + target_compile_definitions(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${item} ${ARGN}) + + if(LIB_PROP_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "zephyr_library_property(${ARGV0} ...) given unknown arguments: ${FILE_UNPARSED_ARGUMENTS}") + endif() + + foreach(arg ${single_args}) + if(DEFINED LIB_PROP_${arg}) + set_property(TARGET ${ZEPHYR_CURRENT_LIBRARY} PROPERTY ${arg} ${LIB_PROP_${arg}}) + endif() + endforeach() +endfunction() + # 1.2.1 zephyr_interface_library_* # # A Zephyr interface library is a thin wrapper over a CMake INTERFACE