From 85446c8cf1da95d0119e0b643144f2959bfa2088 Mon Sep 17 00:00:00 2001
From: Aleric Inglewood <Aleric.Inglewood@gmail.com>
Date: Wed, 15 Dec 2010 22:44:21 +0100
Subject: [PATCH] VWR-10579: Fix NDOF.cmake to do the right thing on
 standalone.

The old one just assumed that libndof is installed,
even on standalone.

This patch looks for it on standalone, unless configured
with -DNDOF:BOOL=OFF, and when not found prints an error
message (including telling about -DNDOF:BOOL=OFF).
---
 doc/contributions.txt      |  4 ++++
 indra/cmake/FindNDOF.cmake | 39 ++++++++++++++++++++++++++++++++++++++
 indra/cmake/NDOF.cmake     | 34 +++++++++++++++++++++++++--------
 3 files changed, 69 insertions(+), 8 deletions(-)
 create mode 100644 indra/cmake/FindNDOF.cmake

diff --git a/doc/contributions.txt b/doc/contributions.txt
index 35a82569004..05e5e0f43cb 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -67,6 +67,7 @@ Aleric Inglewood
 	SNOW-756
 	SNOW-764
 	VWR-10001
+	VWR-10579
 	VWR-10759
 	VWR-10837
 	VWR-12691
@@ -215,6 +216,8 @@ Catherine Pfeffer
 Celierra Darling
 	VWR-1274
 	VWR-6975
+Cron Stardust
+	VWR-10579
 Cypren Christenson
 	STORM-417
 Dale Glass
@@ -591,6 +594,7 @@ Robin Cornelius
 	STORM-422
 	VWR-2488
 	VWR-9557
+	VWR-10579
 	VWR-11128
 	VWR-12533
 	VWR-12587
diff --git a/indra/cmake/FindNDOF.cmake b/indra/cmake/FindNDOF.cmake
new file mode 100644
index 00000000000..6dcf590a53d
--- /dev/null
+++ b/indra/cmake/FindNDOF.cmake
@@ -0,0 +1,39 @@
+# -*- cmake -*-
+
+# - Find NDOF
+# Find the NDOF includes and library
+# This module defines
+#  NDOF_INCLUDE_DIR, where to find ndofdev_external.h, etc.
+#  NDOF_LIBRARY, the library needed to use NDOF.
+#  NDOF_FOUND, If false, do not try to use NDOF.
+
+find_path(NDOF_INCLUDE_DIR ndofdev_external.h
+  PATH_SUFFIXES ndofdev
+  )
+
+set(NDOF_NAMES ${NDOF_NAMES} ndofdev libndofdev)
+find_library(NDOF_LIBRARY
+  NAMES ${NDOF_NAMES}
+  )
+
+if (NDOF_LIBRARY AND NDOF_INCLUDE_DIR)
+  set(NDOF_FOUND "YES")
+else (NDOF_LIBRARY AND NDOF_INCLUDE_DIR)
+  set(NDOF_FOUND "NO")
+endif (NDOF_LIBRARY AND NDOF_INCLUDE_DIR)
+
+
+if (NDOF_FOUND)
+  if (NOT NDOF_FIND_QUIETLY)
+    message(STATUS "Found NDOF: Library in '${NDOF_LIBRARY}' and header in '${NDOF_INCLUDE_DIR}' ")
+  endif (NOT NDOF_FIND_QUIETLY)
+else (NDOF_FOUND)
+  if (NDOF_FIND_REQUIRED)
+    message(FATAL_ERROR " * * *\nCould not find NDOF library!\nIf you don't need Space Navigator Joystick support you can skip this test by configuring with -DNDOF:BOOL=OFF\n * * *")
+  endif (NDOF_FIND_REQUIRED)
+endif (NDOF_FOUND)
+
+mark_as_advanced(
+  NDOF_LIBRARY
+  NDOF_INCLUDE_DIR
+  )
diff --git a/indra/cmake/NDOF.cmake b/indra/cmake/NDOF.cmake
index dad74e99b1b..7a463d11907 100644
--- a/indra/cmake/NDOF.cmake
+++ b/indra/cmake/NDOF.cmake
@@ -1,14 +1,32 @@
 # -*- cmake -*-
 include(Prebuilt)
 
-use_prebuilt_binary(ndofdev)
+set(NDOF ON CACHE BOOL "Use NDOF space navigator joystick library.")
 
-if (WINDOWS OR DARWIN OR LINUX)
+if (NDOF)
+  if (STANDALONE)
+	set(NDOF_FIND_REQUIRED ON)
+	include(FindNDOF)
+  else (STANDALONE)
+	use_prebuilt_binary(ndofdev)
+
+	if (WINDOWS)
+	  set(NDOF_LIBRARY libndofdev)
+	elseif (DARWIN OR LINUX)
+	  set(NDOF_LIBRARY ndofdev)
+	endif (WINDOWS)
+
+	set(NDOF_INCLUDE_DIR ${ARCH_PREBUILT_DIRS}/include/ndofdev)
+	set(NDOF_FOUND 1)
+  endif (STANDALONE)
+endif (NDOF)
+
+if (NDOF_FOUND)
   add_definitions(-DLIB_NDOF=1)
-endif (WINDOWS OR DARWIN OR LINUX)
+  include_directories(${NDOF_INCLUDE_DIR})
+else (NDOF_FOUND)
+  message(STATUS "Building without N-DoF joystick support")
+  set(NDOF_INCLUDE_DIR "")
+  set(NDOF_LIBRARY "")
+endif (NDOF_FOUND)
 
-if (WINDOWS)
-  set(NDOF_LIBRARY libndofdev)
-elseif (DARWIN OR LINUX)
-  set(NDOF_LIBRARY ndofdev)
-endif (WINDOWS)
-- 
GitLab