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)

Who is online

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