From f2c4e513a426f1215ed0df37a60e3b41e787788c Mon Sep 17 00:00:00 2001
From: k1ll <karl.glatzer@gmx.de>
Date: Thu, 5 Apr 2012 13:01:09 +0200
Subject: [PATCH] Add support for building with a static build of the MyGui
 Libraries.

---
 CMakeLists.txt        |  1 +
 cmake/FindMyGUI.cmake | 45 +++++++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e0f67e4bf5..71f36fe3de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,6 +24,7 @@ set (OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VE
 
 configure_file ("${OpenMW_SOURCE_DIR}/Docs/mainpage.hpp.cmake" "${OpenMW_SOURCE_DIR}/Docs/mainpage.hpp")
 
+option(MYGUI_STATIC "Link static build of Mygui into the binaries" FALSE)
 option(OGRE_STATIC "Link static build of Ogre and Ogre Plugins into the binaries" FALSE)
 
 # Sound source selection
diff --git a/cmake/FindMyGUI.cmake b/cmake/FindMyGUI.cmake
index cc97992084..6731d584c0 100644
--- a/cmake/FindMyGUI.cmake
+++ b/cmake/FindMyGUI.cmake
@@ -82,20 +82,37 @@ findpkg_finish ( "MYGUI" )
 ELSE (WIN32) #Unix
     CMAKE_MINIMUM_REQUIRED(VERSION 2.4.7 FATAL_ERROR)
     FIND_PACKAGE(PkgConfig)
-    PKG_SEARCH_MODULE(MYGUI MYGUI MyGUI)
-    IF (MYGUI_INCLUDE_DIRS)
-        SET(MYGUI_INCLUDE_DIRS ${MYGUI_INCLUDE_DIRS})
-        SET(MYGUI_LIB_DIR ${MYGUI_LIBDIR})
-        SET(MYGUI_LIBRARIES ${MYGUI_LIBRARIES} CACHE STRING "")
-        SET(MYGUI_PLATFORM_LIBRARIES "MyGUI.OgrePlatform")
-    ELSE (MYGUI_INCLUDE_DIRS)
-        FIND_PATH(MYGUI_INCLUDE_DIRS MyGUI.h PATHS /usr/local/include /usr/include PATH_SUFFIXES MyGUI MYGUI)
-        FIND_LIBRARY(MYGUI_LIBRARIES mygui PATHS /usr/lib /usr/local/lib)
-        SET(MYGUI_PLATFORM_LIBRARIES "MyGUI.OgrePlatform")
-        SET(MYGUI_LIB_DIR ${MYGUI_LIBRARIES})
-        STRING(REGEX REPLACE "(.*)/.*" "\\1" MYGUI_LIB_DIR "${MYGUI_LIB_DIR}")
-        STRING(REGEX REPLACE ".*/" "" MYGUI_LIBRARIES "${MYGUI_LIBRARIES}")
-    ENDIF (MYGUI_INCLUDE_DIRS)
+	IF(MYGUI_STATIC)
+		PKG_SEARCH_MODULE(MYGUI MYGUIStatic MyGUIStatic)
+		IF (MYGUI_INCLUDE_DIRS)
+		    SET(MYGUI_INCLUDE_DIRS ${MYGUI_INCLUDE_DIRS})
+		    SET(MYGUI_LIB_DIR ${MYGUI_LIBDIR})
+		    SET(MYGUI_LIBRARIES ${MYGUI_LIBRARIES} CACHE STRING "")
+		    SET(MYGUI_PLATFORM_LIBRARIES "MyGUI.OgrePlatform")
+		ELSE (MYGUI_INCLUDE_DIRS)
+		    FIND_PATH(MYGUI_INCLUDE_DIRS MyGUI.h PATHS /usr/local/include /usr/include PATH_SUFFIXES MyGUI MYGUI)
+		    FIND_LIBRARY(MYGUI_LIBRARIES myguistatic PATHS /usr/lib /usr/local/lib)
+		    SET(MYGUI_PLATFORM_LIBRARIES "MyGUI.OgrePlatform")
+		    SET(MYGUI_LIB_DIR ${MYGUI_LIBRARIES})
+		    STRING(REGEX REPLACE "(.*)/.*" "\\1" MYGUI_LIB_DIR "${MYGUI_LIB_DIR}")
+		    STRING(REGEX REPLACE ".*/" "" MYGUI_LIBRARIES "${MYGUI_LIBRARIES}")
+		ENDIF (MYGUI_INCLUDE_DIRS)
+	ELSE(MYGUI_STATIC)
+		PKG_SEARCH_MODULE(MYGUI MYGUI MyGUI)
+		IF (MYGUI_INCLUDE_DIRS)
+		    SET(MYGUI_INCLUDE_DIRS ${MYGUI_INCLUDE_DIRS})
+		    SET(MYGUI_LIB_DIR ${MYGUI_LIBDIR})
+		    SET(MYGUI_LIBRARIES ${MYGUI_LIBRARIES} CACHE STRING "")
+		    SET(MYGUI_PLATFORM_LIBRARIES "MyGUI.OgrePlatform")
+		ELSE (MYGUI_INCLUDE_DIRS)
+		    FIND_PATH(MYGUI_INCLUDE_DIRS MyGUI.h PATHS /usr/local/include /usr/include PATH_SUFFIXES MyGUI MYGUI)
+		    FIND_LIBRARY(MYGUI_LIBRARIES mygui PATHS /usr/lib /usr/local/lib)
+		    SET(MYGUI_PLATFORM_LIBRARIES "MyGUI.OgrePlatform")
+		    SET(MYGUI_LIB_DIR ${MYGUI_LIBRARIES})
+		    STRING(REGEX REPLACE "(.*)/.*" "\\1" MYGUI_LIB_DIR "${MYGUI_LIB_DIR}")
+		    STRING(REGEX REPLACE ".*/" "" MYGUI_LIBRARIES "${MYGUI_LIBRARIES}")
+		ENDIF (MYGUI_INCLUDE_DIRS)
+	ENDIF(MYGUI_STATIC)
 ENDIF (WIN32)
 
 #Do some preparation