Skip to content

Commit

Permalink
Make examples independent from main build system
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Feb 1, 2017
1 parent dd6cbdc commit b490cc6
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 66 deletions.
63 changes: 37 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,6 @@ if(DART_VERBOSE)
message(STATUS "CMAKE_BINARY_DIR : ${CMAKE_BINARY_DIR}")
endif(DART_VERBOSE)

#===============================================================================
# Helper Functions
#===============================================================================
function(dart_add_example)
dart_property_add(DART_EXAMPLES ${ARGN})
endfunction(dart_add_example)

function(dart_add_tutorial)
dart_property_add(DART_TUTORIALS ${ARGN})
endfunction(dart_add_tutorial)

function(dart_format_add)
dart_property_add(DART_FORMAT_FILES ${ARGN})
endfunction()

#===============================================================================
# Add sub-directories
#===============================================================================
Expand All @@ -279,9 +264,36 @@ if(TINYXML_FOUND AND TINYXML2_FOUND AND BULLET_FOUND)

if (OPENGL_FOUND AND HAVE_GLUT)

# Add an "examples" target to build examples.
add_subdirectory(examples EXCLUDE_FROM_ALL)
# Add example targets
dart_add_example(examples/addDeleteSkels dart dart-utils-urdf dart-gui)
dart_add_example(examples/atlasSimbicon dart dart-utils-urdf dart-gui)
dart_add_example(examples/bipedStand dart dart-utils-urdf dart-gui)
dart_add_example(examples/hardcodedDesign dart dart-utils-urdf dart-gui)
dart_add_example(examples/hybridDynamics dart dart-utils-urdf dart-gui)
dart_add_example(examples/jointConstraints dart dart-utils-urdf dart-gui)
dart_add_example(examples/mixedChain dart dart-utils-urdf dart-gui)
dart_add_example(examples/operationalSpaceControl dart dart-utils-urdf dart-gui)
dart_add_example(examples/rigidChain dart dart-utils-urdf dart-gui)
dart_add_example(examples/rigidLoop dart dart-utils-urdf dart-gui)
dart_add_example(examples/rigidShapes dart dart-utils-urdf dart-gui)
dart_add_example(examples/simpleFrames dart dart-utils-urdf dart-gui)
dart_add_example(examples/softBodies dart dart-utils-urdf dart-gui)
dart_add_example(examples/speedTest dart dart-utils-urdf dart-gui)
dart_add_example(examples/vehicle dart dart-utils-urdf dart-gui)

if(HAVE_OPENSCENEGRAPH)
dart_add_example(examples/osgExamples/osgAtlasPuppet dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgAtlasSimbicon dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgDragAndDrop dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgEmpty dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgHuboPuppet dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgImGui dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgOperationalSpaceControl dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgSoftBodies dart dart-utils-urdf dart-gui-osg)
dart_add_example(examples/osgExamples/osgTinkertoy dart dart-utils-urdf dart-gui-osg)
endif()

# Add an "examples" target to build examples.
get_property(examples GLOBAL PROPERTY DART_EXAMPLES)
add_custom_target(examples DEPENDS ${examples})

Expand All @@ -297,15 +309,14 @@ if(TINYXML_FOUND AND TINYXML2_FOUND AND BULLET_FOUND)
endif(DART_VERBOSE)

