Skip to content

Commit

Permalink
[script] simplify how platform libs are pulled into the CMake build tree
Browse files Browse the repository at this point in the history
  • Loading branch information
lmnotran committed Apr 12, 2024
1 parent 04e5672 commit 9784aae
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 149 deletions.
104 changes: 30 additions & 74 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ endif()
# ==============================================================================
# Set platform libs and allow overriding
# ==============================================================================

# SoC (mtd/ftd) platform library
if(NOT OT_PLATFORM_LIB)
set(OT_PLATFORM_LIB "openthread-efr32-soc" CACHE STRING "default efr32 SoC platform library")
endif()

# RCP platform library
if(NOT OT_PLATFORM_LIB_RCP_SPI)
set(OT_PLATFORM_LIB_RCP_SPI "openthread-efr32-rcp-spi" CACHE STRING "default efr32 RCP platform library")
endif()

if(NOT OT_PLATFORM_LIB_RCP_UART)
set(OT_PLATFORM_LIB_RCP_UART "openthread-efr32-rcp-uart" CACHE STRING "default efr32 RCP platform library")
endif()

# RCP platform library
unset(OT_PLATFORM_LIB_RCP CACHE)

if(NOT OT_PLATFORM_LIB_RCP)
if(OT_NCP_SPI)
set(OT_PLATFORM_LIB_RCP "${OT_PLATFORM_LIB_RCP_SPI}" CACHE STRING "default efr32 RCP platform library")
Expand All @@ -92,22 +92,28 @@ set(OT_PLATFORM "external" CACHE STRING "disable example platforms" FORCE)
# ==============================================================================
# mbedtls
# ==============================================================================
# SoC mbedtls library
# Specify a default mbedtls library if not provided
unset(OT_EXTERNAL_MBEDTLS CACHE)
unset(OT_MBEDTLS_RCP CACHE)

if(NOT OT_EXTERNAL_MBEDTLS)
set(OT_EXTERNAL_MBEDTLS "${OT_PLATFORM_LIB}-mbedtls" CACHE STRING "external mbedtls library")
if(OT_FTD OR OT_MTD)
# SoC mbedtls library
set(OT_EXTERNAL_MBEDTLS "${OT_PLATFORM_LIB}-mbedtls" CACHE STRING "external mbedtls library")
elseif(OT_RCP)
# RCP mbedtls library
set(OT_MBEDTLS_RCP "${OT_PLATFORM_LIB_RCP}-mbedtls" CACHE STRING "default efr32 RCP mbedtls library")
set(OT_EXTERNAL_MBEDTLS "${OT_MBEDTLS_RCP}" CACHE STRING "external mbedtls library")
endif()
endif()
set(OT_MBEDTLS ${OT_EXTERNAL_MBEDTLS})

# RCP mbedtls library
unset(OT_MBEDTLS_RCP CACHE)
if(NOT OT_MBEDTLS_RCP)
set(OT_MBEDTLS_RCP "${OT_PLATFORM_LIB_RCP}-mbedtls" CACHE STRING "default efr32 RCP mbedtls library")
# If using
if(OT_EXTERNAL_MBEDTLS)
set(OT_BUILTIN_MBEDTLS_MANAGEMENT OFF CACHE BOOL "disable builtin mbedtls management" FORCE)
endif()
set(OT_BUILTIN_MBEDTLS_MANAGEMENT OFF CACHE BOOL "disable builtin mbedtls management" FORCE)

# ==============================================================================
# mbedtls
# openthread
# ==============================================================================
# NOTE: The "openthread" subdirectory needs to be added after all OT_* variables are defined
add_subdirectory(openthread)
Expand All @@ -125,84 +131,34 @@ target_compile_options(ot-config INTERFACE
# ==============================================================================
# Generated platform projects
# ==============================================================================
# Default library definition paths
if(NOT RCP_SPI_DIR)
set(RCP_SPI_DIR "${PROJECT_SOURCE_DIR}/build/${BOARD_LOWERCASE}/slc/rcp_spi" CACHE STRING "Path to RCP (SPI) library definition")
endif()
if(NOT RCP_UART_DIR)
set(RCP_UART_DIR "${PROJECT_SOURCE_DIR}/build/${BOARD_LOWERCASE}/slc/rcp_uart" CACHE STRING "Path to RCP (UART) library definition")
endif()
if(NOT SOC_DIR)
set(SOC_DIR "${PROJECT_SOURCE_DIR}/build/${BOARD_LOWERCASE}/slc/soc" CACHE STRING "Path to SoC library definition")
endif()

message("OT_RCP = ${OT_RCP}")
message("OT_FTD = ${OT_FTD}")
message("OT_MTD = ${OT_MTD}")
message("OT_APP_RCP = ${OT_APP_RCP}")
message("OT_APP_NCP = ${OT_APP_NCP}")
message("OT_APP_CLI = ${OT_APP_CLI}")

message("===================================================================")
message("Using the following platform library targets:")
if(OT_PLATFORM_LIB_DIR)
message(STATUS "Using platform library from ${OT_PLATFORM_LIB_DIR}")
add_subdirectory(${OT_PLATFORM_LIB_DIR})
else()
message(FATAL_ERROR "No platform library directory found")
endif()

if(OT_APP_RCP)
message("===================================================================")
message("Using the following platform library targets:")
if(OT_RCP)
if(OT_NCP_SPI)
message("-- OT_PLATFORM_LIB_RCP_SPI = ${OT_PLATFORM_LIB_RCP_SPI}")
else()
message("-- OT_PLATFORM_LIB_RCP_UART = ${OT_PLATFORM_LIB_RCP_UART}")
endif()
message("-- OT_PLATFORM_LIB_RCP = ${OT_PLATFORM_LIB_RCP}")
message("-- OT_MBEDTLS_RCP = ${OT_MBEDTLS_RCP}")
elseif(OT_APP_NCP OR OT_APP_CLI)
message("-- OT_PLATFORM_LIB = ${OT_PLATFORM_LIB}")
message("-- OT_MBEDTLS = ${OT_MBEDTLS}")
else()
elseif(OT_FTD OR OT_MTD)
message("-- OT_PLATFORM_LIB = ${OT_PLATFORM_LIB}")
message("-- OT_MBEDTLS = ${OT_MBEDTLS}")
endif()

message("===================================================================")
message("Using generated SLC projects:")
if(OT_APP_RCP)
if(OT_NCP_SPI)
message("-- RCP_SPI_DIR = ${RCP_SPI_DIR}")
else()
message("-- RCP_UART_DIR = ${RCP_UART_DIR}")
endif()
elseif(OT_APP_NCP OR OT_APP_CLI)
message("-- SOC_DIR = ${SOC_DIR}")
endif()

if(OT_APP_RCP)
if(OT_NCP_SPI)
add_subdirectory(${RCP_SPI_DIR})
else()
add_subdirectory(${RCP_UART_DIR})
endif()
elseif(OT_APP_NCP OR OT_APP_CLI)
add_subdirectory(${SOC_DIR})
else()
file(READ ${PROJECT_SOURCE_DIR}/build/${BOARD_LOWERCASE}/slc/generated_projects.txt slc_generated_projects)

# Convert file contents into a CMake list (where each element in the list
# is one line of the file)
#
STRING(REGEX REPLACE ";" "\\\\;" slc_generated_projects "${slc_generated_projects}")
STRING(REGEX REPLACE "\n" ";" slc_generated_projects "${slc_generated_projects}")

# Remove trailing empty list entry
STRING(REGEX REPLACE ";$" "" slc_generated_projects "${slc_generated_projects}")

foreach(slc_project IN LISTS slc_generated_projects)
message("Checking ${slc_project}")
if(EXISTS ${slc_project})
message("......... EXISTS")
add_subdirectory(${slc_project})
else()
message("......... NOT EXISTS")
endif()
endforeach()
endif()
message("-- OT_EXTERNAL_MBEDTLS = ${OT_EXTERNAL_MBEDTLS}")
message("===================================================================")


Expand Down
6 changes: 4 additions & 2 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ generate()
return
fi

local slc_generated_projects_dir="${OT_CMAKE_BUILD_DIR}"/slc

if contains ".*-(ftd|mtd)" "${OT_CMAKE_NINJA_TARGET[@]}"; then
set +x
echo "========================================================================================================="
Expand Down Expand Up @@ -148,6 +146,7 @@ build_rcp_uart()

cmake \
-GNinja \
-DOT_PLATFORM_LIB_DIR=${slc_generated_projects_dir}/rcp_uart \
-DOT_FTD=OFF \
-DOT_MTD=OFF \
-DOT_RCP=ON \
Expand Down Expand Up @@ -177,6 +176,7 @@ build_rcp_spi()

cmake \
-GNinja \
-DOT_PLATFORM_LIB_DIR=${slc_generated_projects_dir}/rcp_spi \
-DOT_FTD=OFF \
-DOT_MTD=OFF \
-DOT_RCP=ON \
Expand Down Expand Up @@ -211,6 +211,7 @@ build_soc()

cmake \
-GNinja \
-DOT_PLATFORM_LIB_DIR=${slc_generated_projects_dir}/soc \
-DOT_FTD=ON \
-DOT_MTD=ON \
-DOT_RCP=OFF \
Expand Down Expand Up @@ -295,6 +296,7 @@ main()

options+=("$@")
export OT_CMAKE_BUILD_DIR="$repo_dir/build/${board}"
slc_generated_projects_dir="${OT_CMAKE_BUILD_DIR}"/slc

# Generate the platform libs and related libs
if [ -n "${VENDOR_EXTENSION-}" ]; then
Expand Down
Loading

0 comments on commit 9784aae

Please sign in to comment.