Commit 25578be9 authored by Torsten Rasmussen's avatar Torsten Rasmussen Committed by Carles Cufi
Browse files

cmake: rework empty zephyr libraries handling.



This is an update to #34289.

When using CMake <=3.18 an interface library may not use the property
SOURCES.

Therefore, if an interface lib is added to the list of ZEPHYR_LIBS, then
CMake <=3.18 will raise the following error:
```
CMake Error .... (get_property):
  INTERFACE_LIBRARY targets may only have whitelisted properties.
  The property "SOURCES" is not allowed.
```

Therefore the check has been reworked into two steps.
First ensure all libs are static, and if they are, then check if they
are empty and not imported.

Signed-off-by: default avatarTorsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
parent 96f20cfb
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -700,16 +700,16 @@ add_subdirectory(kernel)
get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS)

foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
  get_property(source_list  TARGET ${zephyr_lib} PROPERTY SOURCES)
  get_property(lib_type     TARGET ${zephyr_lib} PROPERTY TYPE)
  get_property(lib_imported TARGET ${zephyr_lib} PROPERTY IMPORTED)

  # To prevent CMake failure when a driver is enabled, for example: REGULATOR=y
  # we disable any Zephyr libraries without sources and adds the `empty_file.c`.
  if(${lib_type} STREQUAL STATIC_LIBRARY
     AND NOT ${lib_imported}
     AND NOT source_list
     AND NOT ${zephyr_lib} STREQUAL app
  )
    get_property(source_list  TARGET ${zephyr_lib} PROPERTY SOURCES)
    get_property(lib_imported TARGET ${zephyr_lib} PROPERTY IMPORTED)
    if(NOT source_list
       AND NOT ${lib_imported}
    )
      message(WARNING
        "No SOURCES given to Zephyr library: ${zephyr_lib}\nExcluding target from build."
@@ -717,10 +717,12 @@ foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
      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})
  else()
      continue()
    endif()
  endif()

  # TODO: Could this become an INTERFACE property of zephyr_interface?
  add_dependencies(${zephyr_lib} zephyr_generated_headers)
  endif()
endforeach()

get_property(OUTPUT_FORMAT        GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT)