Difference between revisions of "Simple template for modules in contrib old"

From Wiki for iCub and Friends
Jump to navigation Jump to search
m (Elena.ceseracciu@iit.it moved page Simple template for modules in contrib to Simple template for modules in contrib old: Updating installation instructions to account for new YARP2.4 repository structure)
(No difference)

Revision as of 19:38, 10 September 2013

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

Basic template

 cmake_minimum_required(VERSION 2.6)
 find_package(YARP)
 
 include_directories(${YARP_INCLUDE_DIRS})
 add_executable(example1 main.cpp)
 target_link_libraries(example1 ${YARP_LIBRARIES})

Advanced template

 cmake_minimum_required(VERSION 2.6)
 
 set(MODULENAME mymodule)
 find_package(YARP)
 find_package(ICUB)
 
 #optionally: use cmake find scripts provided by YARP and iCub
 set(CMAKE_MODULE_PATH ${YARP_MODULE_PATH} ${CMAKE_MODULE_PATH})
 set(CMAKE_MODULE_PATH ${ICUB_MODULE_PATH} ${CMAKE_MODULE_PATH))
 ## inherit options from the iCub build (inlcudes rpath settings and 
 ## disables some warnings in msvc
 include(iCubOptions)
 ## load some macros useful for applications (see below)
 include(iCubHelpers)
 
 #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(${MODULENAME} main.cpp)
 target_link_libraries(${MODULENAME}  ${YARP_LIBRARIES})
 
 #link other packages
 target_link_libraries(${MODULENAME} ${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(${MODULENAME} ${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(${MODULENAME} ctrlLib)

Applications

The line include(iCubHelpers) loads a set of macros that are useful for defining applications. Instructions for doing this are reported here: http://eris.liralab.it/wiki/Applications.