Friday, October 12, 2012

CMake with NetBeans

There were problems getting the new test code to work properly.  Using gdb from the command line was not the first choice (more time is spent looking up help on commands than actually debugging).  So this left NetBeans, which I was hoping to delay if not permanently postpone the use of (for the reason the change in development alluded to earlier, more on this soon).  NetBeans is supposed to work with CMake and it was time to find out. 

In the spirit of staying current, the latest version (7.2) was downloaded from NetBeans.org.  The C/C++ bundle was selected for both Windows and Linux (x86/x64).  The defaults for the installer were used on all three platforms (XP, 7 and Mint 13) and available updates were installed.

On Windows XP and 7, getting NetBeans to work with CMake was problematic, in fact, I never did figure out how to get it to work correctly.  NetBeans appeared to give CMake incorrect options and CMake said that the compiler was not able to be used.  All attempts to get the options that worked were unsuccessful.

The solution found searching the Internet was to run CMake outside of NetBeans, then point NetBeans to the Makefile produced and this worked.  CMake would have to be run outside of NetBeans from then on when needed - not ideal.  After a bit of work, debugging was enabled and the program could be stepped through.

On Mint 13, NetBeans worked with CMake the way it was supposed to.  NetBeans was able to run CMake and build the program.  The program was built with debugging enabled by default.  Debugging the problems in the new test code went without a hitch.  Hit Continue... for details of the procedures on both platforms.

On Windows, before running NetBeans, the make file needs to be generated by CMake.  In CMake (cmake-gui), run as instructed before.  To enable a debug build, after clicking Configure, change the CMAKE_BUILD_TYPE parameter to Debug (from blank), click Configure again followed by Generate.  From the command line, the command would be (from the ibcp/build directory):
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
When running NetBeans, it should discover MinGW.  This can be verified by going to the Tools menu and selecting Options, then the C/C++ section.  Clicking the Versions... button will show the versions of all the tools.  The C Compiler (GCC) should should say 4.6.2 assuming MinGW was installed as instructed on October 5, 2012.  The CMake Command is also set on this dialog, but as mentioned above, this should not be necessary as CMake is being run out side of NetBeans.

To load the ibcp project, from the File menu select New Project..., which starts a series of dialogs.  On 1. Choose Project: make sure C/C++ and C/C++ Project with Existing Sources are selected and click Next.  On 2. Select Mode: select (browse to) the ibcp directory and under Select Configuration Mode: select Custom then click Next.  On 3. Build Tool: select Using an existing makefile, browse to the build directory and select Makefile (which was generated by CMake).  Click Next through the rest of the dialogs including Finish.  NetBeans will then build the program.

On Linux, CMake can be run from within NetBeans.  From the File menu select New Project....  On 1. Choose Project: make sure C/C++ and C/C++ Project with Existing Sources are selected.  On 2. Select Mode: select the ibcp directory and under Select Configuration Mode: select Custom then click Next.  Don't select Automatic (using cmake) as this will build in the source directory, which is not recommended.  On 3. Build Tool: select Run Configure Script in Subfolder.  Click through the rest of the dialogs.  NetBeans will then run CMake and build the program.

To set the program command line options, go to the File menu select Project Properties (ibcp) and then under Categories select Run.  Add the options to the Run Command line after the "${OUTPUT_PATH}" for example " ‑p 1" (without the quotes) to run parser test #1.

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)