Skip to content

Commit

Permalink
Merge pull request #21 from bjornblissing/sdk-v0.4
Browse files Browse the repository at this point in the history
Support for Oculus SDK v0.4.1
  • Loading branch information
Björn Blissing committed Aug 19, 2014
2 parents 4e55ef1 + bf115c1 commit 1bac19d
Show file tree
Hide file tree
Showing 21 changed files with 1,286 additions and 979 deletions.
76 changes: 57 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ PROJECT(OsgOculusViewer)

SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Show relative paths options
OPTION(CMAKE_USE_RELATIVE_PATHS "If true, cmake will use relative paths in makefiles and projects." ON)
# Check if we are doing out of source builds
STRING(COMPARE NOTEQUAL ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} CMAKE_OUT_OF_SOURCE_BUILD)

# Relative paths can be trouble when doing out of source builds
IF(CMAKE_OUT_OF_SOURCE_BUILD)
SET(DEFAULT_RELATIVE_PATHS OFF)
ELSE()
SET(DEFAULT_RELATIVE_PATHS ON)
ENDIF()

# Show relative paths options
OPTION(CMAKE_USE_RELATIVE_PATHS "If true, cmake will use relative paths in makefiles and projects." ${DEFAULT_RELATIVE_PATHS})
MARK_AS_ADVANCED(CMAKE_USE_RELATIVE_PATHS)

# Build example viewer
OPTION(BUILD_EXAMPLE "Enable to build viewer example" ON)
# Build example viewers
OPTION(BUILD_EXAMPLES "Enable to build viewer examples" ON)


IF (WIN32)
Expand All @@ -20,18 +30,28 @@ IF (WIN32)
IF(NOT OSG_DIR)
MESSAGE(FATAL_ERROR "Error: OpenSceneGraph not found.")
ENDIF(NOT OSG_DIR)

# Where to find OpenSceneGraph third party dependencies
SET(OSG_THIRD_PARTY_DIR CACHE PATH "Path where to find the OpenSceneGraph third party dependencies")
SET(OSG_THIRD_PARTY_DIR $ENV{OSG_THIRD_PARTY_DIR} CACHE PATH "Path where to find the OpenSceneGraph third party dependencies")
IF(NOT OSG_THIRD_PARTY_DIR)
MESSAGE(FATAL_ERROR "Error: OpenSceneGraph 3rd Party Directory not found.")
ENDIF(NOT OSG_THIRD_PARTY_DIR)

# Where to find Oculus SDK
SET(OCULUS_SDK_ROOT_DIR $ENV{OCULUS_SDK_ROOT_DIR} CACHE PATH "Path where to find the Oculus SDK")
IF(NOT OCULUS_SDK_ROOT_DIR)
MESSAGE(FATAL_ERROR "Error: Oculus SDK not found.")
ENDIF(NOT OCULUS_SDK_ROOT_DIR)

IF(MSVC)
OPTION(VISUAL_STUDIO_EXPRESS "Building with Visual Studio Express" OFF)
IF(VISUAL_STUDIO_EXPRESS)
# If building with Visual Studio Express we must specify location of ATL include directory and libraries
# These are not included in then Visual Studio Express install, but must be installed separately via Windows Driver Kit
SET(ATL_INCLUDE_DIR CACHE PATH "Path where to find the ATL include directory")
SET(ATL_LIBRARY_DIR CACHE PATH "Path where to find the ATL libries directory")
ENDIF(VISUAL_STUDIO_EXPRESS)
ENDIF(MSVC)
ENDIF(WIN32)

#Solution
Expand All @@ -45,20 +65,31 @@ FIND_PACKAGE( OpenGL REQUIRED )
FIND_PACKAGE( OpenSceneGraph REQUIRED osgViewer osgDB osgGA)
FIND_PACKAGE( OculusSDK REQUIRED )

# Oculus SDK dependencies for Mac OSX
IF (APPLE)
FIND_LIBRARY (CORE_FOUNDATION CoreFoundation)
FIND_LIBRARY (CORE_GRAPHICS CoreGraphics)
FIND_LIBRARY (IOKIT IOKit)
ENDIF (APPLE)

INCLUDE_DIRECTORIES(BEFORE
${OPENGL_INCLUDE_DIR}
${OPENSCENEGRAPH_INCLUDE_DIR}
${OCULUS_SDK_INCLUDE_DIRS}
)

IF(VISUAL_STUDIO_EXPRESS)
INCLUDE_DIRECTORIES(BEFORE
${ATL_INCLUDE_DIR}
)
ENDIF(VISUAL_STUDIO_EXPRESS)

# osgViewer::ViewConfig concept requires osg 3.2 or later
IF(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL 3.2.0 AND
NOT OPENSCENEGRAPH_VERSION VERSION_GREATER 3.2.0)
SET (USE_VIEW_CONFIG OFF)
SET (BUILD_DEPRECATED ON)
ELSE()
SET (USE_VIEW_CONFIG ON)
OPTION(BUILD_DEPRECATED "Enable to build deprecated version as well" OFF)
ENDIF()

###############################################################################
Expand All @@ -68,18 +99,18 @@ IF(MSVC)
# Make sure we use minimal windows.h library without min max macros
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"WIN32_LEAN_AND_MEAN\"")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D \"NOMINMAX\"")

# Use Link Time Code Generation
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG")
IF(MSVC80)
# Detech 64-bit portability Issues
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wp64")
ENDIF(MSVC80)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")

# Add ATL libraries for Visual Studio Express builds
IF(VISUAL_STUDIO_EXPRESS)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LIBPATH:${ATL_LIBRARY_DIR}")
ENDIF(VISUAL_STUDIO_EXPRESS)

OPTION(BUILD_MULTI_PROCESSOR_COMPILATION "Use multiple processors when compiling" ON)
MARK_AS_ADVANCED(BUILD_MULTI_PROCESSOR_COMPILATION)

IF(BUILD_MULTI_PROCESSOR_COMPILATION)
# Set multi processor build
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
Expand All @@ -95,9 +126,16 @@ IF(UNIX)
IF(CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-Wall -ansi -pedantic -Wextra)
IF (WARNINGS_AS_ERRORS)
ADD_DEFINITIONS(-Werror)
ADD_DEFINITIONS(-Werror)
ENDIF(WARNINGS_AS_ERRORS)
ENDIF(CMAKE_COMPILER_IS_GNUCC)
IF (APPLE)
# set standard lib, clang defaults to c++0x
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++98")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libstdc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98 -stdlib=libstdc++ -Wno-overloaded-virtual -Wno-conversion")
set(WARNING_CFLAGS "")
ENDIF()
ENDIF(UNIX)

###############################################################################
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OsgOculusViewer

An OsgViewer with support for the Oculus Rift

Last tested against Oculus SDK 0.2.5
Last tested against Oculus SDK 0.4.1 Beta

To be able to use the osgViewer::ViewConfig version you will need to use OpenSceneGraph 3.2.0 or later.

Expand All @@ -13,6 +13,8 @@ License
Source code is licensed according to the 3-clause license BSD-license.
See license.txt for complete licensing information.

**NOTE** By linking to the Oculus SDK libraries you must adhere to the terms of the Oculus SDK License Agreement.


Contributors
------------
Expand All @@ -21,3 +23,5 @@ Björn Blissing
Jan Ciger

Nico Kruithof

Daniel Sjölie
72 changes: 62 additions & 10 deletions cmake/FindOculusSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# OCULUS_SDK_INCLUDE_DIRS - where to find OVR.h, etc.
# OCULUS_SDK_LIBRARIES - List of libraries when using OculusSDK.
# OCULUS_SDK_FOUND - True if OculusSDK found.
# OCULUS_SDK_VERSION - Version of the OculusSDK if found

