From 1129e8b8d4ff093194fd95185b541866e6093968 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 19 Aug 2025 16:08:19 +0200 Subject: [PATCH] feat(cmakev2/utilities): add add_prebuilt_library function Imported from cmakev1 to enable the addition of prebuilt libraries into the build. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/utilities.cmake | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/cmakev2/utilities.cmake b/tools/cmakev2/utilities.cmake index dcff6522a2f..7a469fe1db2 100644 --- a/tools/cmakev2/utilities.cmake +++ b/tools/cmakev2/utilities.cmake @@ -658,3 +658,38 @@ function(target_add_binary_data target embed_file embed_type) target_sources("${target}" PRIVATE "${embed_srcfile}") endfunction() + +#[[ + add_prebuilt_library( + [REQUIRES ...]) + [PRIV_REQUIRES ...]) + + :target[in]: Target name for the imported library. + :library[in]: Imported library path. + :REQUIRES[in,opt]: Optional dependency on other components. + :PRIV_REQUIRES[in,opt]: Optional private dependency on other components. + + Add prebuilt library with support for adding dependencies on ESP-IDF + components. +#]] +function(add_prebuilt_library target_name lib_path) + cmake_parse_arguments(_ "" "" "REQUIRES;PRIV_REQUIRES" ${ARGN}) + + get_filename_component(lib_path "${lib_path}" + ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") + + add_library(${target_name} STATIC IMPORTED GLOBAL) + set_property(TARGET ${target_name} PROPERTY IMPORTED_LOCATION ${lib_path}) + + foreach(req ${__REQUIRES}) + idf_component_get_property(req_lib "${req}" COMPONENT_LIB) + set_property(TARGET ${target_name} APPEND PROPERTY LINK_LIBRARIES "${req_lib}") + set_property(TARGET ${target_name} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${req_lib}") + endforeach() + + foreach(req ${__PRIV_REQUIRES}) + idf_component_get_property(req_lib "${req}" COMPONENT_LIB) + set_property(TARGET ${target_name} APPEND PROPERTY LINK_LIBRARIES "${req_lib}") + set_property(TARGET ${target_name} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "$") + endforeach() +endfunction()