# Add tutorial targets
dart_get_subdir_list(tutorial_subdirs ${CMAKE_CURRENT_LIST_DIR}/tutorials)
foreach(child ${tutorial_subdirs})
if(IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/tutorials/${child}")
file(GLOB srcs "${CMAKE_CURRENT_LIST_DIR}/tutorials/${child}/*.cpp")
add_executable(${child} EXCLUDE_FROM_ALL ${srcs})
target_link_libraries(${child} dart dart-utils-urdf dart-gui)
dart_add_tutorial(${child})
endif()
endforeach()
dart_add_tutorial(tutorials/tutorialBiped dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialBiped-Finished dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialCollisions dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialCollisions-Finished dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialDominoes dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialDominoes-Finished dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialMultiPendulum dart-utils-urdf dart-gui)
dart_add_tutorial(tutorials/tutorialMultiPendulum-Finished dart-utils-urdf dart-gui)

# Add a "tutorials" target to build tutorials.
get_property(tutorials GLOBAL PROPERTY DART_TUTORIALS)
Expand Down
35 changes: 35 additions & 0 deletions cmake/DARTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,38 @@ function(dart_check_optional_package variable component dependency)
return()
endif()
endfunction()

#===============================================================================
function(dart_add_custom_target rel_dir property_name)
set(abs_dir "${CMAKE_CURRENT_LIST_DIR}/${rel_dir}")

if(NOT IS_DIRECTORY ${abs_dir})
message(SEND_ERROR "Failed to find directory: ${abs_dir}")
endif()

# Use the directory name as the executable name
get_filename_component(target_name ${rel_dir} NAME)

file(GLOB hdrs "${abs_dir}/*.hpp")
file(GLOB srcs "${abs_dir}/*.cpp")
if(srcs)
add_executable(${target_name} EXCLUDE_FROM_ALL ${hdrs} ${srcs})
target_link_libraries(${target_name} ${ARGN})
dart_property_add(${property_name} ${target_name})
endif()
endfunction()

#===============================================================================
function(dart_add_example rel_dir)
dart_add_custom_target(${rel_dir} DART_EXAMPLES ${ARGN})
endfunction()

#===============================================================================
function(dart_add_tutorial rel_dir)
dart_add_custom_target(${rel_dir} DART_TUTORIALS ${ARGN})
endfunction(dart_add_tutorial)

#===============================================================================
function(dart_format_add)
dart_property_add(DART_FORMAT_FILES ${ARGN})
endfunction()
35 changes: 18 additions & 17 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# A list of examples
set_property(DIRECTORY PROPERTY FOLDER Examples)
cmake_minimum_required(VERSION 2.8.12)

# Automatically identify all directories in the examples folder
file(GLOB children RELATIVE ${CMAKE_CURRENT_LIST_DIR} "*")
set(directories "")
foreach(child ${children})
if(IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${child}")
project(dart-examples)

file(GLOB srcs "${CMAKE_CURRENT_LIST_DIR}/${child}/*.cpp")
add_subdirectory(addDeleteSkels)
add_subdirectory(atlasSimbicon)
add_subdirectory(bipedStand)
add_subdirectory(hardcodedDesign)
add_subdirectory(hybridDynamics)
add_subdirectory(jointConstraints)
add_subdirectory(mixedChain)
add_subdirectory(operationalSpaceControl)
add_subdirectory(rigidChain)
add_subdirectory(rigidLoop)
add_subdirectory(rigidShapes)
add_subdirectory(simpleFrames)
add_subdirectory(softBodies)
add_subdirectory(speedTest)
add_subdirectory(vehicle)

if(srcs)
add_executable(${child} ${srcs})
target_link_libraries(${child} dart dart-utils-urdf dart-gui)
dart_add_example(${child})
else()
add_subdirectory(${child})
endif()
add_subdirectory(osgExamples)

endif()
endforeach()
32 changes: 9 additions & 23 deletions examples/osgExamples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# This directory depends on OpenSceneGraph
if(HAVE_OPENSCENEGRAPH)

# Automatically identify all directories in the examples folder
file(GLOB children RELATIVE ${CMAKE_CURRENT_LIST_DIR} "*")
set(directories "")
foreach(child ${children})
if(IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${child}")

file(GLOB srcs "${CMAKE_CURRENT_LIST_DIR}/${child}/*.cpp")

if(srcs)
add_executable(${child} ${srcs})
target_link_libraries(${child} dart dart-utils-urdf dart-gui-osg)
dart_add_example(${child})
else()
add_subdirectory(${child})
endif()

endif()
endforeach()

endif(HAVE_OPENSCENEGRAPH)
add_subdirectory(osgAtlasPuppet)
add_subdirectory(osgAtlasSimbicon)
add_subdirectory(osgDragAndDrop)
add_subdirectory(osgEmpty)
add_subdirectory(osgHuboPuppet)
add_subdirectory(osgImGui)
add_subdirectory(osgOperationalSpaceControl)
add_subdirectory(osgSoftBodies)
add_subdirectory(osgTinkertoy)
File renamed without changes.
1 change: 1 addition & 0 deletions tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_subdirectory(tutorialDominoes)
add_subdirectory(tutorialDominoes-Finished)
add_subdirectory(tutorialMultiPendulum)
add_subdirectory(tutorialMultiPendulum-Finished)

0 comments on commit b490cc6

Please sign in to comment.