Build several CDT C++ projects from commandline - eclipse

What is the best solution to build several CDT C++ projects from the command line? The projects have references and so it is not possible to just build single projects.

This feature has been added in CDT 6 (Final build due June 15th 2009). You can download the final release candidate from builds page: download.eclipse.org/tools/cdt/builds/6.0.0/.
Using a release of Eclipse 3.5 + CDT 6, you can import, build and clean-build projects and the workspace using the following options sent to Eclipse at the command line:
eclipse -nosplash
-application org.eclipse.cdt.managedbuilder.core.headlessbuild
-import {[uri:/]/path/to/project}
-build {project_name | all}
-cleanBuild {projec_name | all}
On Windows, use eclipsec.exe instead of eclipse.exe to have build output written to stdout/stderr and so that the call blocks until completion.
The '-application' switch instructs Eclipse to run the CDT headless builder rather than starting the workbench. The other switches can be used individually or together. This means you can checkout a project using a shell script of your own, '-import' it into a workspace, and '-build' it using the Managedbuilder's headless builder.
Use the '-data' switch to specify the workspace to use, which can be an empty temporary directory, see the runtime documentation for other switches supported by the platform runtime:
help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
See bug 186847 comment 24 and onwards for more detail on the committed functionality.

Pre CDT 6 you could use the JDT's AptBuilder (included with classic Eclipse, for example).
This lets you build an already configured workspace. So you: checkout your source, configure a workspace which points to the checked-out projects. Your automated build scripts can then update the checkouts and run the AptBuilder without needing to start the GUI.

If you created a Make project under CDT you can just use your favorite shell and execute make in all the projects dirs.

Headless build with the manage builder is currently not supported, see bug 186847 - CDT internal builder does not support automated command line builds.
If you use the unmanaged (make) builder, then you already have Makefiles that you can use from the command line.

We do this in our existing build.
Put a makefile in all your external references and your toplevel project.
In your "all" rule, have it run:
make -C ./externalref1
make -C ./externalref2
etc
we actually define the external dependencies in a variable:
EXT_DEP = externalref1 externalref2
then use the subst (substitute) command to kick off all the sub-makes using the correct call.

Related

How to build an Eclipse project from command line with any pre-existing workspace?

I have a C source repository with an Eclipse project (.project and .cproject files at the top-level). I need to build that project from the command line, so that it is integrated with our CI system.
I know that I can build an Eclipse workspace from the command line (or a specific project within a workspace), as explained here: C++ eclipse project automatic build server and here: Build Eclipse Java Project from Command Line
But what I would like to do is to build a project without having any workspace. It sounds pretty ugly to commit a workspace (.metadata folder) into the source repository.
Is there other command line options for building a project without having to specify a workspace? If not, is it possible to generate the workspace "on the fly"?
I eventually found a solution following this answer: https://stackoverflow.com/a/8908262/6289487
I was using -data command line option, the trick is to use -import.

eclipsec.exe options/ command line usage?

Is there an exhaustive list of documented commands that I can use with eclipsec.exe?
Build Eclipse Java Project from Command Line
I see that we can build projects outside GUI. Is the command line powerful enough to control any other features inside eclipse GUI?
For example : Is it possible to launch a saved "Java Application" inside eclipse workspace from the command line directly?
Basically, I want to explore all options that I have on eclipsec.exe. I tried eclipsec.exe --help and eclipsec.exe -help to see if I can get some help but none of them work.
The Eclipse runtime options
- http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html
using p2 director to install/uninstall plugins
- https://wiki.eclipse.org/Equinox/p2/Director_application
- http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fp2_director.html
There is also linked Question Build Eclipse Java Project from Command Line

Eclipse + CDT: How to batch build several build configurations

