Difference between revisions of "Simple template for libraries in contrib"
Jump to navigation
Jump to search
(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) |
|||
Line 1: | Line 1: | ||
<big>'''These instructions only apply to YARP > 2.3.23 and iCub > 1.1.13 software versions'''</big> | |||
''See [[Simple template for libraries in contrib old]] for older instructions'' | |||
CMake code for a library in contrib is quite similar to that required for modules. | |||
cmake_minimum_required(VERSION 2.8.7) | |||
project(mylibrary) | |||
#find packages, examples YARP and/or ICUB | |||
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} ${ICUB_MODULE_PATH} ${ICUBCONTRIB_MODULE_PATH}) | |||
include(ICUBcontribHelpers) | |||
set_contrib_default_prefix() #set CMAKE_INSTALL_PREFIX to the ICUBcontrib one; print warning if user modifies it | |||
## inherit options from the iCub build (inlcudes rpath settings and | |||
## disables some warnings in msvc | |||
include(iCubOptions) | |||
#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(${PROJECT_NAME} ${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(${PROJECT_NAME} ${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(${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) |
Revision as of 19:43, 10 September 2013
These instructions only apply to YARP > 2.3.23 and iCub > 1.1.13 software versions
See Simple template for libraries in contrib old for older instructions
CMake code for a library in contrib is quite similar to that required for modules.
cmake_minimum_required(VERSION 2.8.7) project(mylibrary)
#find packages, examples YARP and/or ICUB 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} ${ICUB_MODULE_PATH} ${ICUBCONTRIB_MODULE_PATH})
include(ICUBcontribHelpers) set_contrib_default_prefix() #set CMAKE_INSTALL_PREFIX to the ICUBcontrib one; print warning if user modifies it
## inherit options from the iCub build (inlcudes rpath settings and ## disables some warnings in msvc include(iCubOptions)
#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(${PROJECT_NAME} ${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(${PROJECT_NAME} ${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(${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)