[Bf-blender-cvs] [864abbd4251] soc-2019-openxr: Support system installed OpenXR SDK

Julian Eisel noreply at git.blender.org
Thu May 30 01:51:43 CEST 2019


Commit: 864abbd42514542559d9e99bf47e8ffff418e54d
Author: Julian Eisel
Date:   Thu May 30 01:44:13 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB864abbd42514542559d9e99bf47e8ffff418e54d

Support system installed OpenXR SDK

Adds OPENXR_USE_BUNDLED_SRC so that if disabled, CMake tries to find
the SDK headers and libraries in system paths or in specified root
directory.

I guess this is the way we'd want to do this in master. However for
people testing the branch the bundled sources are much more convenient
(should work out of the box, no need to compile the SDK manually).

===================================================================

M	CMakeLists.txt
A	build_files/cmake/Modules/FindOpenXR-SDK.cmake
M	build_files/cmake/macros.cmake
M	extern/CMakeLists.txt
M	source/blender/windowmanager/CMakeLists.txt

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5c0dfb971a8..0e072831fc5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -235,6 +235,16 @@ option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported
 mark_as_advanced(WITH_SYSTEM_BULLET)
 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
 option(WITH_OPENXR        "Enable VR features through the OpenXR specification" ON)
+if(WITH_OPENXR)
+  option(OPENXR_USE_BUNDLED_SRC "Compile using the bundled OpenXR SDK sources (otherwise it has to be compiled manually)" ON)
+  if(NOT OPENXR_USE_BUNDLED_SRC)
+    find_package(OpenXR-SDK)
+    if(NOT OPENXR_SDK_FOUND)
+      message(WARNING "OpenXR-SDK was not found, disabling WITH_OPENXR")
+      set(WITH_OPENXR OFF)
+    endif()
+  endif()
+endif()
 
 # Compositor
 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
diff --git a/build_files/cmake/Modules/FindOpenXR-SDK.cmake b/build_files/cmake/Modules/FindOpenXR-SDK.cmake
new file mode 100644
index 00000000000..6682f665465
--- /dev/null
+++ b/build_files/cmake/Modules/FindOpenXR-SDK.cmake
@@ -0,0 +1,67 @@
+# - Find OpenXR-SDK library
+# Find the native OpenXR-SDK includes and library
+# This module defines
+#  OPENXR_SDK_INCLUDE_DIRS, where to find OpenXR-SDK headers, Set when
+#                           OPENXR_SDK_INCLUDE_DIR is found.
+#  OPENXR_SDK_LIBRARIES, libraries to link against to use OpenXR-SDK.
+#  OPENXR_SDK_ROOT_DIR, the base directory to search for OpenXR-SDK.
+#                        This can also be an environment variable.
+#  OPENXR_SDK_FOUND, if false, do not try to use OpenXR-SDK.
+#
+# also defined, but not for general use are
+#  OPENXR_LOADER_LIBRARY, where to find the OpenXR-SDK library.
+
+#=============================================================================
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.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 License for more information.
+#=============================================================================
+
+# If OPENXR_SDK_ROOT_DIR was defined in the environment, use it.
+IF(NOT OPENXR_SDK_ROOT_DIR AND NOT $ENV{OPENXR_SDK_ROOT_DIR} STREQUAL "")
+  SET(OPENXR_SDK_ROOT_DIR $ENV{OPENXR_SDK_ROOT_DIR})
+ENDIF()
+
+SET(_openxr_sdk_SEARCH_DIRS
+  ${OPENXR_SDK_ROOT_DIR}
+  /usr/local
+  /sw # Fink
+  /opt/local # DarwinPorts
+)
+
+FIND_PATH(OPENXR_SDK_INCLUDE_DIR
+  NAMES
+    openxr/openxr.h
+  HINTS
+    ${_openxr_sdk_SEARCH_DIRS}
+  PATH_SUFFIXES
+    include
+)
+
+FIND_LIBRARY(OPENXR_LOADER_LIBRARY
+  NAMES
+    openxr_loader
+  HINTS
+    ${_openxr_sdk_SEARCH_DIRS}
+  PATH_SUFFIXES
+    lib64 lib
+)
+
+# handle the QUIETLY and REQUIRED arguments and set OPENXR_SDK_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENXR_SDK DEFAULT_MSG
+    OPENXR_LOADER_LIBRARY OPENXR_SDK_INCLUDE_DIR)
+
+IF(OPENXR_SDK_FOUND)
+  SET(OPENXR_SDK_LIBRARIES ${OPENXR_LOADER_LIBRARY})
+  SET(OPENXR_SDK_INCLUDE_DIRS ${OPENXR_SDK_INCLUDE_DIR})
+ENDIF(OPENXR_SDK_FOUND)
+
+MARK_AS_ADVANCED(
+  OPENXR_SDK_INCLUDE_DIR
+  OPENXR_LOADER_LIBRARY
+)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 10b293c64b4..e9736acf7d2 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -451,6 +451,9 @@ function(setup_liblinks
   if(WITH_OPENSUBDIV)
       target_link_libraries(${target} ${OPENSUBDIV_LIBRARIES})
   endif()
+  if(WITH_OPENXR)
+    target_link_libraries(${target} ${OPENXR_SDK_LIBRARIES})
+  endif()
   if(WITH_CYCLES_EMBREE)
     target_link_libraries(${target} ${EMBREE_LIBRARIES})
   endif()
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 94b9ac4a909..104ac4307ca 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -106,7 +106,7 @@ if(WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE)
   add_subdirectory(audaspace)
 endif()
 
-if(WITH_OPENXR)
+if(WITH_OPENXR AND OPENXR_USE_BUNDLED_SRC)
   add_subdirectory(jsoncpp)
   add_subdirectory(openxr)
-endif()
\ No newline at end of file
+endif()
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index c65a9ca470a..e1e11b3759f 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -175,21 +175,23 @@ if(WITH_COMPOSITOR)
 endif()
 
 if(WITH_OPENXR)
-  list(APPEND INC
-    ../../../extern/openxr/include
+  list(APPEND INC_SYS
+    ${OPENXR_SDK_INCLUDES}
   )
-
   add_definitions(-DWITH_OPENXR)
 endif()
 
 blender_add_lib_nolist(bf_windowmanager "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
 
 if(WITH_OPENXR)
-  add_dependencies(bf_windowmanager generate_openxr_header)
-  if(WIN32)
-      set(OPENXR_LOADER_NAME openxr_loader-0_90)
-  else()
-      set(OPENXR_LOADER_NAME openxr_loader)
+  if(OPENXR_USE_BUNDLED_SRC)
+    if(WIN32)
+        set(OPENXR_LOADER_NAME openxr_loader-0_90)
+    else()
+        set(OPENXR_LOADER_NAME openxr_loader)
+    endif()
+
+    add_dependencies(bf_windowmanager generate_openxr_header)
+    target_link_libraries(bf_windowmanager ${OPENXR_LOADER_NAME})
   endif()
-  target_link_libraries(bf_windowmanager ${OPENXR_LOADER_NAME})
 endif()



More information about the Bf-blender-cvs mailing list