Skip to content

Commit

Permalink
Replace OpenGL dependency CMake variables with targets (#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Apr 10, 2021
1 parent 095605e commit 82028e3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
* Added CI for multiple Linux platforms: arm64 and ppc64le: [#1531](https://github.com/dartsim/dart/pull/1531)
* Fixed Aspect/Composite-relate tests on Windows/MSVC: [#1541](https://github.com/dartsim/dart/pull/1541), [#1542](https://github.com/dartsim/dart/pull/1542)
* Added `DART_SKIP_<dep>`_advanced option: [#1529](https://github.com/dartsim/dart/pull/1529)
* Replaced OpenGL dependency variables with targets: [#1552](https://github.com/dartsim/dart/pull/1552)

* Documentation

Expand Down
7 changes: 6 additions & 1 deletion cmake/DARTFindOpenGL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ if(POLICY CMP0072)
cmake_policy(SET CMP0072 OLD)
endif()

find_package(OpenGL QUIET MODULE)
# Use OpenGL config if available
find_package(OpenGL QUIET CONFIG)
# Otherwise, fall back to FindOpenGL.cmake provided by CMake
if(NOT OPENGL_FOUND)
find_package(OpenGL QUIET MODULE)
endif()

cmake_policy(POP)

Expand Down
63 changes: 63 additions & 0 deletions cmake/DARTFindOpenSceneGraph.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2011-2021, The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/master/LICENSE
#
# This file is provided under the "BSD-style" License

if (CMAKE_VERSION VERSION_LESS 3.12)
get_property(old_find_library_use_lib64_paths GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
endif()

find_package(OpenSceneGraph 3.0 QUIET
COMPONENTS osg osgViewer osgManipulator osgGA osgDB osgShadow
)

if (CMAKE_VERSION VERSION_LESS 3.12)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ${old_find_library_use_lib64_paths})
endif()

# It seems that OPENSCENEGRAPH_FOUND will inadvertently get set to true when
# OpenThreads is found, even if OpenSceneGraph is not installed. This is quite
# possibly a bug in OSG's cmake configuration file. For now, it seems that
# requiring OSG_FOUND to be true as well fixes this.
if(OPENSCENEGRAPH_FOUND AND OSG_FOUND)
if(DART_VERBOSE)
message(STATUS "Looking for OpenSceneGraph - ${OPENSCENEGRAPH_VERSION} found")
endif()
else()
# dart-gui-osg requires both OSG and OpenThreads. This section attempts to
# identify which of those are missing from the building machine and offer
# advice to the user for getting dart-gui-osg to build.
find_package(OpenThreads QUIET)
if(OPENTHREADS_FOUND)
set(warning_msg "Could NOT find OpenSceneGraph")
else()
if(OSG_LIBRARY)
set(warning_msg "Could NOT find OpenThreads")
else()
set(warning_msg "Could NOT find OpenSceneGraph nor OpenThreads")
endif()
endif()
message(STATUS "${warning_msg} -- we will skip dart-gui-osg\n"
"If you believe you do have both OSG and OpenThreads installed, try setting OSG_DIR")
return()
endif()

# Define an imported target "osg::osg" if it's not defined in the provided find
# module.
#
# This is required to make the DART module that uses OpenSceneGraph relocatable.
# For that, any DART targets (e.g., dart-gui-osg) should use "osg::osg" instead
# of OPENSCENEGRAPH_INCLUDE_DIRS and OPENSCENEGRAPH_LIBRARIES because the
# variables contain absolute paths of OpenSceneGraph that could be different in
# where the system that DART is built and where the system that consumes DART.
if((OPENSCENEGRAPH_FOUND OR OpenSceneGraph_FOUND) AND NOT TARGET osg::osg)
add_library(osg::osg INTERFACE IMPORTED)
set_target_properties(osg::osg PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENSCENEGRAPH_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${OPENSCENEGRAPH_LIBRARIES}"
)
endif()
5 changes: 2 additions & 3 deletions dart/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ get_property(dart_gui_sources GLOBAL PROPERTY DART_GUI_SOURCES)
dart_add_library(${target_name}
${hdrs} ${srcs} ${dart_gui_headers} ${dart_gui_sources}
)
target_include_directories(${target_name} PUBLIC ${GLUT_INCLUDE_DIRS})
target_link_libraries(${target_name}
PUBLIC
dart-utils
${GLUT_LIBRARIES}
OpenGL::GLU
OpenGL::GL
OpenGL::GLU
GLUT::GLUT
${PROJECT_NAME}-external-lodepng
${PROJECT_NAME}-external-imgui
)
Expand Down
56 changes: 4 additions & 52 deletions dart/gui/osg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,11 @@ endif()

# OpenSceneGraph
if(DART_BUILD_GUI_OSG)

if (CMAKE_VERSION VERSION_LESS 3.12)
get_property(old_find_library_use_lib64_paths GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
endif()

find_package(OpenSceneGraph ${min_osg_version} QUIET
COMPONENTS osg osgViewer osgManipulator osgGA osgDB osgShadow
)

if (CMAKE_VERSION VERSION_LESS 3.12)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ${old_find_library_use_lib64_paths})
endif()

# It seems that OPENSCENEGRAPH_FOUND will inadvertently get set to true when
# OpenThreads is found, even if OpenSceneGraph is not installed. This is quite
# possibly a bug in OSG's cmake configuration file. For now, it seems that
# requiring OSG_FOUND to be true as well fixes this.
if(OPENSCENEGRAPH_FOUND AND OSG_FOUND)
if(DART_VERBOSE)
message(STATUS "Looking for OpenSceneGraph - ${OPENSCENEGRAPH_VERSION} found")
endif()
else()
# dart-gui-osg requires both OSG and OpenThreads. This section attempts to
# identify which of those are missing from the building machine and offer
# advice to the user for getting dart-gui-osg to build.
find_package(OpenThreads QUIET)
if(OPENTHREADS_FOUND)
set(warning_msg "Could NOT find OpenSceneGraph")
else()
if(OSG_LIBRARY)
set(warning_msg "Could NOT find OpenThreads")
else()
set(warning_msg "Could NOT find OpenSceneGraph nor OpenThreads")
endif()
endif()
message(WARNING "${warning_msg} -- we will skip dart-gui-osg\n"
"If you believe you do have both OSG and OpenThreads installed, try setting OSG_DIR")
return()
endif()

dart_find_package(OpenSceneGraph)
dart_check_optional_package(OpenSceneGraph "dart-gui-osg" "OpenSceneGraph" "3.0")
else()

message(STATUS "Skipping OpenSceneGraph (DART_BUILD_GUI_OSG == ${DART_BUILD_GUI_OSG})")
return()

endif()

# Search all header and source files
Expand All @@ -78,20 +37,13 @@ add_subdirectory(render)

# Add target
dart_add_library(${target_name} ${hdrs} ${srcs} ${dart_gui_osg_hdrs} ${dart_gui_osg_srcs})
target_include_directories(
${target_name} SYSTEM
PUBLIC ${OPENSCENEGRAPH_INCLUDE_DIRS}
)
target_link_libraries(
${target_name}
dart-gui
${OPENSCENEGRAPH_LIBRARIES}
)
target_link_libraries(${target_name} dart-gui osg::osg)

# Component
add_component(${PROJECT_NAME} ${component_name})
add_component_targets(${PROJECT_NAME} ${component_name} ${target_name})
add_component_dependencies(${PROJECT_NAME} ${component_name} gui)
add_component_dependency_packages(${PROJECT_NAME} ${component_name} OpenSceneGraph)

# Generate header for this namespace
dart_get_filename_components(header_names "gui osg headers" ${hdrs})
Expand Down

0 comments on commit 82028e3

Please sign in to comment.