Simple template for libraries in main

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

Basic template

 set (PROJECTNAME mylibrary)
 
 project(${PROJECTNAME})
 
 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})


Advanced template

 set (PROJECTNAME mylibrary)
 
 project(${PROJECTNAME})
 
 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)
 include_directories(${YARP_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}  
                     ${ctrlLib_INCLUDE_DIRS})
 
 
 source_group("Source Files" FILES ${folder_source})
 source_group("Header Files" FILES ${folder_header})
 
 add_library(${PROJECTNAME} ${folder_source} ${folder_header})
 
 #important, do not forget dependencies
 #here ctrLib is a library provided within the iCub build, notice we use the 
 #name of the project
 target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES} ctrlLib)
 
 #optionally, export the library (also set installation rule)
 icub_export_library(${PROJECT_NAME}
                     INTERNAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
                     EXTERNAL_INCLUDE_DIRS ${ctrlLib_INCLUDE_DIRS}
                     DESTINATION include/iCub 
                     FILES ${folder_header})