Difference between revisions of "CMake"

From Wiki for iCub and Friends
Jump to: navigation, search
(Install CMake)
(update cmake instruction)
 
Line 9: Line 9:
 
== Install CMake ==
 
== Install CMake ==
  
* Install CMake from here: http://www.cmake.org/HTML/Download.html
+
* For Windows download the CMake installer from : https://cmake.org/download/ .  
** Windows: http://www.cmake.org/files/v2.4/cmake-2.4.6-win32-x86.exe
+
* For OS X, the easiest way to install CMake is homebrew http://brew.sh/ :
** OSX Tiger: http://www.cmake.org/files/v2.4/cmake-2.4.6-Darwin-universal.dmg
+
  brew install cmake  
** Generic Linux: http://www.cmake.org/files/v2.4/cmake-2.4.6-Linux-i386.sh
+
* For Linux distributions and *BSD, use the CMake version distributed by your package.  
** Debian Linux: apt-get install cmake
+
** In particular on Debian/Ubuntu you can install cmake throught apt:
** SUSE Linux: add the [http://en.opensuse.org/Additional_YaST_Package_Repositories#Guru GURU] YAST repository and use YAST for installing CMake or download directly the rpm from [http://linux01.gwdg.de/~pbleser/allpackages.php GURU website access]
+
   sudo apt-get install cmake
** We've had reports that CMake has problems if you install it in one location and then try to run it via a symbolic link from another location.  We suggest you use a short script rather than a symbolic link if you need to do something like this.  For example, if the cmake binary is installed in /opt/cmake/bin/cmake and you wish to execute it as /usr/local/bin/cmake, then make a script at /usr/local/bin/cmake with the contents:
 
   #!/bin/sh
 
  exec /opt/cmake/bin/cmake $*
 
  
 
== CMake in Windows ==
 
== CMake in Windows ==
Line 51: Line 48:
 
In the same directory, create a file called "main.cpp".  In it place the following:
 
In the same directory, create a file called "main.cpp".  In it place the following:
  
   #include <stdio.h>
+
   #include <cstdio>
 
   int main() {
 
   int main() {
 
     printf("CMake the world a better place!\n");
 
     printf("CMake the world a better place!\n");

Latest revision as of 13:12, 30 March 2016

Why CMake?

We'd like you all to use the development environment you are used to, and not force you to switch to something else -- no Linux/g++/emacs vs Windows/DevStudio vs Mac/... fights please!

To achieve this without complete chaos, we ask you to install "CMake". CMake lets us describe our programs and libraries in a cross-platform way. CMake takes care of building the makefiles or workspaces needed by whatever development environment you like to work in.

Install CMake

 brew install cmake 
  • For Linux distributions and *BSD, use the CMake version distributed by your package.
    • In particular on Debian/Ubuntu you can install cmake throught apt:
 sudo apt-get install cmake

CMake in Windows

On Windows, the easiest way to use CMake is via its GUI. After installing, you should have an icon for CMake in your START menu. Click that, then fill in the path to your code, and the path you want CMake to build in (that can be the same if you want). Click "configure". Depending on the project, configuration may involve several steps -- you may have to answer new questions and click "configure" again. When the "OK" button becomes clickable, then CMake has enough information to set up your project. Click "OK" and you're done. Project files of the type you specified should exist in the build path you gave.

If you want to start over from the beginning with CMake, it is important to press the "delete cache" button to make it forget everything you've told it.

CMake in UNIX

On UNIX CMake can be used conveniently in two ways:

  • From the command line : type "cmake ."
  • Interactively: type "ccmake ."

If you are running CMake while in a directory different to where your code is, replace "." with the path to your code.

"ccmake" is very much like the Windows GUI, and you may need to iterate "configure" a few times before the option to "generate" appears.

"cmake" doesn't ask questions, and just uses defaults. You can pass it values on the command line:

  cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .

The generated file "CMakeCache.txt" contains all settings stored by CMake. It can be useful to delete this if you want to start over completely.

An Example

Create a new directory, something like $HOME/cmake/example or C:\cmake\example.

Inside that directory, create a file called "CMakeLists.txt". In it place the following:

 PROJECT(example)
 ADD_EXECUTABLE(example main.cpp)

In the same directory, create a file called "main.cpp". In it place the following:

 #include <cstdio>
 int main() {
   printf("CMake the world a better place!\n");
   return 0;
 }

In UNIX, type "cmake ." in that directory, and then "make", and then "./example". Easy!

On Windows, run the CMake GUI, fill in the path to the example, click "configure", say what compiler you use, click "configure" again if needed, then click "ok". Then run your compiler, and finally the program. Easy!

Notice that the abstract description of our project above can be shared by developers on Windows, Linux, OSX, ...