Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Include Paths for Adjacent Libraries (for Unit Testing, etc) (Read 4221 times)
HarrisonOTN
Newbies
*
Offline


Posts: 1
Joined: Feb 14th, 2017
Include Paths for Adjacent Libraries (for Unit Testing, etc)
Feb 14th, 2017 at 11:24am
Print Post  
Firstly, compliments upon today's release, the path improvements are nice!

There's an additional path request that I have, and that is for unit testing: as I do this for a living, I don't do projects that are not TDD led.

My Scenario is this.

I typically have three projects in my Arduino solutions:

  • Sketch project
  • .h and .cpp project, for the objects I am creating for use in the sketch project
  • Unit Testing Project to test the objects being created above


Sketch Includes currently support Arduino libraries, and User Installed Libraries, however libraries that are under construction in adjacent projects in the same solution cannot be accessed in these paths in anything except for full directory notation.

The following works, but is not elegant!

So that my sketches can access the adjacent library that has my .h and .cpp files that are under construction and being Unit Tested in the adjacent Unit Testing project, I have to make the following type of references in my Sketches (BathSpaCentral is the username of this particular machine, yup, welcome to Bath Spa in the UK!):

#include <C:\Users\BathSpaCentral\Documents\Visual Studio 2015\Projects\BitChannel\BitChannel\BitChannel.h>
#include <C:\Users\BathSpaCentral\Documents\Visual Studio 2015\Projects\BitChannel\BitChannel\BitChannel.cpp>

However references like these make my solutions non-distributable to other users, who would have to make their own path modifications instead of being able to use them as cloned from my github repository. 

I'd like, at a minimum, to be able to access the paths using relative paths - but indeed, any solution that would enable users to clone my git repository without having to modify path names will be satisfactory ... however at the moment the relative path mechanism seems to use the arduino location as it's root, hence relative paths cannot locate the adjacent libraries in the solution.

If you want an example that you can download to test - it is complete with Unit Testing and has all of these problems but is of commercial standard - here's an arduino quadcopter project that I have on the go.

https://github.com/HarrisonOfTheNorth/BitChannels

You'll find a sketch that has this exact path problem in the SticksSketch project, SticksSketch.ino

The proof of the pudding will be the capacity to alter the hard-coded paths to something that will work as given, for any user who clones the solution from a git repo.

I am indeed very hopeful that you can resolve this problem as I hope to build a community of quadcopter boffins around this particular repo, and perhaps others, that I will create.

And by the same token, I would like to be able to clone other people's solutions and be able to run them up without having to modify include paths etcetera!

Unit Testing doesn't seem to be a big thing in the arduino community - perhaps I am wrong, but for IoT to properly break out of it's box, engineers have to be capable of full Test Driven Development, because let's face it, it is the unit tests that professionally indemnify us!

Creating Unit Test projects like this does have it's own unique set of problems, and for example, none of the objects that I create directly include the arduino libraries, because they are way off on the C:\Program Files (x86)\Arduino path ... but that's another problem - the upside of which is that I tend to go for the minimalist library inclusion route, which isn't a bad thing for micro-controllers anyway.

Anything that will help either problem will be helpful, but in particular, the include path problem fopr adjacent libraries in the same solution!

Kind regards,

Anthony
« Last Edit: Feb 14th, 2017 at 11:34am by HarrisonOTN »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Include Paths for Adjacent Libraries (for Unit Testing, etc)
Reply #1 - Feb 14th, 2017 at 10:54pm
Print Post  
Hello,

Thanks for the message.

Before I look into this in more detail can I make a few statements and please let me know if you agree they work the way I describe and if they satisfy your requirements.

Visual Micro generated relative paths are only used for intellisense and are relative to the current project. So we are talking about paths for intellisense? The compiler always uses full paths and keep in mind the compilation is performed in a temp build folder, same as the arduino ide.

In the arduino world libraries can be placed below "my documents\arduino\libararies\libName" or can be located below the ide/hardware folders (but this is not recommended)

Hopefully you are clear about what an "Arduino Library" is and that they are #included without paths.

In the visual micro world you have a number of additional options to locate shared project code and shared library code.

1) Adding code short cuts to a project is a crude way to force shared code into the build folder so it is available and compiled from the root of the project during builds. This is the least recommended way of working but useful for ad-hoc small numbers of shared sources.

2) In Visual studio 2015 and above you have the option to create shared c++ projects which are simply .vcxitems files that when opened show as Shared Visual Studio Projects. You could, for example, create a shared project in a sibling or parent folder called MyTest and then locate your .h and .cpp files in the folder and include into the vcxitems project. Once you have a shared project and a master project in your solution you can click the references node of the master project and then click "Add Reference". A dialog will open that has a "Shared Projects" tab and under the tab will be the MyTest project. Click OK and you will find that the master project code will allow #includes exactly as if the code of the shared project is located in the master project. If for example your shared project has code in a sub folder called "src\MyTestStuff\Test.h" then the master project .ino code could contain #include "src\MyTestStuff\Test.h".

3) If you consider the official arduino library system which should always #include "MyLib.h" without path qualifier then this is a useful feature and makes code very transportable. Another aspect of Arduino libraries is that they have a library.properties text file in the root of the library. Visual Micro will detect a library.properties file and will automatically change the compile behavior of the shared project from "Merge Mode" to "Library Mode". This will mean the source code of the shared project will be treated separate to the project code,

Microsoft Shared C++ Projects

[urlhttp://www.visualmicro.com/post/2017/01/16/Arduino-Cross-Platform-Library-Development.aspx]Visual Micro Shared C++ Projects As Arduino Libraries[/url]

So in summary the recent addition of shared C++ projects allows code to be located in any location but is still compiled in an arduino compatible manner. This is designed to work well for source control and also will provide cross-platform intellisense n the shared projects based on the board/architecture of the solution "Startup Project" (master)

« Last Edit: Feb 14th, 2017 at 10:54pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint