From aecf408585d5e7af62f06c056ffee309602f2bf6 Mon Sep 17 00:00:00 2001
From: kervala <none@none>
Date: Mon, 23 May 2011 12:52:35 +0200
Subject: [PATCH] Fixed: Luabind detection when compiled from sources

---
 code/CMakeModules/FindLuabind.cmake | 31 +++++++++++++++++------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/code/CMakeModules/FindLuabind.cmake b/code/CMakeModules/FindLuabind.cmake
index b73530ef5..75dfbd73f 100644
--- a/code/CMakeModules/FindLuabind.cmake
+++ b/code/CMakeModules/FindLuabind.cmake
@@ -6,7 +6,7 @@
 
 IF(LUABIND_LIBRARIES AND LUABIND_INCLUDE_DIR)
   # in cache already
-  SET(LUABIND_FIND_QUIETLY TRUE)
+  SET(Luabind_FIND_QUIETLY TRUE)
 ENDIF(LUABIND_LIBRARIES AND LUABIND_INCLUDE_DIR)
 
 FIND_PATH(LUABIND_INCLUDE_DIR
@@ -62,30 +62,35 @@ FIND_LIBRARY(LUABIND_LIBRARY_DEBUG
 FIND_PACKAGE(Boost REQUIRED)
 
 IF(LUABIND_INCLUDE_DIR AND Boost_INCLUDE_DIR)
-  IF(LUABIND_LIBRARY_RELEASE)
+  IF(LUABIND_LIBRARY_RELEASE AND LUABIND_LIBRARY_DEBUG)
+    # Case where both Release and Debug versions are provided
     SET(LUABIND_FOUND TRUE)
-    SET(LUABIND_INCLUDE_DIR ${LUABIND_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
-    IF(LUABIND_LIBRARY_DEBUG)
-      SET(LUABIND_LIBRARIES "optimized;${LUABIND_LIBRARY_RELEASE};debug;${LUABIND_LIBRARY_DEBUG}")
-    ELSE(LUABIND_LIBRARY_DEBUG)
-      SET(LUABIND_LIBRARIES "${LUABIND_LIBRARY_RELEASE}")
-    ENDIF(LUABIND_LIBRARY_DEBUG)
-  ENDIF(LUABIND_LIBRARY_RELEASE)
+    SET(LUABIND_LIBRARIES optimized ${LUABIND_LIBRARY_RELEASE} debug ${LUABIND_LIBRARY_DEBUG})
+  ELSEIF(LUABIND_LIBRARY_RELEASE)
+    # Normal case
+    SET(LUABIND_FOUND TRUE)
+    SET(LUABIND_LIBRARIES ${LUABIND_LIBRARY_RELEASE})
+  ELSEIF(LUABIND_LIBRARY_DEBUG)
+    # Case where Luabind is compiled from sources (debug version is compiled by default)
+    SET(LUABIND_FOUND TRUE)
+    SET(LUABIND_LIBRARIES ${LUABIND_LIBRARY_DEBUG})
+  ENDIF(LUABIND_LIBRARY_RELEASE AND LUABIND_LIBRARY_DEBUG)
 ENDIF(LUABIND_INCLUDE_DIR AND Boost_INCLUDE_DIR)
 
 IF(LUABIND_FOUND)
+  SET(LUABIND_INCLUDE_DIR ${LUABIND_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
   # Check if luabind/version.hpp exists
   FIND_FILE(LUABIND_VERSION_FILE luabind/version.hpp PATHS ${LUABIND_INCLUDE_DIR})
   IF(LUABIND_VERSION_FILE)
     SET(LUABIND_DEFINITIONS "-DHAVE_LUABIND_VERSION")
   ENDIF(LUABIND_VERSION_FILE)
-  IF(NOT LUABIND_FIND_QUIETLY)
+  IF(NOT Luabind_FIND_QUIETLY)
     MESSAGE(STATUS "Found Luabind: ${LUABIND_LIBRARIES}")
-  ENDIF(NOT LUABIND_FIND_QUIETLY)
+  ENDIF(NOT Luabind_FIND_QUIETLY)
 ELSE(LUABIND_FOUND)
-  IF(NOT LUABIND_FIND_QUIETLY)
+  IF(NOT Luabind_FIND_QUIETLY)
     MESSAGE(STATUS "Warning: Unable to find Luabind!")
-  ENDIF(NOT LUABIND_FIND_QUIETLY)
+  ENDIF(NOT Luabind_FIND_QUIETLY)
 ENDIF(LUABIND_FOUND)
 
 MARK_AS_ADVANCED(LUABIND_LIBRARY_RELEASE LUABIND_LIBRARY_DEBUG Boost_LIB_DIAGNOSTIC_DEFINITIONS)