Skip to content

Commit ce7318c

Browse files
committed
demo of downloading and building an external library
1 parent de831e4 commit ce7318c

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
arduino_libs
2+
build
3+
.cache
4+
managed_components
5+
dependencies.lock
6+
sdkconfig
7+
sdkconfig.old
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# For more information about build system see
2-
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3-
# The following five lines of boilerplate have to be in your project's
4-
# CMakeLists in this exact order for cmake to work correctly
5-
cmake_minimum_required(VERSION 3.16)
1+
cmake_minimum_required(VERSION 3.17)
62

73
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8-
project(main)
4+
project(hello_world)
5+
6+
# Download BufferUtils library
7+
include(FetchContent)
8+
FetchContent_Populate(BufferUtils
9+
URL https://github.com/bakercp/BufferUtils/archive/refs/tags/3.0.0.zip
10+
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/arduino_libs/BufferUtils
11+
)
12+
13+
# Add Arduino libraries to the project
14+
add_arduino_libraries(${CMAKE_CURRENT_LIST_DIR}/arduino_libs)

idf_component_examples/Hello_world/main/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#include "Arduino.h"
2+
#include "CircularBuffer.h"
23

34
void setup() {
45
Serial.begin(115200);
6+
7+
uint8_t data[10];
8+
CircularBuffer buffer(data, sizeof(data));
9+
buffer.put(1);
510
}
611

712
void loop() {

project_include.cmake

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
function(add_arduino_libraries libs_dir)
22
# Construct the absolute path for libs_dir relative to the CMake project root
3-
set(libs_dir_abs "${CMAKE_SOURCE_DIR}/${libs_dir}")
4-
3+
if (IS_ABSOLUTE "${libs_dir}")
4+
set(libs_dir_abs "${libs_dir}")
5+
else()
6+
set(libs_dir_abs "${CMAKE_SOURCE_DIR}/${libs_dir}")
7+
endif()
8+
59
# Verify if libs_dir_abs is a valid directory
610
if(NOT IS_DIRECTORY "${libs_dir_abs}")
711
message(FATAL_ERROR "The specified libs_dir (${libs_dir_abs}) is not a valid directory.")
812
return() # Stop processing if the directory is invalid
913
endif()
1014

11-
idf_component_get_property(arduino_esp32_lib arduino COMPONENT_LIB)
12-
15+
# Get the name of the arduino component. It is the same as the name of the current directory.
16+
get_filename_component(arduino_component_name ${CMAKE_CURRENT_FUNCTION_LIST_DIR} NAME)
17+
message(STATUS "Adding Arduino libraries to ${arduino_component_name} component")
18+
19+
idf_component_get_property(arduino_esp32_lib ${arduino_component_name} COMPONENT_LIB)
20+
1321
# Loop through each folder in the libs_dir
1422
file(GLOB children RELATIVE ${libs_dir_abs} ${libs_dir_abs}/*)
1523
foreach(child ${children})

0 commit comments

Comments
 (0)