I have an eclipse CDT project that builds static and shared libraries. I have created several build configurations for them.
I want to know if there is any way to do a batch build i.e. build all configurations at once with single operation. I tried "Build All" (ctrl+B) but it seems to be building only the current configuration (just that it applies "all" as the target for the current configuration).
One of the earlier posts suggest making use of CMake(http://stackoverflow.com/questions/5204180/how-to-build-several-configurations-at-once-with-cmake) .
Is this the way, or is there any other alternative without getting into CMake.
regards,
Ravi
If you have CDT installed, then there is also a launch configuration type called Launch group. You can create one of that to list all your other already configured launch configurations and to execute one after the other. Make sure to set the post build action in the list dialog to "wait until terminate".
put all your projects into a tree (symlinks), e.g. my/Projects and run a headless build (ref http://gnuarmeclipse.livius.net/blog/headless-builds/)
eclipse -application org.eclipse.cdt.managedbuilder.core.headlessbuild -importAll my/Projects -cleanBuild all -nosplash -data ./eclipse_ws_dir --launcher.suppressErrors -vmargs -Xmx7g

Why does CDT rebuild my C-project on Ant build in unrelated project?

I have an Eclipse workspace where a CDT project lives together with other unrelated projects. However, when I run "build as Ant build" in one of those projects, CDT insists on rebuilding its projects too.
Anyone have any ideas where to look to disconnect this "hidden" dependency? (And no, it's not in the "Linked Resources" or the "Project References"...)
The workspace wide build was actually caused by me failing to find the option for the build in "External Tools Configurations". There you can specify to build the whole workspace, the containing project, or some specific resource.
There is also an Eclipse bug for setting the default to something different than to build the whole workspace. (One could think that "Run as Ant build" would default to not build anything except running the specified Ant target.)
Project builders are run at the request of some build trigger. This might be resource changes (when you have build automatically enabled) or it could be the build action you're using: "build as Ant build". The build action may be inadvertently requesting a build of the whole workspace.
Put the following in a text file:
# Eclipse build
org.eclipse.core.resources/debug=true
org.eclipse.core.resources/build/interrupt=true
org.eclipse.core.resources/build/invoking=true
org.eclipse.core.resources/build/needbuild=true
#Managedbuild
org.eclipse.cdt.managedbuilder.core/debug/builder=true
org.eclipse.cdt.managedbuilder.core/debug=true
org.eclipse.cdt.managedbuilder.core/debug/pathEntryInit=false
org.eclipse.cdt.managedbuilder.core/debug/pathEntry=false
And run Eclipse with the additional switches:
-debug <trace_options>.file
This will echo trace prints to the shell in which you started Eclipse. You can use this to better target the bug report you'll no doubt file :)
Try to uncheck the Build Automatically checkbox, under Project menu.

Setting up a cross-platform C++ project in Eclipse with cross-platform libraries

I am working on a cross-platform C++ project with 8 other people which uses the following libraries:
OpenCV Library
Boost C++ Library
The project is inteded to be cross-platform so all users have agreed not to use platform-specific code, and, to keep things as simple as possible, all users will be using Eclipse as their IDE. However, some will be using Eclipse for Windows while other will be using Eclipse for Linux.
Since the project will be hosted on SVN, we would like to avoid conflicts with different configuration files (like make files, eclipse project files etc..) which are shared. We would also like to share as much of the configuration files as possible through SVN, to keep the configuration as simple as possible.
Let's assume that all users have properly configured system variables and installed the required build tools (such as make, cmake etc.), and have configured their Eclipse settings configured properly (but not the project-specific settings).
How to configure the project once and what of the configuration files to share on the repository, so that both Windows and Linux users can compile it without modifying configuration files retrieved from the SVN repository?
(I am not looking for the complete solution which would specifically work for those 2 libraries I mentioned, so I would appreciate a general how-to step-by-step explanations which would enable me to easily add another library.)
General discussion:
You will need to install Cygwin or something similar to it to make GNU Autotools toolchain available to Eclipse on Windows:
How to deal with Eclipse CDT+Cygwin?
Once your toolchain, Eclipse, with CDT and SVN connectors are ready on your development machines, go through the following steps.
Open Eclipse and switch to CDT: Click Window->Open Perspective->Other... and select C/C++
Select: Eclipse->File->New->C++ Project
Project name: viewer
Select: Project type->GNU Autotools->Hello World C++ Autotools Project
Click: Next
Click: Finish
Right-click in Project Explorer: viewer->Reconfigure project
Click: Console->Display Selected Console submenu-># CDT Global Build Console. If "autoreconf -i" output is nominal, proceed to step 9. If Console reports: sh: autoreconf: command not found, then add the path to the autoreconf command to the Project Build Environment:
Right-click in Project Explorer: viewer->Properties->C/C++ Build->Environment->Add...
Name: PATH
Value: path_to_autoreconf:${env_var:PATH}
Click: OK
Click: Apply
Go back to step 8.
Double-click: Project Explorer->viewer->src->viewer.cpp
Add some code:
include <opencv/cv.h>
include <opencv/highgui.h>
include <cassert>
int main(int argc, char *argv[]) {
assert(argc > 1);
CvMat* img = cvLoadImageM(argv1);
cvNamedWindow("Picture", CV_WINDOW_AUTOSIZE);
cvShowImage("Picture", img);
cvWaitKey(0);
return 0;
}
Double-click: Project Explorer->viewer->configure.ac and enter the following code below AC_PROG_CXX.
AC_CHECK_LIB([opencv_core],[cvSetZero],[],[])
AC_CHECK_LIB([opencv_highgui],[cvShowImage],[],[])
AC_CHECK_LIB([boost_regex-mt],[regexecA],[BOOST_LIB_SUFFIX="-mt"],[BOOST_LIB_SUFFIX=""])
AC_SUBST(BOOST_LIB_SUFFIX)
Double-click: Project Explorer->viewer->src->Makefile.am and enter the following code.
>
bin_PROGRAMS=viewer
viewer_SOURCES=openCvFocusIssue.cpp
viewer_LDFLAGS = -lboost_regex#BOOST_LIB_SUFFIX# -lopencv_core -lopencv_highgui
Repeat step 8, autoreconf (Reconfigure project)
Click: Project Explorer->viewer
Build project by clicking the hammer in the toolbar. If you do not see the hammer, Window->Open Perspective->Other... and select C/C++. If C/C++ does not show up, install the CDT.
Click: Project Explorer->viewer and then Run->Run, then in the Run As window->Local C/C++ Application, then in the Launch Debug Configuration Selection window->gdb/mi and press enter. You should see Hello World.
Quit Eclipse and navigate to the viewer project directory.
On the command line, issue make dist
Ensure you got a viewer-1.0.tar.gz or similarly named file, and then remove it: rm viewer-1.0.tar.gz
On the command line, issue make clean
In the same place, issue make distclean.
Navigate to the workspace directory that contains the viewer project.
Move the entire viewer directory to the directory that contains the svn checkout you want to place the viewer project in.
Change directories to where you just moved the viewer.
svn add viewer && svn ci -m "Added eclipse-autotool project"
Open eclipse and make sure that you have an SVN connector installed.
Remove the "viewer" project from the Project Explorer view.
Open eclipse and add this SVN repository checkout to the Team perspective.
Import the viewer project from your SVN repository checkout.
Switch back to the C/C++ perspective and have fun.
Two suggestions:
Use cmake: I love this tool. There is a bit of a learning curve but
if you get it right all the project will include is the cmake files
and when a person first checks it out they run cmake to generate
their makefiles (or VC++ project files, etc) with all the different rules for linux or windows one
might need.
or
Check in a basic config for the project, then add those configs to the git/svn ignore so no one ever checks them in again, then when you checkout for the first time you have to get your config running but after that it won't be overwritten.