Compiling with CMake

In series 3.1, we use a tool called "CMake" to ease the compiling procedure.

First install CMake. In Ubuntu, you can do it by;

$ sudo apt-get install cmake

CMake is used to get the Makefile and Visual C++ project files generated, based on a configuration file called "CMakeLists.txt" that kept in each directory of OpenHRP3 source package. Generating procedure starts as follows;
(Note: Visual C++ files are not completely listed yet)

Move to top of source directory and enter;

$ ccmake .
CMake configuration panel will be opened.

Now you are in the state, prior to start the configuration. Hit "c" to proceed. It will automatically search for required libraries and set necessary configurations to use them.

However, in some cases cmake may not be able to find the libraries/files that are not kept in standard directory or the directory pointed by path. In this case, you will be notified as "Cmake Error: <cause of the error>". For instance, if tvtmet library is not found, it will be informed as;

$ CMake Error: Could not find tvmet. Please set TVMET_DIR correctly

In case of such error, press "e" according to the instruction shown at the bottom of the screen. You will be moved to a screen where you can edit the value of directory paths.

Here, for example you may see "TVMET_DIR-NOTFOUNT" for the "TVMET_DIR" entry. Set the erroneous entries appropriately. Move the cursor to the entry and press "Enter". Then enter the correct path. Here you can use "TAB" key to interpolate the file path.

When you are done, hit "c". Settings will be reconfigured, and the error will be gone if you have entered the correct value. Repeat this process until all errors are get cleared.

Even there is no error, you can set the library path to somewhare that is not the default path. For instance, if you want to use a library in home directory that installed by your self, set the corresponded library entry to point the path where you are intended.

Finally, press "g". Makefile will be generated automatically according to the configuration settings.

The above mentioned operation can also be done as batch-process. In that case, use the command "cmake" instead of "ccmake". For instance, if you see no errors in library configuration, Makefile can get generated simply by entering,

$ cmake .

"Make" can be done normally with this newly generated Makefile. Since the dependences have also been stated perfectly, there is no need to use "make clean" to clean the previous compilation, at each time you make changes in source codes. Moreover, parallel compiling for 'n' processes is also possible by using the command "make -j n".

When you make using the Makefile that was generated by cmake, you will not see each and every compilation result in command-line. Instead, it will give you a neat report with most important results such as processing file and prograss rate etc. However, if you want to see the individual compilation results in command-line, use following command;

$ make VERBOSE=1
If you want to set this as default make style, go to cmake settings and set "ON" in "CMAKE_VERBOSE_MAKEFILE" item.

For more about cmake, visit http://www.cmake.org/ and refer the documents at http://www.cmake.org/Wiki/CMake or http://www.cmake.org/HTML/CMake-2.4.html .

If you hope to add a new source file to the package in future, beware to edit CMakeLists.txt but not Makefile.

Allocating separate location for build-directory

Here we describe how to set build-directory to a seperated location apart from the source-directory.

Suppose your source-directory is /OpenHRP3.1 and build-directory is /test.

$ cd /test
$ ccmake ../OpenHRP3.1
This will open cmake-settings panel.

Once you are done with settings, press "g" to generate build-files and directory. You can see build-files (Makefile, CMakeCache.txt) and working-directory generated in /test.

If you already have those build-files in /OpenHRP3.1, the above process will cause to reconfigure them. Therefore you better delete or rename and take a backup of those files in advance.