CMake and building

Your CMakeLists.txt files will be created by the orocreate-pkg tool. However, when you need to tune your build, you'll need more information which you can find below.

Finding RTT and its plugins

In order to locate RTT or one of the plugins on your filesystem, you need to modify the find_package(OROCOS-RTT REQUIRED) command to find_package(OROCOS-RTT REQUIRED <pluginlibname>). For example:
find_package(OROCOS-RTT REQUIRED rtt-marshalling)
# Defines: ${OROCOS-RTT_RTT-MARSHALLING_LIBRARY} and ${OROCOS-RTT_RTT-MARSHALLING_FOUND}

pre-2.3.2: You may only call find_package(OROCOS-RTT ... ) once. Next calls to this macro will return immediately, so you need to specify all plugins up-front. RTT versions from 2.3.2 on don't have this limitation.

Using find_package(OROCOS-RTT)

After find_package found the RTT and its plugins, you must explicitly use the created CMake variables in order to have them in effect. This looks typically like:

# Link all targets AFTER THIS LINE with 'rtt-scripting' COMPONENT:
if ( OROCOS-RTT_RTT-SCRIPTING_FOUND )
  link_libraries( ${OROCOS-RTT_RTT-SCRIPTING_LIBRARY} )
else( OROCOS-RTT_RTT-SCRIPTING_FOUND )
  message(SEND_ERROR "'rtt-scripting' not found !")
endif( OROCOS-RTT_RTT-SCRIPTING_FOUND )
 
# now define your components, libraries etc...
 
# ...
 
#Prefered way to link instead of the above method:
target_link_libraries( mycomponent ${OROCOS-RTT_RTT-SCRIPTING_LIBRARY})

Or for linking with the standard provided CORBA transport:

# Link all targets AFTER THIS LINE with the CORBA transport (detected by default!) :
if ( OROCOS-RTT_CORBA_FOUND )
  link_libraries( ${OROCOS-RTT_CORBA_LIBRARIES} )
else( OROCOS-RTT_CORBA_FOUND )
  message(SEND_ERROR "'CORBA' transport not found !")
endif( OROCOS-RTT_CORBA_FOUND )
 
# now define your components, libraries etc...
 
# ...
 
#Prefered way to link instead of the above method:
target_link_libraries( mycomponent ${OROCOS-RTT_RTT_CORBA_LIBRARIES})

Using other packages for building and linking (orocos_use_package)

Orocos has a system which lets you specify which packages you want to use for including headers and linking with their libraries. Orocos will always get these flags from a pkg-config .pc file, so in order to use this system, check that the package you want to depend on provides such a .pc file.

If the package or library you want to use has a .pc file, you can directly use this macro:

# The CORBA transport provides a .pc file 'orocos-rtt-corba-<target>.pc':
orocos_use_package( orocos-rtt-corba )
 
# Link with the OCL Deployment component:
orocos_use_package( ocl-deployment )
 
# now define your components, libraries etc...

This macro has a similar effect as putting this dependency in your manifest.xml file, it sets the include paths and links your libraries if OROCOS_NO_AUTO_LINKING is not defined in CMake (the default). Some packages (like OCL) define multiple .pc files, in which case you can put the ocl dependency in the manifest.xml file and use orocos_use_package() to use a specific ocl .pc file.

If the argument to orocos_use_package() is a real package, it is advised to put the dependency in the manifest.xml file, such that the build system can use that information for dependency tracking. In case it is a library as a part of a package (in this case: CORBA is a sub-library of the 'rtt' package), you should put rtt as a dependency in the manifest.xml file, and orocos-rtt-corba with the orocos_use_package macro as shown above.

find_package(OROCOS-RTT) syntax

The Orocos-RTT find macro has this API (copied from the orocos-rtt.config.cmake file of RTT):
##################################################################################
#
# CMake package configuration file for the OROCOS-RTT package.
# This script imports targets and sets up the variables needed to use the package.
# In case this file is installed in a nonstandard location, its location can be 
# specified using the OROCOS-RTT_DIR cache
# entry.
#
# find_package COMPONENTS represent OROCOS-RTT plugins such as scripting,
# marshalling or corba-transport.
# The default search path for them is:
#  /path/to/OROCOS-RTTinstallation/lib/orocos/plugins
#  /path/to/OROCOS-RTTinstallation/lib/orocos/types
#
# For this script to find user-defined OROCOS-RTT plugins, the RTT_COMPONENT_PATH 
# environment variable should be appropriately set. E.g., if the plugin is located 
# at /path/to/plugins/libfoo-plugin.so, then add /path/to to RTT_COMPONENT_PATH
#
# This script sets the following variables:
#  OROCOS-RTT_FOUND: Boolean that indicates if OROCOS-RTT was found
#  OROCOS-RTT_INCLUDE_DIRS: Paths to the necessary header files
#  OROCOS-RTT_LIBRARIES: Libraries to link against to use OROCOS-RTT
#  OROCOS-RTT_DEFINITIONS: Definitions to use when compiling code that uses OROCOS-RTT
#
#  OROCOS-RTT_PATH: Path of the RTT installation directory (its CMAKE_INSTALL_PREFIX).
#  OROCOS-RTT_COMPONENT_PATH: The component path of the installation 
#                             <prefix>/lib/orocos + RTT_COMPONENT_PATH
#  OROCOS-RTT_PLUGIN_PATH: OROCOS-RTT_PLUGINS_PATH + OROCOS-RTT_TYPES_PATH
#  OROCOS-RTT_PLUGINS_PATH: The plugins path of the installation 
#                           <prefix>/lib/orocos/plugins + RTT_COMPONENT_PATH * /plugins
#  OROCOS-RTT_TYPES_PATH: The types path of the installation 
#                         <prefix>/lib/orocos/types + RTT_COMPONENT_PATH * /types
#
#  OROCOS-RTT_CORBA_FOUND: Defined if corba transport support is available
#  OROCOS-RTT_CORBA_LIBRARIES: Libraries to link against to use the corba transport
#
#  OROCOS-RTT_MQUEUE_FOUND: Defined if mqueue transport support is available
#  OROCOS-RTT_MQUEUE_LIBRARIES: Libraries to link against to use the mqueue transport
#
#  OROCOS-RTT_VERSION: Package version
#  OROCOS-RTT_VERSION_MAJOR: Package major version
#  OROCOS-RTT_VERSION_MINOR: Package minor version
#  OROCOS-RTT_VERSION_PATCH: Package patch version
#
#  OROCOS-RTT_USE_FILE_PATH: Path to package use file, so it can be included like so
#                            include(${OROCOS-RTT_USE_FILE_PATH}/UseOROCOS-RTT.cmake)
#  OROCOS-RTT_USE_FILE     : Allows you to write: include( ${OROCOS-RTT_USE_FILE} )
#
# This script additionally sets variables for each requested 
# find_package COMPONENTS (OROCOS-RTT plugins).
# For example, for the ''rtt-scripting'' plugin this would be:
#  OROCOS-RTT_RTT-SCRIPTING_FOUND: Boolean that indicates if the component was found
#  OROCOS-RTT_RTT-SCRIPTING_LIBRARY: Libraries to link against to use this component 
#                                    (Notice singular _LIBRARY suffix !)
#
# Note for advanced users: Apart from the OROCOS-RTT_*_LIBRARIES variables, 
# non-COMPONENTS targets can be accessed by their imported name, e.g., 
# target_link_libraries(bar @IMPORTED_TARGET_PREFIX@orocos-rtt-gnulinux_dynamic).
# This of course requires knowing the name of the desired target, which is why using 
# the OROCOS-RTT_*_LIBRARIES variables is recommended.
#
# Example usage:
#  find_package(OROCOS-RTT 2.0.5 EXACT REQUIRED rtt-scripting foo) 
#               # Defines OROCOS-RTT_RTT-SCRIPTING_*
#  find_package(OROCOS-RTT QUIET COMPONENTS rtt-transport-mqueue foo)
#               # Defines OROCOS-RTT_RTT-TRANSPORT-MQUEUE_* 
#
##################################################################################

Orocos CMakeLists.txt Example

This example is identical to the result of running:
orocreate-pkg example

You may remove most of the code/statements that you don't use. We only left the most common CMake macros not commented, which tells you which ones you should use most certainly when building a component:

#
# The find_package macro for Orocos-RTT works best with
# cmake >= 2.6.3
#
cmake_minimum_required(VERSION 2.6.3)
 
#
# This creates a standard cmake project. You may extend this file with
# any cmake macro you see fit.
#
project(example)
 
 
# Set the CMAKE_PREFIX_PATH in case you're not using Orocos through ROS
# for helping these find commands find RTT.
find_package(OROCOS-RTT REQUIRED ${RTT_HINTS})
 
# Defines the orocos_* cmake macros. See that file for additional
# documentation.
include(${OROCOS-RTT_USE_FILE_PATH}/UseOROCOS-RTT.cmake)
 
#
# Components, types and plugins.
#
# The CMake 'target' names are identical to the first argument of the
# macros below, except for orocos_typegen_headers, where the target is fully
# controlled by generated code of 'typegen'.
#
 
 
# Creates a component library libexample-<target>.so
# and installs in the directory lib/orocos/example/
#
orocos_component(example example-component.hpp example-component.cpp) # ...you may add multiple source files
#
# You may add multiple orocos_component statements.
 
#
# Building a typekit (recommended):
#
# Creates a typekit library libexample-types-<target>.so
# and installs in the directory lib/orocos/example/types/
#
#orocos_typegen_headers(example-types.hpp) # ...you may add multiple header files
#
# You may only have *ONE* orocos_typegen_headers statement !
 
#
# Building a normal library (optional):
#
# Creates a library libsupport-<target>.so and installs it in
# lib/
#
#orocos_library(support support.cpp) # ...you may add multiple source files
#
# You may add multiple orocos_library statements.
 
 
#
# Building a Plugin or Service (optional):
#
# Creates a plugin library libexample-service-<target>.so or libexample-plugin-<target>.so
# and installs in the directory lib/orocos/example/plugins/
#
# Be aware that a plugin may only have the loadRTTPlugin() function once defined in a .cpp file.
# This function is defined by the plugin and service CPP macros.
#
#orocos_service(example-service example-service.cpp) # ...only one service per library !
#orocos_plugin(example-plugin example-plugin.cpp) # ...only one plugin function per library !
#
# You may add multiple orocos_plugin/orocos_service statements.
 
 
#
# Additional headers (not in typekit):
#
# Installs in the include/orocos/example/ directory
#
orocos_install_headers( example-component.hpp ) # ...you may add multiple header files
#
# You may add multiple orocos_install_headers statements.
 
#
# Generates and installs our package. Must be the last statement such
# that it can pick up all above settings.
#
orocos_generate_package()