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

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.

Related

importing an autotools project in eclipse doesn't find all includes, breaks autocomplete

I have an autotools project that references an external directory containing build output of a different project (headers, libs, etc...). configuring and building via command line works fine. After importing via eclipse as an existing autotools project, none of the headers/references in that second project are found by eclipse.
Eclipse also fails to find a few libraries/headers that are in non-standard system locations like /opt, etc... Thus, autocomplete, ctrl+click, etc... doesn't work on a lot of things.
Both the second project and the non-standard libraries are correctly referenced when building/compiling and are found properly by configure
I'm able to manually add the necessary paths in the C/C++ build settings to get all of the includes resolved, but I was under the impression that importing an autotools project should automatically find these references. Am I incorrect in that assumption?
An additional note, our configure script requires the use of --prefix to know where to find the second project. when importing the project the first time, it of course tries to autoconf everything without --prefix set and subsequently fails. I then go back in and modify eclipse to use the appropriate prefix OR manually re-run autogen and configure with --prefix=/some/path. Then re-index the project. so everything should be setup fine at this point.
The actual question seems to be this:
I'm able to manually add the necessary paths in the C/C++ build
settings to get all of the includes resolved, but I was under the
impression that importing an autotools project should automatically
find these references. Am I incorrect in that assumption?
Your own experience tells you otherwise, notwithstanding your prior expectation.
In an Eclipse Autotools project, an Autotools build system is used to (configure and) build the project instead of any of Eclipse's built-in builders. To the extent that there is a data flow between components, it is from Eclipse to the project, not the other way around. The distributed Autotools artifacts (Makefile.am, configure.ac, etc.) are opaque to Eclipse, except inasmuch as it has content highlighting for those file types (IIRC). Artifacts built by configuring the project are not only opaque, but also ignored by policy.

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.

BB10 how to generate config.pri file

Is there a script or a tool to generate the config.pri file for a BB10 project? Momentics IDE does it for you automatically whenever a project is refreshed or the directory is changed. Unfortunately, I am deploying and compiling via command line tools (it is an automated script which runs tests).
Without the config.pri file, I can't 'make'. An easy solution would be to track the file on github along with the source code for the project, but since the file has a timestamp on it, it causes many annoying merge conflicts.
Any ideas? I rather not write the script myself to parse through all the directories and accumulate header and source files myself. Since Momentics IDE does it, there must be a script that it calls or uses. Momentics is based off of Eclipse, is there any way to see what commands the IDE is calling?
config.pri is just an additional file included in the project's main .pro file. So if you're able to control .pro file you may not need config.pri at all and this inclusion could be safely removed from .pro file. For example, in earlier BB10 SDK releases config.pri simply didn't exist and has been added later.
.pro file is a main file for generating platform and environment-dependent Makefiles for building project, so I'm not sure if there's some tools allowing to manage it automatically. It could be initially generated by invoking qmake -project but I'm not sure if there are any console tools allowing you to manage it after automatically.
Technically, you should modify this file only if your project structure or build system options changed, all other stuff is done in platform-independent way.

Eclipse: script compiler as part of a project

This question is not limited to lex and yacc, but how can I add a custom script compiler as part of a project? For example, I have the following files in the project:
grammar.y
grammar.l
test.script
The binary 'script_compiler' will be generated using grammar.y and grammar.l compiled by lex, yacc and g++. And then I want to use that generated script_compiler to compile test.script to generate CompiledScript.java. This file should be compiled along with the rest of the java files in the project. This setting is possible with XCode or make, but is it also possible with Eclipse alone? If not, how about together with Maven plugin?
(I might setup the script compiler as a separate project, but it would be nice if they can be put in the same project so that changes to the grammar files can be applied immediately)
Thanks in advance for your help!
You can add a custom "Builder" from the project properties dialog. This can be an ant script (with an optional target) or any other script or executable.
There are also maven plugins for ant and other scripting languages
If you just want to run an external program in Maven this is what you want: http://mojo.codehaus.org/exec-maven-plugin/ -- you can then run Maven targets from your IDE or command line and it should do the right thing either way.
To integrate with the normal compilation bind the plugin to the "generate-sources" phase and add the location where the Java files are generated to the "sourceRoot" option of the exec plugin. That way the compiler will pick them up.
Ideally you generate the code into a folder "target/generated-sources/MY_SCRIPT_NAME". That is the standard location for generated sources in the Maven world and e.g. IntelliJ IDEA will pick up source files inside of that location. Note that this doesn't work if the files are directly in "target/generated-sources".
The other option is to write your own Maven plugin, which is actually quite easy as well. See e.g. https://github.com/peterbecker/maven-code-generator

Netbeans project to scripted build

I'm trying to convert a Netbeans 6.9.1 project into a scripted build (without netbeans). Of course, it fails (or I wouldn't be asking for help).
In the failure it says that the org.apache.commons.httpclient package does not exist. (Of course, it worked when we ran the build in Netbeans).
Now I know exactly where the commons-httpclient.jar file is located in my project structure, but I can't seem to tell it to the compiler via the ant build files and the netbeans property files.
Perhaps related to this is when I ran "ant -v" to build my software, it said,
Property lib.mystuff.classpath has not been set. This variable is important, I guess, because
the file nbproject/project.properties uses lib.mystuff.classpath in its definition of javac.classpath, which of course tells the Java compiler where to find the JARs.
So...when moving a Netbeans project to a netbeans-independent scripted build, how can the build script set these properties? Also, how can I ensure that the jar file gets included in the ant build?
I appreciate any help I can get, as I am a Java newbie.
UPDATE AFTER ACCEPTING ANSWER FROM vkraemer:
There are a few best practices for build scripts for production software:
Put everything needed for a build under a single directory tree. (Netbeans = fail)
Put everything in source code control. (I did that)
The first line of the build script should clear all environment variables.
The next section of the build script should explicitly set all environment variables to values which are known to work.
The next part of the build should be able to execute using command-line programs such as javac, ant, cc, etc, and must not depend on firing up an IDE such as Eclipse or Netbeans.
It is a shame that Netbeans makes this hard.
I did a quick look in a Java Application project and found the following...
javac.classpath = ${libs.MyStuff.classpath}
libs.MyStuff.classpath is defined in %HOME%/.netbeans/6.9.1/build.properties.
You may be able to get by doing the following...
ant -Dlibs.MyStuff.classpath=c:\a\b\c.jar
You would need to do more if you have multiple jar files in the MyStuff library that you created in NetBeans.