From 0d436856ebc7f9d7e4a99d8b20d5b0482b159b35 Mon Sep 17 00:00:00 2001
From: Arnaud Gelas <arnaudgelas@gmail.com>
Date: Mon, 16 Apr 2012 16:18:35 +0200
Subject: [PATCH] Add hint variables one for FindOpenSceneGraph, one for
 FindOpenThreads

 OSG_DIR - FindOpenSceneGraph and FindOpenThreads
 OPENTHREADS_DIR - FindOpenThreads
---
 Modules/FindOpenSceneGraph.cmake |   18 +++++++++-----
 Modules/FindOpenThreads.cmake    |   47 +++++++++++++++++++++-----------------
 Modules/Findosg_functions.cmake  |    8 +++++-
 3 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/Modules/FindOpenSceneGraph.cmake b/Modules/FindOpenSceneGraph.cmake
index 52f9316..88dfd5b 100644
--- a/Modules/FindOpenSceneGraph.cmake
+++ b/Modules/FindOpenSceneGraph.cmake
@@ -14,7 +14,7 @@
 #
 #    OpenSceneGraph_DEBUG - Enable debugging output
 #
-#    OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced 
+#    OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
 #                                      automatically
 #
 # The following environment variables are also respected for finding the OSG
@@ -26,6 +26,12 @@
 #    OSGDIR
 #    OSG_ROOT
 #
+
+# OPENTHREADS_DIR and OSG_DIR are not environment variables and can be set as
+# HINTS when looking for libraries and headers. Note that OPENTHREADS_DIR is a
+# specific variable for OpenThreads; whereas OSG_DIR is shared among all
+# OpenSceneGraph modules/libraries.
+#
 # This module defines the following output variables:
 #
 #    OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
@@ -96,12 +102,12 @@ if(OSG_INCLUDE_DIR)
         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
             "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
     endif()
-    
+
     set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
     if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
         set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
     endif()
-    
+
     if(EXISTS "${_osg_Version_file}")
       file(READ "${_osg_Version_file}" _osg_Version_contents)
     else()
@@ -149,7 +155,7 @@ if(OpenSceneGraph_FIND_VERSION AND OPENSCENEGRAPH_VERSION)
         endif()
     else()
         # version is too low
-        if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION} AND 
+        if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION} AND
                 NOT OPENSCENEGRAPH_VERSION VERSION_GREATER ${OpenSceneGraph_FIND_VERSION})
             set(_osg_version_not_high_enough TRUE)
         endif()
@@ -182,7 +188,7 @@ endforeach()
 if(OPENSCENEGRAPH_INCLUDE_DIR)
     list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
 endif()
-        
+
 #
 # Inform the users with an error message based on
 # what version they have vs. what version was
@@ -221,7 +227,7 @@ else()
                 set(_osg_missing_message "${_osg_missing_message} ${_osg_module}")
             endif()
         endforeach()
-    
+
         if(_osg_missing_nodekit_fail)
             message(FATAL_ERROR "ERROR: Missing the following osg "
                 "libraries: ${_osg_missing_message}.\n"
diff --git a/Modules/FindOpenThreads.cmake b/Modules/FindOpenThreads.cmake
index 6b81fbe..0383d56 100644
--- a/Modules/FindOpenThreads.cmake
+++ b/Modules/FindOpenThreads.cmake
@@ -1,19 +1,19 @@
-# OpenThreads is a C++ based threading library. Its largest userbase 
-# seems to OpenSceneGraph so you might notice I accept OSGDIR as an
-# environment path.
-# I consider this part of the Findosg* suite used to find OpenSceneGraph 
-# components.
-# Each component is separate and you must opt in to each module.
-# 
-# Locate OpenThreads
-# This module defines
-# OPENTHREADS_LIBRARY
-# OPENTHREADS_FOUND, if false, do not try to link to OpenThreads
-# OPENTHREADS_INCLUDE_DIR, where to find the headers
+# OpenThreads is a C++ based threading library. Its largest userbase seems to
+# OpenSceneGraph so you might notice I accept OSGDIR as an environment path.  I
+# consider this part of the Findosg* suite used to find OpenSceneGraph
+# components.  Each component is separate and you must opt in to each module.
 #
-# $OPENTHREADS_DIR is an environment variable that would
-# correspond to the ./configure --prefix=$OPENTHREADS_DIR
-# used in building osg.
+# Locate OpenThreads This module defines OPENTHREADS_LIBRARY OPENTHREADS_FOUND,
+# if false, do not try to link to OpenThreads OPENTHREADS_INCLUDE_DIR, where to
+# find the headers
+#
+# $OPENTHREADS_DIR is an environment variable that would correspond to the
+# ./configure --prefix=$OPENTHREADS_DIR used in building osg.
+#
+# OPENTHREADS_DIR and OSG_DIR are not environment variables and can be set as
+# HINTS when looking for libraries and headers. Note that OPENTHREADS_DIR is a
+# specific variable for OpenThreads; whereas OSG_DIR is shared among all
+# OpenSceneGraph modules/libraries.
 #
 # Created by Eric Wing.
 
@@ -34,8 +34,8 @@
 # #include <OpenThreads/Thread>
 
 # To make it easier for one-step automated configuration/builds,
-# we leverage environmental paths. This is preferable 
-# to the -DVAR=value switches because it insulates the 
+# we leverage environmental paths. This is preferable
+# to the -DVAR=value switches because it insulates the
 # users from changes we may make in this script.
 # It also offers a little more flexibility than setting
 # the CMAKE_*_PATH since we can target specific components.
@@ -53,7 +53,6 @@
 
 find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
     HINTS
-        # enough environment variables?
         $ENV{OPENTHREADS_INCLUDE_DIR}
         $ENV{OPENTHREADS_DIR}
         $ENV{OSG_INCLUDE_DIR}
@@ -61,6 +60,8 @@ find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
         $ENV{OSGDIR}
         $ENV{OpenThreads_ROOT}
         $ENV{OSG_ROOT}
+        ${OPENTHREADS_DIR}
+        ${OSG_DIR}
     PATHS
         /sw # Fink
         /opt/local # DarwinPorts
@@ -71,8 +72,8 @@ find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
 )
 
 
