Skip to content

Add Arduino lib to arduino as IDF component #8115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions docs/source/esp-idf_component.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,89 @@ Compilation Errors
------------------

As commits are made to esp-idf and submodules, the codebases can develop incompatibilities that cause compilation errors. If you have problems compiling, follow the instructions in `Issue #1142 <https://github.com/espressif/arduino-esp32/issues/1142>`_ to roll esp-idf back to a different version.

Adding arduino library
----------------------

There are few approaches:

1. Add global library to ``components/arduino-esp32/libraries/new_library``
2. Add local project library to ``examples/your_project/main/libraries/new_library``

1 Adding global library
***********************

Download the library:

.. code-block:: bash

cd ~/esp/esp-idf/components/arduino-esp32/
git clone --recursive [email protected]:Author/new_library.git libraries/new_library


Edit file ``components/arduino-esp32/CMakeLists.txt``

Get the source file list with shell command:

.. code-block:: bash

find libraries/new_library/src/ -name '*.c' -o -name '*.cpp'
libraries/new_library/src/new_library.cpp
libraries/new_library/src/new_library_extra_file.c

Locate block which starts with ``set(LIBRARY_SRCS`` and copy the list there. Now it should look something like this:

.. code-block:: bash

set(LIBRARY_SRCS
libraries/ArduinoOTA/src/ArduinoOTA.cpp
libraries/AsyncUDP/src/AsyncUDP.cpp
libraries/new_library/src/new_library.cpp
libraries/new_library/src/new_library_extra_file.c


After this add the library path to block which starts with ``set(includedirs``. It should look like this:

.. code-block:: bash

set(includedirs
variants/${CONFIG_ARDUINO_VARIANT}/
cores/esp32/
libraries/ArduinoOTA/src
libraries/AsyncUDP/src
libraries/new_library/src


2 Adding local library
**********************

Download the library:

.. code-block:: bash

cd ~/esp/esp-idf/examples/your_project
mkdir components
git clone --recursive [email protected]:Author/new_library.git components/new_library

??? Modify your main\CMakeLists.txt by adding the library sources:

Create new CMakeists.txt in the library folder: ``components/new_library/CMakelists.txt``

.. code-block:: bash

idf_component_register(SRCS "new_library.cpp"
INCLUDE_DIRS "."
)

You can read more about CMakelists in the IDF documentation regarding the `Build System <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html>`_

Tip
---

If you want to use arduino-esp32 both as an ESP-IDF component and with Arduino IDE you can simply create a symlink:

.. code-block:: bash

ln -s ~/Arduino/hardware/espressif/esp32 ~/esp/esp-idf/components/arduino-esp32

This will allow you to install new libraries as usual with Arduino IDE. To use them with IDF component, use ``add_lib.sh -e ~/Arduino/libraries/New_lib``
72 changes: 72 additions & 0 deletions tools/add_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
LIBRARY=""

#TODO project library: -p path_to/project


# this is for new lib: [-n <git-link>]
# Get the directory name where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Construct the absolute path to libraries folder
LIBS_PATH="$SCRIPT_DIR/../libraries"

# Use $LIBS_PATH variable to clone new lib, regardless of where the script is run from.
echo "Cloning: git clone --recursive $1 $LIBS_PATH/Firebase-ESP32"
git clone --recursive $1 $LIBS_PATH/Firebase-ESP32

LIBRARY=$LIBS_PATH/Firebase-ESP32




# get the CMakelists right









# local:
#Modify your main\CMakeLists.txt to this:
#
#idf_component_register(
# SRC_DIRS "."
# "libraries/Firebase-ESP32/src"
# "libraries/Firebase-ESP32/src/addons"
# "libraries/Firebase-ESP32/src/json"
# "libraries/Firebase-ESP32/src/json/extras/print"
# "libraries/Firebase-ESP32/src/json/MB_JSON"
# "libraries/Firebase-ESP32/src/mbfs"
# "libraries/Firebase-ESP32/src/rtdb"
# "libraries/Firebase-ESP32/src/rtdb/stream"
# "libraries/Firebase-ESP32/src/session"
# "libraries/Firebase-ESP32/src/signer"
# "libraries/Firebase-ESP32/src/sslclient/esp32"
# "libraries/Firebase-ESP32/src/wcs"
# "libraries/Firebase-ESP32/src/wcs/base"
# "libraries/Firebase-ESP32/src/wcs/custom"
# "libraries/Firebase-ESP32/src/wcs/esp32"
#
#
# INCLUDE_DIRS "."
# "libraries/Firebase-ESP32/src"
# "libraries/Firebase-ESP32/src/addons"
# "libraries/Firebase-ESP32/src/json"
# "libraries/Firebase-ESP32/src/json/extras/print"
# "libraries/Firebase-ESP32/src/json/MB_JSON"
# "libraries/Firebase-ESP32/src/mbfs"
# "libraries/Firebase-ESP32/src/rtdb"
# "libraries/Firebase-ESP32/src/rtdb/stream"
# "libraries/Firebase-ESP32/src/session"
# "libraries/Firebase-ESP32/src/signer"
# "libraries/Firebase-ESP32/src/sslclient/esp32"
# "libraries/Firebase-ESP32/src/wcs"
# "libraries/Firebase-ESP32/src/wcs/base"
# "libraries/Firebase-ESP32/src/wcs/custom"
# "libraries/Firebase-ESP32/src/wcs/esp32"
#)