0

I've looked at the site here and on the internet, and even on cmake.org - and didn't find this but wanted to post it here in case it could be helpful.

Here's an example cmakelists.txt file:

idf_component_register(SRCS "main.c"
                INCLUDE_DIRS ".")
  • Import the library, specifying a target name and the library path.
  • The private dependencies of the library is also specified.

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

  • main calls a function from the library, so link it to main

    target_link_libraries(${COMPONENT_LIB} PRIVATE prebuilt)


That works. Of course, in the PRIV_REQUIRES need to be all of the component modules that are used by the static prebuilt lib.

For more of a real-world example - please look here: https://github.com/espressif/esp-idf/tree/release/v4.0/examples/build_system/cmake/import_prebuilt

Credit goes to the folks at espressif - when I was using a cmake editor even the auto-complete didn't find add_prebuilt...

Hope some find this helpful as it didn't take me long to fall down this cmake syntax rabbit hole.

Regards, John W.

  • On Stack Overflow we encourage users to share their knowledge, but such sharing should be still in question/answer form: the **question post** should state the **problem** (without solution) for which one needs a help and the **answer post** should contain a **solution** for the problem stated in the question post. Currently it is not clear from your question post **what do you ask** (what is a **problem**). Also note, that `idf_component_register` is not a basic function of CMake but provided by ESP-IDF. – Tsyvarev Mar 25 '20 at 08:27
  • To echo the earlier comment, Stack Overflow strictly tries to adhere to a Question and Answer format. Consider taking the [tour](https://stackoverflow.com/tour) of the site. Please consider re-formatting your post to match that format (including posting an *answer* post as well). However, this question has **already** been asked on the site (several times), so you could also consider posting an *answer* [here](https://stackoverflow.com/q/8774593/3987854) or [here](https://stackoverflow.com/q/29368026/3987854). – Kevin Mar 25 '20 at 11:59
  • OK - my bad here - I thought the add_prebuilt_library was something standard with cmake - evidently it isn't. This is specific to the ESP32 IDF. – John Westmoreland Mar 27 '20 at 03:51

1 Answers1

1

This is something that is ESP32 specific - it's my mistake for thinking the add_prebuilt_library was a cmake standard feature that I find to be pretty convenient.

Here's the text from Espressif:

Using Prebuilt Libraries with Components

.. highlight:: cmake

The ESP-IDF build system provides a utility function add_prebuilt_library for users to be able to easily import and use prebuilt libraries::

add_prebuilt_library(target_name lib_path [REQUIRES req1 req2 ...] [PRIV_REQUIRES req1 req2 ...])

where:

  • target_name- name that can be used to reference the imported library, such as when linking to other targets
  • lib_path- path to prebuilt library; may be an absolute or relative path to the component directory

Optional arguments REQUIRES and PRIV_REQUIRES specify dependency on other components. These have the same meaning as the arguments for idf_component_register.

Take note that the prebuilt library must have been compiled for the same target as the consuming project. Configuration relevant to the prebuilt library must also match. If not paid attention to, these two factors may contribute to subtle bugs in the app.

For an example, take a look at :example:build_system/cmake/import_prebuilt.

====

Sorry about any confusion this caused.

If you're developing for the ESP platforms on the new tools, this could be handy if you missed this in the docs like I did.

Regards, John W.