Skip to content

Commit

Permalink
backends: Automatically include backend.cmake files for Zephyr
Browse files Browse the repository at this point in the history
Append to the pw_set_zephyr_backend_ifdef function such that the
function can include the backend declaration prior to setting the
backend.

Change-Id: I1bdb703d710e96b432a690cd14f87dc79c594e35
Signed-off-by: Yuval Peress <peress@google.com>
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/123390
Reviewed-by: Rob Barnes <robbarnes@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
  • Loading branch information
yperess authored and CQ Bot Account committed Dec 15, 2022
1 parent b77c6b7 commit c5708c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ cmake_minimum_required(VERSION 3.16)
include(pw_build/pigweed.cmake)

if(CONFIG_ZEPHYR_PIGWEED_MODULE)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_ASSERT pw_assert.assert pw_assert_zephyr.assert)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_ASSERT pw_assert.check pw_assert_zephyr.check)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_CHRONO_SYSTEM_CLOCK pw_chrono.system_clock pw_chrono_zephyr.system_clock)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_INTERRUPT_CONTEXT pw_interrupt.context pw_interrupt_zephyr.context)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_LOG pw_log pw_log_zephyr)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_SYNC_MUTEX pw_sync.mutex pw_sync_zephyr.mutex_backend)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_SYNC_BINARY_SEMAPHORE pw_sync.mutex pw_sync_zephyr.binary_semaphore_backend)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_SYS_IO pw_sys_io pw_sys_io_zephyr)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_ASSERT
pw_assert.assert pw_assert_zephyr.assert pw_assert/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_ASSERT
pw_assert.check pw_assert_zephyr.check pw_assert/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_CHRONO_SYSTEM_CLOCK
pw_chrono.system_clock pw_chrono_zephyr.system_clock pw_chrono/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_INTERRUPT_CONTEXT
pw_interrupt.context pw_interrupt_zephyr.context pw_interrupt/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_LOG
pw_log pw_log_zephyr pw_log/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_SYNC_MUTEX
pw_sync.mutex pw_sync_zephyr.mutex_backend pw_sync/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_SYNC_BINARY_SEMAPHORE
pw_sync.mutex pw_sync_zephyr.binary_semaphore_backend pw_sync/backend.cmake)
pw_set_zephyr_backend_ifdef(CONFIG_PIGWEED_SYS_IO
pw_sys_io pw_sys_io_zephyr pw_sys_io/backend.cmake)

if(CONFIG_NANOPB AND "${dir_pw_third_party_nanopb}" STREQUAL "")
set(dir_pw_third_party_nanopb "${ZEPHYR_NANOPB_MODULE_DIR}" CACHE PATH "" FORCE)
Expand Down
8 changes: 8 additions & 0 deletions pw_build/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,14 @@ work with, since their values only change when they're assigned, but then
persist accross CMake invocations. These variables should be set in one of the
following ways:

* Prior to setting a backend, your application should include
``$ENV{PW_ROOT}/backends.cmake``. This file will setup all the backend targets
such that any misspelling of a facade or backend will yield a warning.

.. note::
Zephyr developers do not need to do this, backends can be set automatically
by enabling the appropriate Kconfig options.

* Call ``pw_set_backend`` to set backends appropriate for the target in the
target's toolchain file. The toolchain file is provided to ``cmake`` with
``-DCMAKE_TOOLCHAIN_FILE=<toolchain file>``.
Expand Down
13 changes: 7 additions & 6 deletions pw_build/pigweed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,15 @@ function(pw_set_backend NAME BACKEND)
set("${NAME}" "${BACKEND}" CACHE STRING "backend variable for a facade" FORCE)
endfunction(pw_set_backend)

# Zephyr specific wrapper for pw_set_backend, selects the default zephyr backend based on a Kconfig while
# still allowing the application to set the backend if they choose to
function(pw_set_zephyr_backend_ifdef COND FACADE BACKEND)
get_property(result CACHE "${FACADE}_BACKEND" PROPERTY TYPE)
# Zephyr specific wrapper for pw_set_backend.
function(pw_set_zephyr_backend_ifdef COND FACADE BACKEND BACKEND_DECL)
if(${${COND}})
if("${result}" STREQUAL "")
pw_set_backend("${FACADE}" "${BACKEND}")
if(NOT EXISTS "${BACKEND_DECL}")
message(FATAL_ERROR
"Can't find backend declaration file '${BACKEND_DECL}'")
endif()
include("${BACKEND_DECL}")
pw_set_backend("${FACADE}" "${BACKEND}")
endif()
endfunction()

Expand Down

0 comments on commit c5708c1

Please sign in to comment.