Skip to content

Add sketch directory to include directories #313

Open
@mihaizh

Description

@mihaizh

So, as title says, it would be nice to add the original directory of the sketch file (before is copied to the temporary folder) to the include directories.

The motivation behind this is as follows. Usually, if you want to share code between sketches, you should make a library and then use it in both sketches. One of the problems is that, one should import the library manually if it wants to be able to compile the project.
But what if I want to share the code with another C++ project too, one which is not an Arduino project?

I have the following directory structure:

src
-- common
---- common.h
---- arduino.h
-- other_non_arduino_project
---- CMakeLists.txt
---- main.cpp
-- sketch1
---- sketch1.ino
-- sketch2
---- sketch2.ino

Here, sketch1 and sketch2 share the arduino.h file. Then, both sketches share also the common.h file with the other_non_arduino_project. To be able to do it, the original sketch directory should be added to the include directories such that, in the Arduino sketches I can use the following lines of code to include the common files.
#include "../common/arduino.h"
#include "../common/common.h"

Having this means that the builder does not need to copy the .h files anymore to the temporary directory.
I don't know if this is somehow a breaking change or how it would affect the entire building system of Arduino. I have already patched the arduino-builder locally, and it works just fine. Here you can find the commit on my fork: mihaizh@55f9599

What do you say? Is it worth it? Or is there a way, which I don't know yet about, to do it already?

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions