Difference between revisions of "Simple template for libraries 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 libraries in contrib to Simple template for libraries in contrib old: Updating installation instructions to account for new YARP2.4 repository structure)
(No difference)

Revision as of 19:42, 10 September 2013

CMake code for a library in contrib is quite similar to that required for modules.

cmake_minimum_required(VERSION 2.6)
set (PROJECTNAME mylibrary)

project(${PROJECTNAME})
#find packages, examples YARP and/or ICUB
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})
set(folder_source src/file1.cpp src/file2.cpp)
set(folder_header include/iCub/file1.h include/iCub/file2.h)

# add local directory and other (optional) packages to to search path for 
# header files 
include_directories(${PROJECT_SOURCE_DIR}/include)

source_group("Source Files" FILES ${folder_source})
source_group("Header Files" FILES ${folder_header})

add_library(${PROJECTNAME} ${folder_source} ${folder_header})
#link other packages, this is required to let cmake know dependencies
#your code will compile without this, but you can have problems linking agains
#your lib in modules using it
target_link_libraries(${PROJECTNAME} ${YARP_LIBRARIES} ${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(${PROJECTNAME} ${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(${PROJECTNAME} ctrlLib)