Simple template for modules in contrib

From Wiki for iCub and Friends
Jump to navigation Jump to search

These instructions only apply to YARP > 2.3.23 and iCub > 1.1.13 software versions

See Simple template for modules in contrib old for older instructions

Modules in contrib are external to the iCub build. As such they cannot rely on pre-configuration steps that are automatically done in the build.

These are:

  • calls to FIND_PACKAGE()
  • access to Find scripts provided in YARP and iCub conf directories

Furthermore, in order to have common installation directories (especially for installed data), the ICUBcontrib package has to be configured with CMake (choosing the installation prefix) and installed prior to installing contrib modules. This package provides the CMake variables that should be used to install data (application descriptions, module descriptions, configuration files) that are supposed to be found by YARP's ResourceFinder.

Basic template

 cmake_minimum_required(VERSION 2.8,7)
 find_package(YARP REQUIRED)
 
 include_directories(${YARP_INCLUDE_DIRS})
 add_executable(example1 main.cpp)
 target_link_libraries(example1 ${YARP_LIBRARIES})

Advanced template

 cmake_minimum_required(VERSION 2.8.7)
 
 project(mymodule) #provide project name here
 find_package(YARP REQUIRED)
 find_package(ICUB REQUIRED)
 find_package(ICUBcontrib REQUIRED)
 #optionally: use cmake find scripts provided by YARP and iCub
 list(APPEND CMAKE_MODULE_PATH ${YARP_MODULE_PATH})
 list(APPEND CMAKE_MODULE_PATH ${ICUB_MODULE_PATH})
 list(APPEND CMAKE_MODULE_PATH ${ICUBCONTRIB_MODULE_PATH})
 include(ICUBcontribHelpers)
 icubcontrib_set_default_prefix() #set CMAKE_INSTALL_PREFIX to the ICUBcontrib one; print warning if user modifies it
 ## useful options
 include(ICUBcontribOptions)
 ## load some macros useful for applications (see below)
 include(YarpInstallationHelpers)
 
 #find packages
 find_package(GSL)
 find_package(OpenCV)
 include_directories(${YARP_INCLUDE_DIRS})
 include_directories(${ICUB_INCLUDE_DIRS})
 include_directories(${GSL_INCLUDE_DIRS})
 include_directories(${OpenCV_INCLUDE_DIRS})
 
 add_executable(${PROJECT_NAME} main.cpp)
 target_link_libraries(${PROJECT_NAME}  ${YARP_LIBRARIES})
 
 #link other packages
 target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES} ${GSL_LIBRARIES})

if you want to link all the libraries in iCub, you can rely on the ICUB_LIBRARIES variable:

 #link against all libraries in the iCub build
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ICUB_LINK_FLAGS}")	
 target_link_libraries(${PROJECT_NAME} ${ICUB_LIBRARIES})

but you might prefer to just link the one you actually need:

 #link against single libraries in the iCub package
 #Important: notice that we use the name of the project
 target_link_libraries(${PROJECT_NAME} ctrlLib)
 install(TARGETS ${PROJECT_NAME} DESTINATION bin)

Applications

The line include(YarpInstallationHelpers) loads a set of macros that are useful for defining applications. Instructions for doing this are reported here: http://wiki.icub.org/wiki/Applications.