CMake - CourseReps/ECEN489-Fall2015 GitHub Wiki

Description

CMake is an open-source software for managing the build process of software across multiple platforms. This allows for it build software using a compiler-independent method. Developers across multiple platforms can use CMake to share and collaborate on projects without running into previous issues of differences in the native build environments. It helps automate many steps including compiling and linking.

For this course, we will be using CMake to make sure that all C++ programs built can be compiled on all machines and operating systems. CMake comes integrated into CLion, but CMake must be installed if any other IDE is used instead such as XCode or Microsoft Visual Studio. CLion files can be used to configure and generate the build files using the CMake GUI. See the tutorial below.

CMake works by generating a makefile that is read by the system before compiling.

History

Origins

Originally created to be a cross-platform build environment for the Insight Segmentation and Registration Toolkit (ITK), CMake was influenced by a system called pcmaker. Accelerated development of the tool occurred in early 2001, and many developers contributed improvements as they incorporated it into their systems. Today, CMake has many essential features added and supports a wide variety of systems including GE Corporate R&D and the Advanced Computing Lab at Los Alamos National Laboratory.

Installing CMake

Windows: Use the appropriate link on the download page. It is an executable installer.

Linux, Mac OSX, UNIX & Cygwin: The download page contains pre-compiled binaries. Download the appropriate binary. There are several approaching for building CMake from a source tree.

If no existing CMake is on the machine, use a bootstrap script:

 ./bootstrap
 make
 make install

The make install step is option. Cmake will run from the build directory.

 cmake .
 make
 make install

As before, make install is optional.

On UNIX: If you are not using the GNU C++ compiler, you need to tell the bootstrap with compiler you want to use. For example on the SGI with the 7.3X compiler:

 (setenv CXX CC; setenv CC cc; ./bootstrap)
 make
 make install

For more options with bootstrap, run ./bootstrap --help

More information and help can be found here

Statistics

Statistics

Documentation

CMake comes with a very detailed amount of documentation on all of their features that is kept up to date. Two separate links are provided below. The Wiki covers documentation on all tools in the suite including CPack and CTest.

Webinars

Webinars CMake provides webinars for free that are hosted on vimeo and can be viewed by the link above. Their webinars highlight changes and updates as well as teach introductory CMake courses.

The Introduction to CMake Course is an excellent introduction to CMake. Over the course of an hour an a half, multiple tools are taught and basic configurations are explained. A basic knowledge of C++ is needed before watching the lecture.

Tutorial

  • Using the CMake GUI. Use the Project for Task 2 from CLion as your example. Locate the source code. On my machine, it is found at /Users/Bladeroybal/ClionProjects/Code1

  • In the GUI, select this folder as the source code.

  • Create an empty folder in this folder. I labeled mine as MyPrjFiles. Use this folder as your binaries location.

  • Press Configure and leave the base selection as UNIX and execute.

  • After configuration, press Generate.

  • That is it! This build file contains all Cmake binaries and can be compiled.

If not using CLion to autogenerate the cmakelists.txt files, it is important to know how to write one. This blog contains a very well written and detailed explanation of all parts of the cmakelists.txt file.

How to Pull up the Configuration Dialog Box after initial use

Additional Links