diff --git a/CMake/FindOpenGL.cmake b/CMake/FindOpenGL.cmake new file mode 100644 index 000000000..76fbc4fbf --- /dev/null +++ b/CMake/FindOpenGL.cmake @@ -0,0 +1,468 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#.rst: +# FindOpenGL +# ---------- +# +# FindModule for OpenGL and GLU. +# +# Optional COMPONENTS +# ^^^^^^^^^^^^^^^^^^^ +# +# This module respects several optional COMPONENTS: ``EGL``, ``GLX``, and +# ``OpenGL``. There are corresponding import targets for each of these flags. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the :prop_tgt:`IMPORTED` targets: +# +# ``OpenGL::GL`` +# Defined to the platform-specific OpenGL libraries if the system has OpenGL. +# ``OpenGL::OpenGL`` +# Defined to libOpenGL if the system is GLVND-based. +# ``OpenGL::GL`` +# ``OpenGL::GLU`` +# Defined if the system has GLU. +# ``OpenGL::GLX`` +# Defined if the system has GLX. +# ``OpenGL::EGL`` +# Defined if the system has EGL. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module sets the following variables: +# +# ``OPENGL_FOUND`` +# True, if the system has OpenGL and all components are found. +# ``OPENGL_XMESA_FOUND`` +# True, if the system has XMESA. +# ``OPENGL_GLU_FOUND`` +# True, if the system has GLU. +# ``OpenGL_OpenGL_FOUND`` +# True, if the system has an OpenGL library. +# ``OpenGL_GLX_FOUND`` +# True, if the system has GLX. +# ``OpenGL_EGL_FOUND`` +# True, if the system has EGL. +# ``OPENGL_INCLUDE_DIR`` +# Path to the OpenGL include directory. +# ``OPENGL_EGL_INCLUDE_DIRS`` +# Path to the EGL include directory. +# ``OPENGL_LIBRARIES`` +# Paths to the OpenGL library, windowing system libraries, and GLU libraries. +# On Linux, this assumes glX and is never correct for EGL-based targets. +# Clients are encouraged to use the ``OpenGL::*`` import targets instead. +# +# Cache variables +# ^^^^^^^^^^^^^^^ +# +# The following cache variables may also be set: +# +# ``OPENGL_egl_LIBRARY`` +# Path to the EGL library. +# ``OPENGL_glu_LIBRARY`` +# Path to the GLU library. +# ``OPENGL_glx_LIBRARY`` +# Path to the GLVND 'GLX' library. +# ``OPENGL_opengl_LIBRARY`` +# Path to the GLVND 'OpenGL' library +# ``OPENGL_gl_LIBRARY`` +# Path to the OpenGL library. New code should prefer the ``OpenGL::*`` import +# targets. +# +# Linux-specific +# ^^^^^^^^^^^^^^ +# +# Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates +# context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and +# contexts are defined in "libGLX" or "libEGL". GLVND is currently the only way +# to get OpenGL 3+ functionality via EGL in a manner portable across vendors. +# +# On Linux systems FindOpenGL defaults to using GLVND if available. Users can +# utilize GLVND explicitly with targets ``OpenGL::OpenGL``, ``OpenGL::GLX``, and +# ``OpenGL::EGL``. Additionally, when GLVND is available the ``OpenGL::GL`` +# target is equivalent to ``OpenGL::OpenGL OpenGL::GLX``. When the system is +# not GLVND-based, ``OpenGL::GL`` expands to libGL as it has historically done. +# Thus, for non-EGL-based Linux targets, the ``OpenGL::GL`` target is most +# portable. +# +# For EGL targets the client must rely on GLVND support on the user's system. +# Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets. Using GLES* +# libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this +# module does not currently support that; contributions welcome. +# +# ``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of +# GLVND. For non-GLVND Linux and other systems these are left undefined. +# +# macOS-Specific +# ^^^^^^^^^^^^^^ +# +# On OSX FindOpenGL defaults to using the framework version of OpenGL. People +# will have to change the cache values of OPENGL_glu_LIBRARY and +# OPENGL_gl_LIBRARY to use OpenGL with X11 on OSX. + +set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) + +# Provide OPENGL_USE_ variables for each component. +foreach(component ${OpenGL_FIND_COMPONENTS}) + string(TOUPPER ${component} _COMPONENT) + set(OPENGL_USE_${_COMPONENT} 1) +endforeach() + +if (CYGWIN) + find_path(OPENGL_INCLUDE_DIR GL/gl.h ) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) + + find_library(OPENGL_gl_LIBRARY opengl32 ) + find_library(OPENGL_glu_LIBRARY glu32 ) + +elseif (WIN32) + + if(BORLAND) + set (OPENGL_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32") + set (OPENGL_glu_LIBRARY import32 CACHE STRING "GLU library for win32") + else() + set (OPENGL_gl_LIBRARY opengl32 CACHE STRING "OpenGL library for win32") + set (OPENGL_glu_LIBRARY glu32 CACHE STRING "GLU library for win32") + endif() + +elseif (APPLE) + # The OpenGL.framework provides both gl and glu + find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X") + find_library(OPENGL_glu_LIBRARY OpenGL DOC + "GLU library for OS X (usually same as OpenGL library)") + find_path(OPENGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OS X") + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) + +else() + if (CMAKE_SYSTEM_NAME MATCHES "HP-UX") + # Handle HP-UX cases where we only want to find OpenGL in either hpux64 + # or hpux32 depending on if we're doing a 64 bit build. + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(_OPENGL_LIB_PATH + /opt/graphics/OpenGL/lib/hpux32/) + else() + set(_OPENGL_LIB_PATH + /opt/graphics/OpenGL/lib/hpux64/ + /opt/graphics/OpenGL/lib/pa20_64) + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL Haiku) + set(_OPENGL_LIB_PATH + /boot/develop/lib/x86) + set(_OPENGL_INCLUDE_PATH + /boot/develop/headers/os/opengl) + endif() + + # The first line below is to make sure that the proper headers + # are used on a Linux machine with the NVidia drivers installed. + # They replace Mesa with NVidia's own library but normally do not + # install headers and that causes the linking to + # fail since the compiler finds the Mesa headers but NVidia's library. + # Make sure the NVIDIA directory comes BEFORE the others. + # - Atanas Georgiev + find_path(OPENGL_INCLUDE_DIR GL/gl.h + /usr/share/doc/NVIDIA_GLX-1.0/include + /usr/openwin/share/include + /opt/graphics/OpenGL/include /usr/X11R6/include + ${_OPENGL_INCLUDE_PATH} + ) + find_path(OPENGL_GLX_INCLUDE_DIR GL/glx.h ${_OPENGL_INCLUDE_PATH}) + find_path(OPENGL_EGL_INCLUDE_DIR EGL/egl.h ${_OPENGL_INCLUDE_PATH}) + find_path(OPENGL_xmesa_INCLUDE_DIR GL/xmesa.h + /usr/share/doc/NVIDIA_GLX-1.0/include + /usr/openwin/share/include + /opt/graphics/OpenGL/include /usr/X11R6/include + ) + + find_library(OPENGL_gl_LIBRARY + NAMES GL MesaGL + PATHS /opt/graphics/OpenGL/lib + /usr/openwin/lib + /usr/shlib /usr/X11R6/lib + ${_OPENGL_LIB_PATH} + ) + # Search for the GLVND libraries. We do this regardless of COMPONENTS; we'll + # take into account the COMPONENTS logic later. + find_library(OPENGL_opengl_LIBRARY + NAMES OpenGL + PATHS /usr/X11R6/lib + ${_OPENGL_LIB_PATH} + ) + + find_library(OPENGL_glx_LIBRARY + NAMES GLX + PATHS /usr/X11R6/lib + ${_OPENGL_LIB_PATH} + ) + + find_library(OPENGL_egl_LIBRARY + NAMES EGL + PATHS ${_OPENGL_LIB_PATH} + ) + + find_library(OPENGL_glu_LIBRARY + NAMES GLU MesaGLU + PATHS ${OPENGL_gl_LIBRARY} + /opt/graphics/OpenGL/lib + /usr/openwin/lib + /usr/shlib /usr/X11R6/lib + ) + + # FPHSA cannot handle "this OR that is required", so we conditionally set what + # it must look for. First clear any previous config we might have done: + set(_OpenGL_REQUIRED_VARS) + + # now we append the libraries as appropriate. The complicated logic + # basically comes down to "use libOpenGL when we can, and add in specific + # context mechanisms when requested, or we need them to preserve the previous + # default where glx is always available." + if((NOT OPENGL_USE_EGL AND + NOT OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY) OR + ( OPENGL_USE_EGL)) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY) + endif() + + # GLVND GLX library. Preferred when available. + if((NOT OPENGL_USE_OPENGL AND + NOT OPENGL_USE_GLX AND + NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + ( OPENGL_USE_GLX AND + NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + NOT OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY) OR + (OPENGL_USE_GLX AND OPENGL_USE_EGL)) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_glx_LIBRARY) + endif() + + # GLVND EGL library. + if(OPENGL_USE_EGL) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_egl_LIBRARY) + endif() + + # Old-style "libGL" library: used as a fallback when GLVND isn't available. + if((NOT OPENGL_USE_EGL AND + NOT OPENGL_opengl_LIBRARY AND + OPENGL_glx_LIBRARY AND + OPENGL_gl_LIBRARY) OR + (NOT OPENGL_USE_EGL AND + NOT OPENGL_glx_LIBRARY AND + OPENGL_gl_LIBRARY)) + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY) + endif() + + # We always need the 'gl.h' include dir. + list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR) + + unset(_OPENGL_INCLUDE_PATH) + unset(_OPENGL_LIB_PATH) + + find_library(OPENGL_glu_LIBRARY + NAMES GLU MesaGLU + PATHS ${OPENGL_gl_LIBRARY} + /opt/graphics/OpenGL/lib + /usr/openwin/lib + /usr/shlib /usr/X11R6/lib + ) +endif () + +if(OPENGL_xmesa_INCLUDE_DIR) + set( OPENGL_XMESA_FOUND "YES" ) +else() + set( OPENGL_XMESA_FOUND "NO" ) +endif() + +if(OPENGL_glu_LIBRARY) + set( OPENGL_GLU_FOUND "YES" ) +else() + set( OPENGL_GLU_FOUND "NO" ) +endif() + +# OpenGL_OpenGL_FOUND is a bit unique in that it is okay if /either/ libOpenGL +# or libGL is found. +# Using libGL with libEGL is never okay, though; we handle that case later. +if(NOT OPENGL_opengl_LIBRARY AND NOT OPENGL_gl_LIBRARY) + set(OpenGL_OpenGL_FOUND FALSE) +else() + set(OpenGL_OpenGL_FOUND TRUE) +endif() + +if(OPENGL_glx_LIBRARY AND OPENGL_GLX_INCLUDE_DIR) + set(OpenGL_GLX_FOUND TRUE) +else() + set(OpenGL_GLX_FOUND FALSE) +endif() + +if(OPENGL_egl_LIBRARY AND OPENGL_EGL_INCLUDE_DIR) + set(OpenGL_EGL_FOUND TRUE) +else() + set(OpenGL_EGL_FOUND FALSE) +endif() + +# User-visible names should be plural. +if(OPENGL_EGL_INCLUDE_DIR) + set(OPENGL_EGL_INCLUDE_DIRS ${OPENGL_EGL_INCLUDE_DIR}) +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS} + HANDLE_COMPONENTS) +unset(_OpenGL_REQUIRED_VARS) + +# OpenGL:: targets +if(OPENGL_FOUND) + # ::OpenGL is a GLVND library, and thus Linux-only: we don't bother checking + # for a framework version of this library. + if(OPENGL_opengl_LIBRARY AND NOT TARGET OpenGL::OpenGL) + if(IS_ABSOLUTE "${OPENGL_opengl_LIBRARY}") + add_library(OpenGL::OpenGL UNKNOWN IMPORTED) + set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LOCATION + "${OPENGL_opengl_LIBRARY}") + else() + add_library(OpenGL::OpenGL INTERFACE IMPORTED) + set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LIBNAME + "${OPENGL_opengl_LIBRARY}") + endif() + set_target_properties(OpenGL::OpenGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_INCLUDE_DIR}") + endif() + + # ::GLX is a GLVND library, and thus Linux-only: we don't bother checking + # for a framework version of this library. + if(OpenGL_GLX_FOUND AND NOT TARGET OpenGL::GLX) + if(IS_ABSOLUTE "${OPENGL_glx_LIBRARY}") + add_library(OpenGL::GLX UNKNOWN IMPORTED) + set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LOCATION + "${OPENGL_glx_LIBRARY}") + else() + add_library(OpenGL::GLX INTERFACE IMPORTED) + set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LIBNAME + "${OPENGL_glx_LIBRARY}") + endif() + set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_LINK_LIBRARIES + OpenGL::OpenGL) + set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_GLX_INCLUDE_DIR}") + endif() + + if(TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX AND NOT TARGET OpenGL::GL) + # if GLVND with GLX is available, make ::GL a synonym for 'OpenGL::OpenGL + # OpenGL::GLX'. + add_library(OpenGL::GL INTERFACE IMPORTED) + set_target_properties(OpenGL::GL PROPERTIES INTERFACE_LINK_LIBRARIES + OpenGL::OpenGL) + set_property(TARGET OpenGL::GL APPEND PROPERTY INTERFACE_LINK_LIBRARIES + OpenGL::GLX) + set_target_properties(OpenGL::GL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_INCLUDE_DIR}") + + elseif(NOT TARGET OpenGL::GL) + if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}") + add_library(OpenGL::GL UNKNOWN IMPORTED) + if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$") + set(_gl_fw "${OPENGL_gl_LIBRARY}/${CMAKE_MATCH_1}") + if(EXISTS "${_gl_fw}.tbd") + string(APPEND _gl_fw ".tbd") + endif() + set_target_properties(OpenGL::GL PROPERTIES + IMPORTED_LOCATION "${_gl_fw}") + else() + set_target_properties(OpenGL::GL PROPERTIES + IMPORTED_LOCATION "${OPENGL_gl_LIBRARY}") + endif() + else() + add_library(OpenGL::GL INTERFACE IMPORTED) + set_target_properties(OpenGL::GL PROPERTIES + IMPORTED_LIBNAME "${OPENGL_gl_LIBRARY}") + endif() + set_target_properties(OpenGL::GL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}") + endif() + + # ::EGL is a GLVND library, and thus Linux-only: we don't bother checking + # for a framework version of this library. + # Note we test for OpenGL::OpenGL as a target. When this module is updated to + # support GLES, we would additionally want to check for the hypothetical GLES + # target and enable EGL if either ::GLES or ::OpenGL is created. + if(TARGET OpenGL::OpenGL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL) + if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}") + add_library(OpenGL::EGL UNKNOWN IMPORTED) + set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION + "${OPENGL_egl_LIBRARY}") + else() + add_library(OpenGL::EGL INTERFACE IMPORTED) + set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LIBNAME + "${OPENGL_egl_LIBRARY}") + endif() + set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES + OpenGL::OpenGL) + # Note that EGL's include directory is different from OpenGL/GLX's! + set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${OPENGL_EGL_INCLUDE_DIR}") + endif() + + if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU) + if(IS_ABSOLUTE "${OPENGL_glu_LIBRARY}") + add_library(OpenGL::GLU UNKNOWN IMPORTED) + if(OPENGL_glu_LIBRARY MATCHES "/([^/]+)\\.framework$") + set(_glu_fw "${OPENGL_glu_LIBRARY}/${CMAKE_MATCH_1}") + if(EXISTS "${_glu_fw}.tbd") + string(APPEND _glu_fw ".tbd") + endif() + set_target_properties(OpenGL::GLU PROPERTIES + IMPORTED_LOCATION "${_glu_fw}") + else() + set_target_properties(OpenGL::GLU PROPERTIES + IMPORTED_LOCATION "${OPENGL_glu_LIBRARY}") + endif() + else() + add_library(OpenGL::GLU INTERFACE IMPORTED) + set_target_properties(OpenGL::GLU PROPERTIES + IMPORTED_LIBNAME "${OPENGL_glu_LIBRARY}") + endif() + set_target_properties(OpenGL::GLU PROPERTIES + INTERFACE_LINK_LIBRARIES OpenGL::GL) + endif() + + # OPENGL_LIBRARIES mirrors OpenGL::GL's logic ... + set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY}) + if(TARGET OpenGL::GLX AND TARGET OpenGL::OpenGL) + set(OPENGL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY}) + endif() + # ... and also includes GLU, if available. + if(TARGET OpenGL::GLU) + list(APPEND OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY}) + endif() +endif() + +# This deprecated setting is for backward compatibility with CMake1.4 +set(OPENGL_LIBRARY ${OPENGL_LIBRARIES}) +# This deprecated setting is for backward compatibility with CMake1.4 +set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR}) + +mark_as_advanced( + OPENGL_INCLUDE_DIR + OPENGL_xmesa_INCLUDE_DIR + OPENGL_egl_LIBRARY + OPENGL_glu_LIBRARY + OPENGL_glx_LIBRARY + OPENGL_gl_LIBRARY + OPENGL_opengl_LIBRARY + OPENGL_EGL_INCLUDE_DIR + OPENGL_GLX_INCLUDE_DIR +) diff --git a/CMake/VTKmConfig.cmake.in b/CMake/VTKmConfig.cmake.in index c10c57805..5f7884969 100755 --- a/CMake/VTKmConfig.cmake.in +++ b/CMake/VTKmConfig.cmake.in @@ -23,6 +23,8 @@ # # vtkm Target that should be used to link to VTK-m # +# vtkm_rendering Target that contains all the rendering code +# # vtkm::tbb Target that contains tbb related link information # implicitly linked to by `vtkm` if tbb is enabled # @@ -58,6 +60,8 @@ endif() set(VTKm_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@") set(VTKm_ENABLE_CUDA "@VTKm_ENABLE_CUDA@") set(VTKm_ENABLE_TBB "@VTKm_ENABLE_TBB@") +set(VTKm_ENABLE_RENDERING "@VTKm_ENABLE_RENDERING@") +set(VTKm_RENDERING_BACKEND "@VTKm_RENDERING_BACKEND@") # Load the library exports, but only if not compiling VTK-m itself set_and_check(VTKm_CONFIG_DIR "@PACKAGE_VTKm_INSTALL_CONFIG_DIR@") @@ -73,4 +77,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${VTKm_CMAKE_MODULE_PATH}) # This includes a host of functions used by VTK-m CMake. include(VTKmWrappers) +if(VTKm_ENABLE_RENDERING) + include(VTKmRenderingBackends) +endif() + check_required_components(vtkm) diff --git a/CMake/VTKmRenderingBackends.cmake b/CMake/VTKmRenderingBackends.cmake new file mode 100644 index 000000000..c73bda94b --- /dev/null +++ b/CMake/VTKmRenderingBackends.cmake @@ -0,0 +1,114 @@ +##============================================================================ +## Copyright (c) Kitware, Inc. +## All rights reserved. +## See LICENSE.txt for details. +## This software is distributed WITHOUT ANY WARRANTY; without even +## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +## PURPOSE. See the above copyright notice for more information. +## +## Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). +## Copyright 2014 UT-Battelle, LLC. +## Copyright 2014 Los Alamos National Security. +## +## Under the terms of Contract DE-NA0003525 with NTESS, +## the U.S. Government retains certain rights in this software. +## +## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National +## Laboratory (LANL), the U.S. Government retains certain rights in +## this software. +##============================================================================ + +#----------------------------------------------------------------------------- +# find OpenGL and supporting libraries provided to make using VTK-m easier +# for consumers. +# +# vtkm_find_gl( +# REQUIRED [GL|GLUT|GLEW] +# OPTIONAL [GL|GLUT|GLEW] +# QUIET [ON/OFF] +# ) +# +# Imports everything as imported modules with the following names: +# - GLUT::GLUT +# - GLEW::GLEW +# - OpenGL::GL +# For OpenGL Will also provide the more explicit targets of: +# - OpenGL::OpenGL +# - OpenGL::GLX +# - OpenGL::EGL +function(vtkm_find_gl) + set(oneValueArgs QUIET) + set(multiValueArgs REQUIRED OPTIONAL) + cmake_parse_arguments(find_gl + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + + set(QUIETLY ) + if(find_gl_QUIET) + set(QUIETLY "QUIET") + endif() + + foreach(item ${find_gl_REQUIRED}) + set(${item}_REQUIRED "REQUIRED") + set(DO_${item}_FIND TRUE) + endforeach() + + foreach(item ${find_gl_OPTIONAL}) + set(DO_${item}_FIND TRUE) + endforeach() + + #Find GL + if(CMAKE_VERSION VERSION_LESS 3.10) + if(DO_GL_FIND AND NOT TARGET OpenGL::GL) + find_package(OpenGL ${GL_REQUIRED} ${QUIETLY} MODULE) + endif() + else() + #clunky but we need to make sure we use the upstream module if it exists + set(orig_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) + set(CMAKE_MODULE_PATH "") + if(DO_GL_FIND AND NOT TARGET OpenGL::GL) + find_package(OpenGL ${GL_REQUIRED} ${QUIETLY} MODULE) + endif() + set(CMAKE_MODULE_PATH ${orig_CMAKE_MODULE_PATH}) + endif() + + #Find GLEW + if(DO_GLEW_FIND AND NOT TARGET GLEW::GLEW) + find_package(GLEW ${GLEW_REQUIRED} ${QUIETLY}) + endif() + + if(DO_GLUT_FIND AND NOT TARGET GLUT::GLUT) + find_package(GLUT ${GLUT_REQUIRED} ${QUIETLY}) + endif() + +endfunction() + +#----------------------------------------------------------------------------- +if(TARGET vtkm_rendering_backend) + return() +endif() + +add_library(vtkm_rendering_backend INTERFACE) +if(NOT VTKm_RENDERING_BACKEND STREQUAL "None") + vtkm_find_gl(REQUIRED GL GLEW + OPTIONAL + QUIET) +endif() + +#----------------------------------------------------------------------------- +if(VTKm_RENDERING_BACKEND STREQUAL "OpenGL") + if(TARGET OpenGL::GLX) + target_link_libraries(vtkm_rendering_backend + INTERFACE OpenGL::OpenGL OpenGL::GLX GLEW::GLEW) + elseif(TARGET OpenGL::GL) + target_link_libraries(vtkm_rendering_backend + INTERFACE OpenGL::GL GLEW::GLEW) + endif() +elseif(VTKm_RENDERING_BACKEND STREQUAL "OSMesa") + target_link_libraries(vtkm_rendering_backend + INTERFACE OpenGL::GL GLEW::GLEW) +elseif(VTKm_RENDERING_BACKEND STREQUAL "EGL") + target_link_libraries(vtkm_rendering_backend + INTERFACE OpenGL::OpenGL OpenGL::EGL GLEW::GLEW) +endif() diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index ae1d2ffc3..6281042c2 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -117,8 +117,6 @@ function(vtkm_install_template_sources) vtkm_install_headers("${dir_prefix}" ${hfiles}) endfunction(vtkm_install_template_sources) - - #----------------------------------------------------------------------------- # Add a VTK-m library. The name of the library will match the "kit" name # (e.g. vtkm_rendering) unless the NAME argument is given. @@ -231,7 +229,7 @@ function(vtkm_unit_tests) RUNTIME_OUTPUT_DIRECTORY ${VTKm_EXECUTABLE_OUTPUT_PATH} ) - target_link_libraries(${test_prog} PRIVATE vtkm) + target_link_libraries(${test_prog} PRIVATE vtkm ${VTKm_UT_LIBRARIES}) if(NOT VTKm_UT_NO_TESTS) return() diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c2144f55..4e888c785 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,6 @@ option(VTKm_ENABLE_TBB "Enable TBB support" OFF) option(VTKm_ENABLE_RENDERING "Enable rendering library" ON) option(VTKm_ENABLE_TESTING "Enable VTKm Testing" ON) option(VTKm_ENABLE_BENCHMARKS "Enable VTKm Benchmarking" OFF) -option(VTKm_ENABLE_OSMESA "Enable creating the OSMesa canvas" OFF) option(VTKm_ENABLE_DOCUMENTATION "Build Doxygen documentation" OFF) option(VTKm_ENABLE_EXAMPLES "Build examples" OFF) @@ -222,6 +221,7 @@ install(FILES ${VTKm_SOURCE_DIR}/LICENSE.txt install( FILES ${VTKm_SOURCE_DIR}/CMake/FindTBB.cmake + ${VTKm_SOURCE_DIR}/CMake/FindOpenGL.cmake DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR} ) @@ -230,6 +230,7 @@ install( FILES ${VTKm_SOURCE_DIR}/CMake/VTKmWrappers.cmake ${VTKm_SOURCE_DIR}/CMake/VTKmBackends.cmake + ${VTKm_SOURCE_DIR}/CMake/VTKmRenderingBackends.cmake ${VTKm_SOURCE_DIR}/CMake/VTKmExportHeaderTemplate.h.in DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR} ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 633f32c6d..560906e9f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,20 +23,17 @@ #path so that our examples can find VTK-m set(CMAKE_PREFIX_PATH ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR}) -# add_subdirectory(clipping) +add_subdirectory(clipping) # add_subdirectory(contour_tree) # add_subdirectory(cosmotools) -# add_subdirectory(demo) +add_subdirectory(demo) # add_subdirectory(dynamic_dispatcher) -# add_subdirectory(game_of_life) -# add_subdirectory(hello_world) +add_subdirectory(game_of_life) +add_subdirectory(hello_world) # add_subdirectory(isosurface) add_subdirectory(multi_backend) # add_subdirectory(streamline) # add_subdirectory(tetrahedra) # add_subdirectory(particle_advection) -# if(VTKm_ENABLE_RENDERING) -# add_subdirectory(rendering) -# endif() +add_subdirectory(rendering) # add_subdirectory(unified_memory) - diff --git a/examples/clipping/CMakeLists.txt b/examples/clipping/CMakeLists.txt index 3d8d17173..9100e86ee 100644 --- a/examples/clipping/CMakeLists.txt +++ b/examples/clipping/CMakeLists.txt @@ -19,45 +19,33 @@ ## this software. ## ##============================================================================= +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) +project(Clipping CXX) + #Find the VTK-m package -find_package(VTKm REQUIRED QUIET - OPTIONAL_COMPONENTS Serial CUDA TBB - ) +find_package(VTKm REQUIRED QUIET) + add_executable(Clipping_SERIAL Clipping.cxx) -target_include_directories(Clipping_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS}) -target_link_libraries(Clipping_SERIAL PRIVATE ${VTKm_LIBRARIES}) -target_compile_options(Clipping_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS}) target_compile_definitions(Clipping_SERIAL PRIVATE "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_SERIAL") +target_link_libraries(Clipping_SERIAL PRIVATE vtkm) -if(VTKm_CUDA_FOUND) + +if(TARGET vtkm::tbb) + add_executable(Clipping_TBB Clipping.cxx) + target_compile_definitions(Clipping_TBB PRIVATE + "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB") + target_link_libraries(Clipping_TBB PRIVATE vtkm) +endif() + +if(TARGET vtkm::cuda) set (cudaSource "${CMAKE_CURRENT_BINARY_DIR}/Clipping.cu") configure_file(Clipping.cxx ${cudaSource} COPYONLY) - set(old_nvcc_flags ${CUDA_NVCC_FLAGS}) - set(old_cxx_flags ${CMAKE_CXX_FLAGS}) - vtkm_setup_nvcc_flags( old_nvcc_flags old_cxx_flags) - - - # Cuda compiles do not respect target_include_directories - cuda_include_directories(${VTKm_INCLUDE_DIRS}) - - cuda_add_executable(Clipping_CUDA ${cudaSource}) - target_include_directories(Clipping_CUDA PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(Clipping_CUDA PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(Clipping_CUDA PRIVATE ${VTKm_COMPILE_OPTIONS}) - - set(CUDA_NVCC_FLAGS ${old_nvcc_flags}) - set(CMAKE_CXX_FLAGS ${old_cxx_flags}) + add_executable(Clipping_CUDA ${cudaSource}) -endif() - -if(VTKm_TBB_FOUND) - add_executable(Clipping_TBB Clipping.cxx) - target_include_directories(Clipping_TBB PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(Clipping_TBB PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(Clipping_TBB PRIVATE PRIVATE ${VTKm_COMPILE_OPTIONS}) - target_compile_definitions(Clipping_TBB PRIVATE - "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB") + target_compile_definitions(Clipping_CUDA PRIVATE + "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA") + target_link_libraries(Clipping_CUDA PRIVATE vtkm) endif() diff --git a/examples/demo/CMakeLists.txt b/examples/demo/CMakeLists.txt index c2d745c1b..9062f0e44 100644 --- a/examples/demo/CMakeLists.txt +++ b/examples/demo/CMakeLists.txt @@ -19,33 +19,23 @@ ## this software. ## ##============================================================================= +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) +project(VTKmDemo CXX) #Find the VTK-m package -find_package(VTKm QUIET REQUIRED - OPTIONAL_COMPONENTS Serial CUDA TBB OSMesa Rendering - ) +find_package(VTKm REQUIRED QUIET) +if(TARGET vtkm_rendering) -if(VTKm_OSMesa_FOUND AND VTKm_Rendering_FOUND) - if(VTKm_CUDA_FOUND) - # Cuda compiles do not respect target_include_directories - cuda_include_directories(${VTKm_INCLUDE_DIRS}) - cuda_add_executable(Demo Demo.cu) - else() - add_executable(Demo Demo.cxx) - endif() + add_executable(Demo Demo.cxx) + target_link_libraries(Demo PRIVATE vtkm_rendering) - - #need to setup the default device adapter. - target_include_directories(Demo PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(Demo PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(Demo PRIVATE ${VTKm_COMPILE_OPTIONS}) - - #when we are using TBB pass in the default device adapter as - #a compile definition to make sure we build with TBB selected - if(VTKm_TBB_FOUND) + if(TARGET vtkm::cuda) + set_source_files_properties(Demo.cxx LANGUAGE "CUDA") + target_compile_definitions(Demo + PRIVATE "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_CUDA") + elseif(TARGET vtkm::tbb) target_compile_definitions(Demo PRIVATE "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB") endif() - endif() diff --git a/examples/demo/Demo.cxx b/examples/demo/Demo.cxx index 60ad0b8d5..33df1b15d 100644 --- a/examples/demo/Demo.cxx +++ b/examples/demo/Demo.cxx @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) vtkm::rendering::Camera camera = vtkm::rendering::Camera(); //Set3DView - vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG()); + vtkm::Bounds coordsBounds = coords.GetBounds(); camera.ResetToBounds(coordsBounds); diff --git a/examples/game_of_life/CMakeLists.txt b/examples/game_of_life/CMakeLists.txt index 7b67e0e5c..9523cf8fc 100644 --- a/examples/game_of_life/CMakeLists.txt +++ b/examples/game_of_life/CMakeLists.txt @@ -19,22 +19,22 @@ ## this software. ## ##============================================================================= - -cmake_minimum_required(VERSION 3.8 FATAL_ERROR) +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) project(GameOfLife CXX) #Find the VTK-m package -find_package(VTKm REQUIRED - OPTIONAL_COMPONENTS Serial CUDA TBB OpenGL GLUT - ) +find_package(VTKm REQUIRED QUIET) +vtkm_find_gl(OPTIONAL GL GLUT GLEW) + +if(TARGET OpenGL::GL AND + TARGET GLUT::GLUT AND + TARGET GLEW::GLEW) + + if(TARGET vtkm::cuda) + set_source_files_properties(GameOfLife.cxx LANGUAGE "CUDA") + endif() -if(VTKm_CUDA_FOUND) - cuda_add_executable(GameOfLife GameOfLife.cu LoadShaders.h) -else() add_executable(GameOfLife GameOfLife.cxx LoadShaders.h) + target_link_libraries(GameOfLife PRIVATE vtkm OpenGL::GL GLEW::GLEW GLUT::GLUT) + endif() - - -target_include_directories(GameOfLife PRIVATE ${VTKm_INCLUDE_DIRS}) -target_link_libraries(GameOfLife PRIVATE ${VTKm_LIBRARIES}) -target_compile_options(GameOfLife PRIVATE ${VTKm_COMPILE_OPTIONS}) diff --git a/examples/game_of_life/GameOfLife.cxx b/examples/game_of_life/GameOfLife.cxx index 74d8a4d08..304ceb6d5 100644 --- a/examples/game_of_life/GameOfLife.cxx +++ b/examples/game_of_life/GameOfLife.cxx @@ -17,6 +17,8 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ +// Must be included before any other GL includes: +#include // Must be included before any other GL includes: #include diff --git a/examples/hello_world/CMakeLists.txt b/examples/hello_world/CMakeLists.txt index 7b06e6fd2..987d08b9c 100755 --- a/examples/hello_world/CMakeLists.txt +++ b/examples/hello_world/CMakeLists.txt @@ -19,35 +19,30 @@ ## this software. ## ##============================================================================= +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) +project(HelloWorld CXX) #Find the VTK-m package -find_package(VTKm REQUIRED QUIET - OPTIONAL_COMPONENTS Serial CUDA TBB OpenGL GLUT - ) +find_package(VTKm REQUIRED QUIET) +vtkm_find_gl(OPTIONAL GL GLUT GLEW) + +if(TARGET OpenGL::GL AND + TARGET GLUT::GLUT AND + TARGET GLEW::GLEW) -if(VTKm_OpenGL_FOUND AND VTKm_GLUT_FOUND) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_executable(HelloWorld_SERIAL HelloWorld.cxx LoadShaders.h) - set_source_files_properties(LoadShaders.h PROPERTIES HEADER_FILE_ONLY TRUE) - target_include_directories(HelloWorld_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(HelloWorld_SERIAL PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(HelloWorld_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS}) + target_link_libraries(HelloWorld_SERIAL + PRIVATE vtkm OpenGL::GL GLEW::GLEW GLUT::GLUT) - if(VTKm_CUDA_FOUND) - # Cuda compiles do not respect target_include_directories - cuda_include_directories(${VTKm_INCLUDE_DIRS}) - - cuda_add_executable(HelloWorld_CUDA HelloWorld.cu LoadShaders.h) - target_include_directories(HelloWorld_CUDA PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(HelloWorld_CUDA PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(HelloWorld_CUDA PRIVATE ${VTKm_COMPILE_OPTIONS}) - endif() - - if(VTKm_TBB_FOUND) + if(TARGET vtkm::tbb) add_executable(HelloWorld_TBB HelloWorldTBB.cxx LoadShaders.h) - target_include_directories(HelloWorld_TBB PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(HelloWorld_TBB PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(HelloWorld_TBB PRIVATE ${VTKm_COMPILE_OPTIONS}) + target_link_libraries(HelloWorld_TBB + PRIVATE vtkm OpenGL::GL GLEW::GLEW GLUT::GLUT) endif() + if(TARGET vtkm::cuda) + add_executable(HelloWorld_CUDA HelloWorld.cu LoadShaders.h) + target_link_libraries(HelloWorld_CUDA + PRIVATE vtkm OpenGL::GL GLEW::GLEW GLUT::GLUT) + endif() endif() diff --git a/examples/multi_backend/CMakeLists.txt b/examples/multi_backend/CMakeLists.txt index 1688346f6..ac827a970 100644 --- a/examples/multi_backend/CMakeLists.txt +++ b/examples/multi_backend/CMakeLists.txt @@ -19,6 +19,8 @@ ## this software. ## ##============================================================================= +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) +project(MultiBackend CXX) #Find the VTK-m package find_package(VTKm REQUIRED QUIET) diff --git a/examples/rendering/CMakeLists.txt b/examples/rendering/CMakeLists.txt index 76b16eb61..8a7edd15b 100644 --- a/examples/rendering/CMakeLists.txt +++ b/examples/rendering/CMakeLists.txt @@ -19,15 +19,27 @@ ## this software. ## ##============================================================================= +cmake_minimum_required(VERSION 3.3 FATAL_ERROR) +project(Rendering CXX) #Find the VTK-m package -find_package(VTKm REQUIRED QUIET - OPTIONAL_COMPONENTS Serial OpenGL Rendering GLUT - ) +find_package(VTKm REQUIRED QUIET) -if(VTKm_OpenGL_FOUND AND VTKm_Rendering_FOUND AND VTKm_GLUT_FOUND) - add_executable(Rendering_SERIAL Rendering.cxx) - target_include_directories(Rendering_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS}) - target_link_libraries(Rendering_SERIAL PRIVATE ${VTKm_LIBRARIES}) - target_compile_options(Rendering_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS}) +if(NOT TARGET vtkm_rendering OR NOT VTKm_RENDERING_BACKEND STREQUAL "OpenGL") + return() +endif() + +vtkm_find_gl(OPTIONAL GLUT) +if(NOT TARGET GLUT::GLUT) + return() +endif() + +add_executable(Rendering_SERIAL Rendering.cxx) +target_link_libraries(Rendering_SERIAL PRIVATE vtkm_rendering GLUT::GLUT) + +if(TARGET vtkm::tbb) + add_executable(Rendering_TBB Rendering.cxx) + target_compile_definitions(Rendering_TBB PRIVATE + "VTKM_DEVICE_ADAPTER=VTKM_DEVICE_ADAPTER_TBB") + target_link_libraries(Rendering_TBB PRIVATE vtkm_rendering GLUT::GLUT) endif() diff --git a/vtkm/CMakeLists.txt b/vtkm/CMakeLists.txt index 79b3eac75..b41d99efc 100644 --- a/vtkm/CMakeLists.txt +++ b/vtkm/CMakeLists.txt @@ -82,11 +82,9 @@ add_subdirectory(filter) #----------------------------------------------------------------------------- # Build rendering -# if(VTKm_ENABLE_RENDERING) -# add_subdirectory(rendering) -# endif() +add_subdirectory(rendering) -# add_subdirectory(interop) +add_subdirectory(interop) #----------------------------------------------------------------------------- #add the benchmarking folder diff --git a/vtkm/interop/CMakeLists.txt b/vtkm/interop/CMakeLists.txt index 0cdc9fe8d..646c06d61 100755 --- a/vtkm/interop/CMakeLists.txt +++ b/vtkm/interop/CMakeLists.txt @@ -23,9 +23,11 @@ set(headers TransferToOpenGL.h ) -if(VTKm_ENABLE_TESTING) - # Determine if we actually want to compile OpenGL Interop tests. - vtkm_configure_component_OpenGL() +#----------------------------------------------------------------------------- +vtkm_declare_headers(${headers} TESTABLE FALSE) + +if(VTKm_ENABLE_TESTING AND TARGET vtkm_rendering) + add_subdirectory(testing) endif() #----------------------------------------------------------------------------- @@ -34,11 +36,3 @@ add_subdirectory(internal) if(VTKm_CUDA_FOUND) add_subdirectory(cuda) endif() - -#----------------------------------------------------------------------------- -vtkm_declare_headers(${headers} TESTABLE FALSE) - -#----------------------------------------------------------------------------- -if(VTKm_OpenGL_FOUND) - add_subdirectory(testing) -endif() diff --git a/vtkm/interop/internal/CMakeLists.txt b/vtkm/interop/internal/CMakeLists.txt index 65165e78d..b3544a8b3 100644 --- a/vtkm/interop/internal/CMakeLists.txt +++ b/vtkm/interop/internal/CMakeLists.txt @@ -28,6 +28,6 @@ set(headers vtkm_declare_headers(${headers} TESTABLE FALSE) #----------------------------------------------------------------------------- -if(VTKm_OpenGL_FOUND) +if(TARGET vtkm_rendering) add_subdirectory(testing) endif() diff --git a/vtkm/interop/internal/testing/CMakeLists.txt b/vtkm/interop/internal/testing/CMakeLists.txt index afa24d4ff..a939be1bc 100644 --- a/vtkm/interop/internal/testing/CMakeLists.txt +++ b/vtkm/interop/internal/testing/CMakeLists.txt @@ -18,9 +18,13 @@ ## this software. ##============================================================================ +if(NOT TARGET GLEW::GLEW) + return() +endif() + set(unit_tests - UnitTestBufferTypePicker.cxx - UnitTestOpenGLHeaders.cxx + UnitTestOpenGLHeaders.cxx + UnitTestBufferTypePicker.cxx ) -vtkm_unit_tests(SOURCES ${unit_tests}) +vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES GLEW::GLEW) diff --git a/vtkm/interop/testing/CMakeLists.txt b/vtkm/interop/testing/CMakeLists.txt index fd1c6ad75..73055ce4b 100644 --- a/vtkm/interop/testing/CMakeLists.txt +++ b/vtkm/interop/testing/CMakeLists.txt @@ -22,40 +22,35 @@ set(headers TestingOpenGLInterop.h TestingTransferFancyHandles.h ) +vtkm_declare_headers(${headers} TESTABLE FALSE) -set(unit_tests) -# So because we are using GLEW to do our -# GL binding we can only expect one -# of these transfer tests to work -# -# -set(needs_rendering FALSE) -if(VTKm_OSMesa_FOUND AND TARGET vtkm_rendering) +if(NOT TARGET GLUT::GLUT) + find_package(GLUT QUIET) + + if(NOT TARGET GLUT::GLUT) + return() + endif() +endif() + +# rendering can only have a single backend so we need to +if(VTKm_RENDERING_BACKEND STREQUAL "OSMesa" AND TARGET vtkm_rendering) list(APPEND unit_tests UnitTestTransferOSMesa.cxx UnitTestFancyTransferOSMesa.cxx ) - set(needs_rendering TRUE) -elseif(VTKm_EGL_FOUND AND TARGET vtkm_rendering) +elseif(VTKm_RENDERING_BACKEND STREQUAL "EGL" AND TARGET vtkm_rendering) list(APPEND unit_tests UnitTestTransferEGL.cxx UnitTestFancyTransferEGL.cxx ) - set(needs_rendering TRUE) -else() - vtkm_configure_component_GLUT() - if(VTKm_GLUT_FOUND) - list(APPEND unit_tests - UnitTestTransferGLUT.cxx - UnitTestFancyTransferGLUT.cxx - ) - endif() +elseif(VTKm_RENDERING_BACKEND STREQUAL "OpenGL" AND TARGET vtkm_rendering) + list(APPEND unit_tests + UnitTestTransferGLUT.cxx + UnitTestFancyTransferGLUT.cxx + ) endif() - -vtkm_declare_headers(${headers} TESTABLE FALSE) -vtkm_unit_tests(SOURCES ${unit_tests}) -if(needs_rendering) - target_link_libraries(UnitTests_vtkm_interop_testing PRIVATE vtkm_rendering) +if(unit_tests) + vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering GLUT::GLUT) endif() diff --git a/vtkm/rendering/CMakeLists.txt b/vtkm/rendering/CMakeLists.txt index ec584a55e..621fd6b54 100644 --- a/vtkm/rendering/CMakeLists.txt +++ b/vtkm/rendering/CMakeLists.txt @@ -18,6 +18,24 @@ ## this software. ##============================================================================ +if(NOT VTKm_ENABLE_RENDERING) + return() +endif() +# determine what backend for rendering we want to build + +set(default_backend "OpenGL") +if(NOT VTKm_RENDERING_BACKEND) + message(STATUS "Setting rendering backend to '${default_backend}' as none was specified.") + set(VTKm_RENDERING_BACKEND "${default_backend}" CACHE + STRING "Choose the backend for vtkm rendering." FORCE) + # Set the possible values of rendering backend types for cmake-gui + set(extra_backends ) + if(UNIX AND NOT APPLE) + list(APPEND extra_backends "OSMesa" "EGL") + endif() + set_property(CACHE VTKm_RENDERING_BACKEND PROPERTY STRINGS "None" "OpenGL" ${extra_backends}) +endif() + set(headers Actor.h AxisAnnotation.h @@ -100,6 +118,8 @@ set(sources raytracing/VolumeRendererStructured.cxx ) +# Note that EGL and OSMesa Canvas depend on the GL version being built. Only +# the None backend supports not building the opengl version set(opengl_headers CanvasGL.h MapperGL.h @@ -148,64 +168,39 @@ set(device_sources ) #----------------------------------------------------------------------------- -vtkm_configure_component_OpenGL() -if(VTKm_OpenGL_FOUND) - list(APPEND headers ${opengl_headers}) - list(APPEND sources ${opengl_sources}) - - vtkm_configure_component_OSMesa() - if(VTKm_OSMesa_FOUND) - list(APPEND headers ${osmesa_headers}) - list(APPEND sources ${osmesa_sources}) - endif() - -# vtkm_configure_component_EGL() -# if(VTKm_EGL_FOUND) -# list(APPEND headers ${egl_headers}) -# list(APPEND sources ${egl_sources}) -# endif() -endif() - -if(VTKm_ENABLE_OSMESA AND NOT VTKm_OSMesa_FOUND) - message(SEND_ERROR "OSMesa was requested by not properly configured. -Either make sure the OSMesa headers and library are properly found or set -VTKm_ENABLE_OSMESA to OFF.") -endif() - -vtkm_declare_headers(${headers}) - vtkm_library( + NAME vtkm_rendering SOURCES ${sources} + HEADERS ${headers} WRAP_FOR_CUDA ${device_sources} ) -# EGL Libs are added here to ensure propper linking when statically compiling. -# This is safe to do even when not using EGL as the values will then be empty. -target_link_libraries(vtkm_rendering - PUBLIC vtkm_cont - PRIVATE ${VTKm_OPENGL_LIBRARIES} - ${VTKm_BACKEND_LIBRARIES} - ${EGL_LIBRARIES} - ) +if(VTKm_RENDERING_BACKEND STREQUAL "OpenGL") + vtkm_declare_headers(${opengl_headers}) + target_sources(vtkm_rendering PRIVATE ${opengl_sources}) +elseif(VTKm_RENDERING_BACKEND STREQUAL "OSMesa") + vtkm_declare_headers(${opengl_headers} ${osmesa_headers}) + target_sources(vtkm_rendering PRIVATE ${opengl_sources} ${osmesa_sources}) +elseif(VTKm_RENDERING_BACKEND STREQUAL "EGL") + vtkm_declare_headers(${opengl_headers} ${egl_headers}) + target_sources(vtkm_rendering PRIVATE ${opengl_sources} ${egl_sources}) +endif() -# EGL Dirs are added here to ensure propper linking when statically compiling. -# This is safe to do even when not using EGL as the values will then be empty. -target_include_directories(vtkm_rendering - PRIVATE ${VTKm_OPENGL_INCLUDE_DIRS} - ${VTKm_BACKEND_INCLUDE_DIRS} - ${EGL_INCLUDE_DIRS} - ) +#----------------------------------------------------------------------------- +target_link_libraries(vtkm_rendering PUBLIC vtkm) if(UNIX AND NOT APPLE) target_link_libraries(vtkm_rendering PRIVATE rt ) endif() - -# Subclasses need rendering library -vtkm_configure_component_Rendering() - -add_subdirectory(internal) -add_subdirectory(raytracing) +#----------------------------------------------------------------------------- +include(VTKmRenderingBackends) +target_link_libraries(vtkm_rendering PUBLIC vtkm_rendering_backend) + install(TARGETS vtkm_rendering_backend + EXPORT ${VTKm_EXPORT_NAME} + ) #----------------------------------------------------------------------------- +add_subdirectory(internal) +add_subdirectory(raytracing) add_subdirectory(testing) diff --git a/vtkm/rendering/internal/CMakeLists.txt b/vtkm/rendering/internal/CMakeLists.txt index 7ce7f1355..f87fcc27d 100644 --- a/vtkm/rendering/internal/CMakeLists.txt +++ b/vtkm/rendering/internal/CMakeLists.txt @@ -19,15 +19,11 @@ ##============================================================================ set(headers + OpenGLHeaders.h RunTriangulator.h ) -set(opengl_headers - OpenGLHeaders.h - ) - -if(VTKm_OpenGL_FOUND) - list(APPEND headers ${opengl_headers}) -endif() +set_source_files_properties(OpenGLHeaders.h + PROPERTIES VTKm_CANT_BE_HEADER_TESTED TRUE) vtkm_declare_headers(${headers}) diff --git a/vtkm/rendering/testing/CMakeLists.txt b/vtkm/rendering/testing/CMakeLists.txt index 7bf33fe0f..9a405c987 100644 --- a/vtkm/rendering/testing/CMakeLists.txt +++ b/vtkm/rendering/testing/CMakeLists.txt @@ -33,9 +33,15 @@ set(unit_tests UnitTestMapperVolume.cxx ) -VTKm_unit_tests(SOURCES ${unit_tests}) - -#add_subdirectory(osmesa) -#add_subdirectory(egl) -#add_subdirectory(glfw) +vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering) +if(VTKm_RENDERING_BACKEND STREQUAL "OpenGL") + # message(STATUS "rendering testing/glfw needs a FindGLFW") + # message(STATUS "rendering testing/glut needs compile corrections") + # add_subdirectory(glfw) + # add_subdirectory(glut) +elseif(VTKm_RENDERING_BACKEND STREQUAL "OSMesa") + add_subdirectory(osmesa) +elseif(VTKm_RENDERING_BACKEND STREQUAL "EGL") + add_subdirectory(egl) +endif() diff --git a/vtkm/rendering/testing/egl/CMakeLists.txt b/vtkm/rendering/testing/egl/CMakeLists.txt index 7be6d2dc4..6e143e296 100644 --- a/vtkm/rendering/testing/egl/CMakeLists.txt +++ b/vtkm/rendering/testing/egl/CMakeLists.txt @@ -18,11 +18,7 @@ ## this software. ##============================================================================ -vtkm_configure_component_EGL() -if (VTKm_EGL_FOUND) - set(unit_tests - UnitTestMapperEGL.cxx - ) - VTKm_unit_tests(SOURCES ${unit_tests}) -endif() - +set(unit_tests + UnitTestMapperEGL.cxx + ) +vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering) diff --git a/vtkm/rendering/testing/glfw/CMakeLists.txt b/vtkm/rendering/testing/glfw/CMakeLists.txt index f6214ebda..8a9582051 100644 --- a/vtkm/rendering/testing/glfw/CMakeLists.txt +++ b/vtkm/rendering/testing/glfw/CMakeLists.txt @@ -17,15 +17,15 @@ ## Laboratory (LANL), the U.S. Government retains certain rights in ## this software. ##============================================================================ - -vtkm_configure_component_GLFW() -if (VTKm_GLFW_FOUND) - set(unit_tests - UnitTestMapperGLFW.cxx - ) - VTKm_unit_tests( - SOURCES ${unit_tests} - TEST_ARGS -B - ) +find_package(GLFW QUIET) +if(NOT TARGET GLFW::GLFW) + return() endif() +set(unit_tests + UnitTestMapperGLFW.cxx + ) +vtkm_unit_tests(SOURCES ${unit_tests} + TEST_ARGS -B + LIBRARIES vtkm_rendering GLFW::GLFW) + diff --git a/vtkm/rendering/testing/glut/CMakeLists.txt b/vtkm/rendering/testing/glut/CMakeLists.txt index 85ef8ce5b..45b888e4a 100644 --- a/vtkm/rendering/testing/glut/CMakeLists.txt +++ b/vtkm/rendering/testing/glut/CMakeLists.txt @@ -17,15 +17,19 @@ ## Laboratory (LANL), the U.S. Government retains certain rights in ## this software. ##============================================================================ +if(NOT TARGET GLUT::GLUT) + find_package(GLUT QUIET) -vtkm_configure_component_GLUT() -if(VTKm_GLUT_FOUND) - set(unit_tests - UnitTestMapperGLUT.cxx - ) - VTKm_unit_tests( - SOURCES ${unit_tests} - TEST_ARGS -B - ) + if(NOT TARGET GLUT::GLUT) + return() + endif() endif() +set(unit_tests + UnitTestMapperGLUT.cxx + ) + +vtkm_unit_tests(SOURCES ${unit_tests} + TEST_ARGS -B + LIBRARIES vtkm_rendering GLUT::GLUT) + diff --git a/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx b/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx index 4eb1a63b4..078c1ba29 100644 --- a/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx +++ b/vtkm/rendering/testing/glut/UnitTestMapperGLUT.cxx @@ -20,11 +20,13 @@ #include #include +#include #if defined(__APPLE__) #include #else #include #endif + #include #include #include diff --git a/vtkm/rendering/testing/osmesa/CMakeLists.txt b/vtkm/rendering/testing/osmesa/CMakeLists.txt index e6df82942..543833c7a 100644 --- a/vtkm/rendering/testing/osmesa/CMakeLists.txt +++ b/vtkm/rendering/testing/osmesa/CMakeLists.txt @@ -17,11 +17,10 @@ ## Laboratory (LANL), the U.S. Government retains certain rights in ## this software. ##============================================================================ -vtkm_configure_component_OSMesa() -if (VTKm_OSMesa_FOUND) - set(unit_tests + +set(unit_tests UnitTestMapperOSMesa.cxx ) - VTKm_unit_tests(SOURCES ${unit_tests}) -endif() + +vtkm_unit_tests(SOURCES ${unit_tests} LIBRARIES vtkm_rendering)