IF (DEFINED ENV{OCULUS_SDK_ROOT_DIR})
SET(OCULUS_SDK_ROOT_DIR "$ENV{OCULUS_SDK_ROOT_DIR}")
Expand All @@ -20,29 +21,80 @@ FIND_PATH(OCULUS_SDK_INCLUDE_DIRS NAMES OVR.h HINTS

# Determine architecture
IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(OCULUS_SDK_LIB_ARCH "x86_64" CACHE STRING "library location")
IF(UNIX)
SET(_OCULUS_SDK_LIB_ARCH "x86_64")
ENDIF()
IF(MSVC)
SET(_OCULUS_SDK_LIB_ARCH "x64")
ENDIF()
ELSE()
SET(OCULUS_SDK_LIB_ARCH "i386" CACHE STRING "library location")
IF(UNIX)
SET(_OCULUS_SDK_LIB_ARCH "i386")
ENDIF()
IF(MSVC)
SET(_OCULUS_SDK_LIB_ARCH "Win32")
ENDIF()
ENDIF()
MARK_AS_ADVANCED(OCULUS_SDK_LIB_ARCH)

MARK_AS_ADVANCED(_OCULUS_SDK_LIB_ARCH)

# Append "d" to debug libs on windows platform
IF (WIN32)
SET(CMAKE_DEBUG_POSTFIX d)
ENDIF()

# Determine the compiler version for Visual Studio
IF (MSVC)
# Visual Studio 2010
IF(MSVC10)
SET(_OCULUS_MSVC_DIR "VS2010")
ENDIF()
# Visual Studio 2012
IF(MSVC11)
SET(_OCULUS_MSVC_DIR "VS2012")
ENDIF()
# Visual Studio 2013
IF(MSVC12)
SET(_OCULUS_MSVC_DIR "VS2013")
ENDIF()
ENDIF()

# Try to ascertain the version of the SDK
IF(OCULUS_SDK_INCLUDE_DIRS)
SET(_OCULUS_VERSION_FILE "${OCULUS_SDK_INCLUDE_DIRS}/OVR_Version.h")

IF(EXISTS "${_OCULUS_VERSION_FILE}")
FILE(STRINGS "${_OCULUS_VERSION_FILE}" _OCULUS_VERSION_FILE_CONTENTS REGEX "#define OVR_[A-Z]+_VERSION[ \t]+[0-9]+")

STRING(REGEX REPLACE ".*#define OVR_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" OCULUS_SDK_VERSION_MAJOR ${_OCULUS_VERSION_FILE_CONTENTS})
STRING(REGEX REPLACE ".*#define OVR_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" OCULUS_SDK_VERSION_MINOR ${_OCULUS_VERSION_FILE_CONTENTS})
STRING(REGEX REPLACE ".*#define OVR_BUILD_VERSION[ \t]+([0-9]+).*" "\\1" OCULUS_SDK_VERSION_BUILD ${_OCULUS_VERSION_FILE_CONTENTS})

SET(OCULUS_SDK_VERSION "${OCULUS_SDK_VERSION_MAJOR}.${OCULUS_SDK_VERSION_MINOR}.${OCULUS_SDK_VERSION_BUILD}" CACHE INTERNAL "The version of Oculus SDK which was detected")
ENDIF()
ENDIF()

# Locate Oculus license file
SET(_OCULUS_SDK_LICENSE_FILE "${OCULUS_SDK_ROOT_DIR}/LICENSE.txt")
IF(EXISTS "${_OCULUS_SDK_LICENSE_FILE}")
SET(OCULUS_SDK_LICENSE_FILE "${_OCULUS_SDK_LICENSE_FILE}" CACHE INTERNAL "The location of the Oculus SDK license file")
ENDIF()

# Look for the library.
FIND_LIBRARY(OCULUS_SDK_LIBRARY NAMES libovr ovr HINTS ${OCULUS_SDK_ROOT_DIR}
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Win32
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Linux/Release/${OCULUS_SDK_LIB_ARCH}
FIND_LIBRARY(OCULUS_SDK_LIBRARY NAMES libovr libovr64 ovr HINTS ${OCULUS_SDK_ROOT_DIR}
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/${_OCULUS_SDK_LIB_ARCH}/${_OCULUS_MSVC_DIR}
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Mac/Release
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Linux/Release/${_OCULUS_SDK_LIB_ARCH}
)

# This will find release lib on Linux if no debug is available - on Linux this is no problem and avoids
# having to compile in debug when not needed
FIND_LIBRARY(OCULUS_SDK_LIBRARY_DEBUG NAMES libovr${CMAKE_DEBUG_POSTFIX} ovr${CMAKE_DEBUG_POSTFIX} ovr HINTS
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Win32
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Linux/Debug/${OCULUS_SDK_LIB_ARCH}
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Linux/Release/${OCULUS_SDK_LIB_ARCH}
FIND_LIBRARY(OCULUS_SDK_LIBRARY_DEBUG NAMES libovr${CMAKE_DEBUG_POSTFIX} libovr64${CMAKE_DEBUG_POSTFIX} ovr${CMAKE_DEBUG_POSTFIX} ovr libovr HINTS
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/${_OCULUS_SDK_LIB_ARCH}/${_OCULUS_MSVC_DIR}
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Mac/Debug
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Mac/Release
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Linux/Debug/${_OCULUS_SDK_LIB_ARCH}
${OCULUS_SDK_ROOT_DIR}/LibOVR/Lib/Linux/Release/${_OCULUS_SDK_LIB_ARCH}
)

MARK_AS_ADVANCED(OCULUS_SDK_LIBRARY)
Expand Down
2 changes: 1 addition & 1 deletion license.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013, Swedish National Road and Transport Research Institute
Copyright (c) 2013-2014, Swedish National Road and Transport Research Institute
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
Loading

0 comments on commit 1bac19d

Please sign in to comment.