Building Eclipse and MCUXpresso IDE Projects from the Command Line

Eclipse as IDE takes care about compiling and building all my source files. But in an automated build system I would like to build it from the command line too. While using make files (see “Tutorial: Makefile Projects with Eclipse“) is an option, there is another easy way to build Eclipse projects from the command line:

Building MCUXpresso IDE from Command Line

Building MCUXpresso IDE from Command Line

Outline

I’m using the MCUXpresso 10.0.2 (Eclipse Neon based with GNU ARM tools) in this article, but the same should work for any other Eclipse version. The principle is to launch Eclipse in ‘headless mode’ using the org.eclipse.cdt.managedbuilder.core.headlessbuild plugin.

Batch File

I’m using the following batch file to do a command line (aka ‘headless’ build) with Eclipse:

# Batch file to build an Eclipse project from the command line on Windows
# Example for using MCUXpresso IDE

# path to GNU tools and compiler: arm-none-eabi-gcc.exe, ....
SET TOOLCHAIN_PATH=C:\nxp\MCUXpressoIDE_10.0.2_411\ide\tools\bin

# variable to the command line Eclipse IDE executable
SET IDE=C:\nxp\MCUXpressoIDE_10.0.2_411\ide\mcuxpressoidec.exe

ECHO Extending PATH if not already present
ECHO %PATH%|findstr /i /c:"%TOOLCHAIN_PATH:"=%">nul || set PATH=%PATH%;%TOOLCHAIN_PATH%

ECHO Launching Eclipse IDE
"%IDE%" -nosplash --launcher.suppressErrors -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data "c:\tmp\wsp" -build frdmk64f_rtos_examples_freertos_event

The batch file can be found on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/MCUXpresso/CmdLineBuild

It uses the following batch variables:

  • TOOLCHAIN_PATH: path variable to the compiler/linker/etc
  • IDE: path/name variable of the command line IDE. On Windows it is the Eclipse executable with a ‘c’ at the end, for Linux it is the normal Eclipse executable

Additional variables (or arguments) could be used for the workspace name and project name. The batch file checks if the toolchain path is already present in the PATH. If not, it gets added.

Then it launches the IDE with the following options:

  • -nosplash: do not show splash screen
  • –launcher.suppressErrors: do not show error dialog (e.g. if workspace is already used)
  • -application org.eclipse.cdt.managedbuilder.core.headlessbuild: launch the IDE in commandline/headless mode
  • -data <wsp folder name>: workspace to be used. Can be an empty workspace, but then I have to use the -import or -importAll option to import projects (see options in next section)
  • -build <project nam>: build the project

The above builds a single project in a workspace. See next section or the Links section at the end for other options.

Other headless build options

The complete set of options can be found e.g. in http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/tree/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java:

/**
 * Helper method to process expected arguments
 *
 * Arguments
 *   -import     {[uri:/]/path/to/project}
 *   -importAll  {[uri:/]/path/to/projectTreeURI} Import all projects in the tree
 *   -build      {project_name_reg_ex/config_name_reg_ex | all}
 *   -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
 *   -I          {include_path} additional include_path to add to tools
 *   -include    {include_file} additional include_file to pass to tools
 *   -D          {prepoc_define} addition preprocessor defines to pass to the tools
 *   -E			 {var=value} replace/add value to environment variable when running all tools
 *   -Ea		 {var=value} append value to environment variable when running all tools
 *   -Ep		 {var=value} prepend value to environment variable when running all tools
 *   -Er         {var} remove/unset the given environment variable
 *   -T          {toolid} {optionid=value} replace a tool option value
 *   -Ta         {toolid} {optionid=value} append to a tool option value
 *   -Tp         {toolid} {optionid=value} prepend to a tool option value
 *   -Tr         {toolid} {optionid=value} remove a tool option value
 *   -no-indexer Disable indexer
 *   -markerType Which markers to consider
 *   -printErrorMarkers Print all error markers that caused build to fail
 *
 * Each argument may be specified more than once
 * @param args String[] of arguments to parse
 * @return boolean indicating success
 */

Summary

With the headless build options I can use Eclipse to build projects from the command line.

Another option would be to use Eclipse with normal make file projects (see “Tutorial: Makefile Projects with Eclipse“), then I could use make with that makefile (make -f myMakefile.mak). That builds faster, because it does not need to start the IDE, but is more work to set up the makes files. Otherwise the IDE headless build is a very good alternative.

Happy Commanding 🙂

Links

Advertisements

3 thoughts on “Building Eclipse and MCUXpresso IDE Projects from the Command Line

  1. I think whats needed to safely archive a project and “detach it” from the installed toolchain and IDE is a project release tool that exports the project, generates makefiles and copies the toolchain into a folder that can be zipped up into an archive. So perhaps in 10 – 15 yrs time it may be possible to compile the project.

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s