Tuesday, June 21, 2011

Using the CMake System

There are a few simple steps for building using the CMake system. It's worth noting that when using CMake, all the output files are put into a separate build directory. This prevents the source directory from getting cluttered with files. Assuming that the source files are in the ibcp sub-directory, an ibcp-build directory will be created. These commands are used for building the project:
  1. mkdir ibcp-build
  2. cd ibcp-build
  3. cmake ../ibcp
  4. make
If no errors occur from Step 3 (like the correct version of GCC was not found), then Step 4 will build the program. All auto-generated include files, object files and the program will be located in the ibcp-build directory. To enable debug information in the executable, the ccmake program is used with these steps:
  1. ccmake ../ibcp
  2. Press Enter on the CMAKE_BUILD_TYPE line
  3. Type in "Debug" and press Enter
  4. Press [c] to configure
  5. Press [g] to generate and exit
  6. Now entering make will build with debug information
Setting the string to "Release" in Step 3 will turn off the debugging information. There is also a "make clean" option. If the build is not performed in the source directory (possible but not recommended), the entire contents of the build directory can also be deleted and cmake rerun. Now that CMake is working on Linux, it is now time to make it work under Windows...