eclipse: use files in different projects or use different toolchains in one project - eclipse

the code i develop for avr microcontrollers i write so that it runs on the PC and only differs in one or more files (the port). till now i do that using makefiles but now id like to move to eclipse CDT with the AVR plugin.
is there a way to
use 2 different toolchains (x86 and avr compiler) in one project (and also tell these toolchains which port to include)
or to create 2 project (one for x86 one for avr) that share the common files?
note that main() is in a shared file.
thanks for your help.

You may be able to set up multiple configurations to do this, with different toolchains. If this looks reasonable, you could have your source files change their behaviour based on what compile-time symbols are present.

Within Eclipse, only the x86 compiler will be used (so you can run the tests, etc). You will have to invoke the Makefile to build for AVR manually, so one project should be enough.
Eclipse will not use the output of the compiler but the C sources to build its project model. Therefore, you will see all files (even those for AVR) but they will never run in Eclipse. That means you can edit them including code completion.

Related

Eclipse CDT: combine a make project with a cmake one

I have a standard C project in Eclipse CDT. Naturally it uses make. I have decided to add some JSON support to my application to be able to load/save its configuration in a readable format that the user (if such desire occurs) can alter those manually and/or through an external tool. I've looked up two options so far namely Jansson and Json-C. The problem is that both are using cmake, which, if I recall correctly, can be imported in Eclipse CDT without problems (though in itself CDT can't create cmake projects).
I was thinking of adding a script for the pre-build step of my project that runs cmake (as an external command) and sets up the JSON library (static and/or dynamic) so that when the build process of my projects starts the library file will be available.
Is there a better way to combine a cmake with a make project in Eclipse CDT? I know that cmake basically generates a Makefile but I've never done such a combination before.
Even if there is a JSON C library somewhere out ther that uses make (I'm 99.9% sure there is such thing :D) I'd still like to know how to tackle this situation.

How to add predefines to the .cproject file after running a Build Target

I'm trying to import a C project to eclipse (CDT) that is managed by waf. There is a list of predefines generated by waf (when running ./waf configure). That list has to be imported to Project->Properties->C/C++ General/Paths and Symbols/Symbols/GNU C so that the indexer knows about them and does not print errors. That list (when using the GUI) is stored to the .cproject file. I created a Build Target that runs ./waf configure and stores the list to a file named DEFINES.txt. How do I automatically update the list of .cproject with the values of DEFINES.txt after running the Build Target?
I thought about the following solutions and their follow-up problems:
Solution: Writing a plug-in.
Problem: What is the appropriate extension point?
Solution: Writing an external program that calls ./waf configure reads DEFINES.txt and writes the list to .cproject. That program replaces the old Build Target.
Problem: How safe is this? Am I allowed to change the .cproject file by an external program without causing any problems?
Solution: Implementing the .cproject updating algorithm in wscript file.
Problem: This is not a solution for me, because the project is used by others, too, that do not use eclipse as IDE. So the modified wscript will cause errors if the other developers want to build the project.
Does anybody have better ideas or some advice?
Here is how to go about it:
Writing a plug-in: What I recommend you do is write an extension to the LanguageSettingsProvider. The FAQ has some more info, but the summary is that provider does:
This extension point is used to contribute a new Language Settings
Provider. A Language Settings Provider is used to get additions to
compiler options such as include paths (-I) or preprocessor defines
(-D) and others into the project model.
CMake has an option to generate .cproject as part of its configure state, so you could do something similar. See the CMake Wiki for inspiration, but the summary is that you don't store and .cproject/.project in source control and have CMake (or waf in your case) generate the IDE specific files.
You could also just pick up the build settings using the build output parser and ignore the DEFINES.txt altogether. That requires running the build once from within Eclipse for CDT to see all the commands, and requires the commands to be parseable in the build output.

Trying to use Eclipse (Mars) with Linked Folders for ESP8266 project

I have successfully built a number of projects with eclipse (mars) under windows 10 with copied common source and header files. I now want to refactor these projects to use the eclipse 'linked folder' facility.
linked folders
I have successfully created the common project and the linked source folders to it in the target project.
However when I try to compile the project the compiler can't see the linked folders...
compiler error messages
I'd appreciate any help with this, or is it that the xtensa compiler under windows doesn't support linked folders??
IMHO "linked folders" is a slightly borked feature as it raises expectations it can't fulfill. The folders are only linked within the Eclipse context. That means that as soon as you leave the safe Eclipse haven those links are gone.
What you actually want/need are links on OS level that also work on the command line i.e. you need them on the file system. Such symlinks are native on Unix(-like) systems but there are ways to create them on Windows as well.

Configuring CDT without too many configurations

I am working on an embedded C project that is somewhat complex (several hundred source files divided into 3 sub-projects). Currently we are using eclipse CDT to generate makefiles and build our project. The advantage of this is that there is no duplication between eclipse configuration and the makefiles. Now I need to create several build types:
a DEBUG build with some compiler options such as -g -O0 and a few macros defined
a PRODUCTION build with -03
a TEST build with some various compiler options and macros defined
Given that I already have 3 eclipse projects this would result in 9 sets different Eclipse configurations that have to be updated any time we need to make a change that affects all the types and projects.
Is there another solution that will allow us to develop in Eclipse--and have it correctly reflect the value of macros based on the desired build type--without needing to maintain so many configurations?
Is there some trick to Eclipse CDT configurations to make this easier? Perhaps I could use a tool such as CMake which has the ability to generate Eclipse CDT files?

Project with multiple binaries in Eclipse CDT

I think it is quite normal to have more than one binary in a project. However, with Eclipse CDT I don't know how to set up the IDE to get things done.
I know I can create several projects - one per binary. And I know I can set the dependencies per project. However, I cannot regard them as one project in Eclipse. If I'd like to share the code with a version control system (like svn), each developer has to import the projects separately.
What I miss is something like the Solution (sln file) in Visual Studio. Should I create a single project and create the make files by myself?
I haven't tried it out yet, but there is this 'project set' which can be ex- and imported. Is this the solution? Can this be put into version control?
My goal it to put everything under version control, not only subprojects. I cannot imagine that CDT makes only sense for single-binary applications.
How can I work properly?
I am quite sure CDT doesn't support sub-projects, which leaves you pretty much with:
one workspace per "set of projects"
one project per binary (like you mention in your question)
project dependencies (like you mention in your question)
In term of version control, that means:
submodules (Git),
subrepos (Mercurial) or
external (SVN)
for each project needing a shared library project.
In short, that means putting under version control various components (set of files), with one referencing specific version of others (that list of specific versions of other components is called a "configuration", based on a component-based approach development)