Cannot Move Components Outside of Project Tree

BoCoKeith
Posts: 2
Joined: Wed Nov 22, 2023 12:38 am

Cannot Move Components Outside of Project Tree

Postby BoCoKeith » Sat Nov 25, 2023 6:59 pm

I am having a problem moving components outside of a project folder. With the following directory structure...

Code: Select all

C:\ESP\sprinkle
└─sprinkle-sensor
  ├─CMakeLists.txt
  ├─sdkconfig
  ├─build
  ├─components
  │ └─sprinkle_common
  │   ├─CMakeLists.txt
  │   ├─component.mk
  │   ├─sprinkle_common.c
  │   └─include
  │     └─sprinkle_common.h
  └─main
    ├─CMakeLists.txt
    └─sprinkle-sensor.c
... and the project CMakeLists.txt file containing ...

Code: Select all

# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(sprinkle-sensor)
... for the almost trivial sprinkle_sensor.c of ...

Code: Select all

#include <stdio.h>
#include "sprinkle_common.h"
    
void app_main(void) {
    printf("MESSAGE_MOISTURE_SENSOR=%d\n", MESSAGE_MOISTURE_SENSOR);
}
... I can build the project just fine. (No errors.) But if I try to move the components folder "up" one level ...

Code: Select all

C:\ESP\sprinkle
├─components
│ └─sprinkle_common
│   ├─CMakeLists.txt
│   ├─component.mk
│   ├─sprinkle_common.c
│   └─include
│     └─sprinkle_common.h
└─sprinkle-sensor
  ├─CMakeLists.txt
  ├─sdkconfig
  ├─build
  └─main
    ├─CMakeLists.txt
    └─sprinkle-sensor.c
... and then change the project CMakeLists.txt to ...

Code: Select all

# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

set(EXTRA_COMPONENTS_DIR ..)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(sprinkle-sensor)
... I keep getting the error ...

Code: Select all

C:/ESP/sprinkle/sprinkle-sensor/main/sprinkle-sensor.c:15:10: fatal error: sprinkle_common.h: No such file or directory
   15 | #include "sprinkle_common.h"
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
I've tried all sorts of variants of the extra components directory: "..", "..\..", "..\components", but no change.

What am I doing wrong?

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Cannot Move Components Outside of Project Tree

Postby MicroController » Sun Nov 26, 2023 2:45 pm

What am I doing wrong?
You're setting the wrong variable.
The thing is (maybe unintuitively) called EXTRA_COMPONENT_DIRS. (Because there can be multiple extra component-directories...)

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Cannot Move Components Outside of Project Tree

Postby ESP_Sprite » Mon Nov 27, 2023 2:21 am

Good catch! I stared at the post for a few minutes but couldn't find anything wrong, even cross-referencing with my own setup.

BoCoKeith
Posts: 2
Joined: Wed Nov 22, 2023 12:38 am

Re: Cannot Move Components Outside of Project Tree

Postby BoCoKeith » Tue Nov 28, 2023 4:37 pm

Thanks a ton, @Microcontroller. That did it! (And thanks for looking @ESP_Sprite.)

Who is online

Users browsing this forum: jwalters1955, MSN [Bot], tizio1234 and 98 guests