-find_library(OPENTHREADS_LIBRARY 
-    NAMES OpenThreads OpenThreadsWin32 
+find_library(OPENTHREADS_LIBRARY
+    NAMES OpenThreads OpenThreadsWin32
     HINTS
         $ENV{OPENTHREADS_LIBRARY_DIR}
         $ENV{OPENTHREADS_DIR}
@@ -81,6 +82,8 @@ find_library(OPENTHREADS_LIBRARY
         $ENV{OSGDIR}
         $ENV{OpenThreads_ROOT}
         $ENV{OSG_ROOT}
+        ${OPENTHREADS_DIR}
+        ${OSG_DIR}
     PATHS
         /sw
         /opt/local
@@ -90,7 +93,7 @@ find_library(OPENTHREADS_LIBRARY
     PATH_SUFFIXES lib64 lib
 )
 
-find_library(OPENTHREADS_LIBRARY_DEBUG 
+find_library(OPENTHREADS_LIBRARY_DEBUG
     NAMES OpenThreadsd OpenThreadsWin32d
     HINTS
         $ENV{OPENTHREADS_DEBUG_LIBRARY_DIR}
@@ -101,6 +104,8 @@ find_library(OPENTHREADS_LIBRARY_DEBUG
         $ENV{OSGDIR}
         $ENV{OpenThreads_ROOT}
         $ENV{OSG_ROOT}
+        ${OPENTHREADS_DIR}
+        ${OSG_DIR}
     PATHS
         /sw
         /opt/local
diff --git a/Modules/Findosg_functions.cmake b/Modules/Findosg_functions.cmake
index ab836ff..8fde5a0 100644
--- a/Modules/Findosg_functions.cmake
+++ b/Modules/Findosg_functions.cmake
@@ -30,6 +30,8 @@ function(OSG_FIND_PATH module header)
             $ENV{OSG_DIR}
             $ENV{OSGDIR}
             $ENV{OSG_ROOT}
+            ${${module_uc}_DIR}
+            ${OSG_DIR}
        PATH_SUFFIXES include
        PATHS
             /sw # Fink
@@ -54,6 +56,8 @@ function(OSG_FIND_LIBRARY module library)
             $ENV{OSG_DIR}
             $ENV{OSGDIR}
             $ENV{OSG_ROOT}
+            ${${module_uc}_DIR}
+            ${OSG_DIR}
        PATH_SUFFIXES lib64 lib
        PATHS
             /sw # Fink
@@ -70,6 +74,8 @@ function(OSG_FIND_LIBRARY module library)
             $ENV{OSG_DIR}
             $ENV{OSGDIR}
             $ENV{OSG_ROOT}
+            ${${module_uc}_DIR}
+            ${OSG_DIR}
        PATH_SUFFIXES lib64 lib
        PATHS
             /sw # Fink
@@ -85,7 +91,7 @@ function(OSG_FIND_LIBRARY module library)
       set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARY} PARENT_SCOPE)
    else()
       # They really have a FOO_LIBRARY_DEBUG
-      set(${module_uc}_LIBRARIES 
+      set(${module_uc}_LIBRARIES
           optimized ${${module_uc}_LIBRARY}
           debug ${${module_uc}_LIBRARY_DEBUG}
           PARENT_SCOPE
-- 
1.7.5.4

