Simple template for modules in main

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

Basic template

 set(PROJECTNAME yourmodule)
 project(${PROJECTNAME})
 
 set(folder_source main.cpp file1.cpp file2.cpp)
 set(header_files  file1.h file2.h)
 
 source_group("Source Files" FILES ${folder_source})
 source_group("Header Files" FILES ${header_files})
 #add local directory 
 include_directories(${PROJECT_SOURCE_DIR})
 #if using YARP
 include_directories(${YARP_INCLUDE_DIRS})
 add_executable(${PROJECTNAME} ${folder_source} ${header_files})
  
 #add yarp if needed, no need to call FIND_PACAKGE()
 target_link_libraries(${PROJECTNAME} ${YARP_LIBRARIES}) 
 
 install(TARGETS ${PROJECTNAME} DESTINATION bin)

Advanced template

 set(PROJECTNAME yourmodule)
 project(${PROJECTNAME})
 
 set(folder_source main.cpp file1.cpp file2.cpp)
 set(header_files  file1.h file2.h)
 
 source_group("Source Files" FILES ${folder_source})
 source_group("Header Files" FILES ${header_files})
 #add local directory 
 include_directories(${PROJECT_SOURCE_DIR})
 #and/or, better:
 include_directories(${PROJECT_SOURCE_DIR}/include)
 #if using YARP
 include_directories(${YARP_INCLUDE_DIRS})
 #if using other packages
 include_directories(${OpenCV_INCLUDE_DIRS})
 include_directories(${GSL_INCLUDE_DIRS})
 ...
 #if using libraries defined within iCub (e.g. ctrLib)
 include_directories(${ctrLib_INCLUDE_DIRS})
 ...
 
 ADD_EXECUTABLE(${PROJECTNAME} ${folder_source} ${header_files})
  
 #add yarp if needed, no need to call FIND_PACAKGE()
 target_link_libraries(${PROJECTNAME} ${YARP_LIBRARIES}) 
 
 #optionally, list of external packages
 target_link_libraries(${PROJECTNAME} ${OpenCV_LIBRARIES})
 target_link_libraries(${PROJECTNAME} ${GSL_LIBRARIES})
 ...
 #if using libraries defined within iCub
 #Important: notice that here we use the name of the project and
 #not <project>_LIBRARIES
 target_link_libraries(${PROJECTNAME} ctrLib)
 INSTALL(TARGETS ${PROJECTNAME} DESTINATION bin)