From 5627acfdbaeb0c748a8f5dccf5b7b0d8cd3904cb Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 9 Apr 2021 15:51:20 -0700 Subject: [PATCH 1/2] Use CMake targets rather than variables for OpenGL dependencies --- cmake/DARTFindOpenGL.cmake | 7 +++- cmake/DARTFindOpenSceneGraph.cmake | 63 ++++++++++++++++++++++++++++++ dart/gui/CMakeLists.txt | 5 +-- dart/gui/osg/CMakeLists.txt | 56 ++------------------------ 4 files changed, 75 insertions(+), 56 deletions(-) create mode 100644 cmake/DARTFindOpenSceneGraph.cmake diff --git a/cmake/DARTFindOpenGL.cmake b/cmake/DARTFindOpenGL.cmake index f857dd0aec471..a5500f48a42b8 100644 --- a/cmake/DARTFindOpenGL.cmake +++ b/cmake/DARTFindOpenGL.cmake @@ -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) diff --git a/cmake/DARTFindOpenSceneGraph.cmake b/cmake/DARTFindOpenSceneGraph.cmake new file mode 100644 index 0000000000000..d6ab72defee79 --- /dev/null +++ b/cmake/DARTFindOpenSceneGraph.cmake @@ -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() diff --git a/dart/gui/CMakeLists.txt b/dart/gui/CMakeLists.txt index 423cfcbedafe9..bcae381d6abe8 100644 --- a/dart/gui/CMakeLists.txt +++ b/dart/gui/CMakeLists.txt @@ -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 ) diff --git a/dart/gui/osg/CMakeLists.txt b/dart/gui/osg/CMakeLists.txt index 3ba4efe6cb370..34d393758f52e 100644 --- a/dart/gui/osg/CMakeLists.txt +++ b/dart/gui/osg/CMakeLists.txt @@ -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 @@ -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}) From 22d4ea5e011edd29e80a04ec23ceeb45372ebafb Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 9 Apr 2021 16:19:53 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c414f3994f8..b0ec47e4676ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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_`_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