Creating a component from a prebuilt lib

lnf_simon
Posts: 2
Joined: Fri Jul 03, 2020 6:48 am

Creating a component from a prebuilt lib

Postby lnf_simon » Wed Jul 08, 2020 1:52 pm

Hello,

I want to create custom components with prebuilt libraries, for example:

Component name foo
Component files: foo.a foo.h

I have been trying to create this component from the import_prebuilt example, but in that example
the lib is imported directly to the main component.

I modified the import_prebuilt example so the project has the following structure:

import_prebuilt
-- components
----- prebuilt
-------- prebuilt.a
-------- prebuilt.h
-------- CMakeList.txt
-- main
----- main.c
----- CMakeList.txt
-- CMakeList.txt

I tried to write the CMakeList.txt of the prebuilt component as:

Code: Select all

idf_component_register(INCLUDE_DIRS .)

add_prebuilt_library(libprebuilt "libprebuilt.a"
             PRIV_REQUIRES spi_flash app_update log)

target_link_libraries(${COMPONENT_LIB} PUBLIC libprebuilt)
But it didn´t work.. I am still a newbie with CMake :? How should I write this file in order to correctly create a component?

The rest of the CMakeList.txt files are the minimum required to successfully compile the project.

I am using IDF 4.1

import_prebuilt example:

https://github.com/espressif/esp-idf/tr ... t_prebuilt

Thanks for your help

lnf_simon
Posts: 2
Joined: Fri Jul 03, 2020 6:48 am

Re: Creating a component from a prebuilt lib

Postby lnf_simon » Fri Jul 17, 2020 9:05 am

Very easy solution!

As there are no source files (SRCS) the library must be linked with INTERFACE attribute

Code: Select all

idf_component_register(INCLUDE_DIRS .)

add_prebuilt_library(libprebuilt "libprebuilt.a"
             PRIV_REQUIRES spi_flash app_update log)

target_link_libraries(${COMPONENT_LIB} INTERFACE libprebuilt)

User avatar
dmarks_ls
Posts: 6
Joined: Fri Feb 10, 2023 4:56 pm

Re: Creating a component from a prebuilt lib

Postby dmarks_ls » Thu May 02, 2024 7:08 pm

I just followed these instructions, and I was able to build a Hello World app while pulling a couple of functions from my application libraries. Here's the CMakeLists.txt for the component:

Code: Select all

# App libs include component w/ prebuilt source library.
# Set this to whatever components your library requires.
set (APPLIBS_REQUIRES freertos driver nvs_flash spi_flash esp_hw_support esp_wifi esp_adc)
idf_component_register(SRCS ""
                    INCLUDE_DIRS "include"
                    REQUIRES ${APPLIBS_REQUIRES})
add_prebuilt_library(applibs_source "lib/libapplibs_source.a"
                    REQUIRES ${APPLIBS_REQUIRES})
target_link_libraries(${COMPONENT_LIB} INTERFACE applibs_source)
So in my component directory, I have the above CMake file, a "lib" subdirectory containing my app libraries archive, and an "include" directory containing all the relevant include files for my library. Works great.

Who is online

Users browsing this forum: Baidu [Spider] and 108 guests