Hi, apologies if this is similar to previous posts such as 12190, but I haven’t found an answer anywhere…
I have downloaded the AWS FreeRTOS repo and am trying to incorporate it into my project, as per the ‘Getting Started’ guide. Aiming for a project structure as follows:
-
freertos
-
components
-
bmp280
- bmp280.c
- bmp280.h
-
other components
-
-
include
- main.h
- other project header files
-
src
- main.c
- other project c files
-
CMakeLists.txt
Based on the guide, I currently have the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(csl_edge)
include_directories(include)
#add_executable(csl_edge src/main.c)
#Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE csl_edge)
set(IDF_EXECUTABLE_SRCS ~/Projects/csl_edge/src/main.c)
#Add some extra components. IDF_EXTRA_COMPONENT_DIRS is a variable used by ESP-IDF
#to collect extra components.
get_filename_component(
EXTRA_COMPONENT_DIRS
“components/bmp280” ABSOLUTE
)
list(APPEND IDF_EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS})
#Add FreeRTOS as a subdirectory. AFR_BOARD tells which board to target.
set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL “”)
add_subdirectory(freertos)
and the following CMakeLists.txt in components/bm280:
set(COMPONENT_ADD_INCLUDEDIRS . )
set(COMPONENT_SRCDIRS . )
register_component()
I haven’t been able to build successfully - problems so far:
- If I leave in the line add_executable(csl_edge src/main.c) as per the guide I get the build error:
‘cannot create target “csl_edge” because another target with
the same name already exists’
I believe this is due to add_executable also being called by freertos/vendors/espressif/board/esp32/CMakeLists.txt, using the name set as IDF_PROJECT_EXECUTABLE. I can resolve the error by removing the ‘add_executable’ line and adding ‘set(IDF_EXECUTABLE_SRCS ~/Projects/csl_edge/src/main.c)’ as shown, which then allows freertos/vendors/espressif/board/esp32/CMakeLists.txt to correctly call add_executable with my main.c file. Does this approach sound correct?
- The build is currently not compiling bm280.c (or indeed any of my c files except for main.c), and is not finding bm280.h when trying to compile main.c. Should appending to IDF_EXTRA_COMPONENT_DIRS be sufficient to add the component and make it available? I’ve tried to follow what’s in the guide but am not sure how this works as I don’t see the IDF_EXTRA_COMPONENT_DIRS variable being read anywhere?
Any help much appreciated…