Patch to find Ogre under linux with OGRE_HOME flag

badfish

05-05-2011 14:37:38

Hi,

I have a minor patch for the cmake build system. Its against a recent snapshot from the trunk in svn (MyGUI 3.2).

I build under linux, with a custom install root for my dependencies, i.e.project-dir/thirdparty/install, and the build system does not pick up this when looking for Ogre.

Modification makes sure OGRE_HOME is searched as first preference when passed to the build system. If passed, this location will be searched using find_package. CMake was unable to find Ogre without this change.

I am unable to test on windows/apple, hence the linux only cmake if(). Patch below, interested in feedback (in case i broke something)! Thanks


Index: CMake/Packages/FindOGRE_Old.cmake
===================================================================
--- CMake/Packages/FindOGRE_Old.cmake (revision 4273)
+++ CMake/Packages/FindOGRE_Old.cmake (working copy)
@@ -28,23 +28,37 @@
if(WIN32 OR APPLE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OGRE_SOURCE}/CMake ${OGRE_SOURCE}/CMake/Packages)
else()
- set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /usr/local/lib/OGRE/cmake)
+ if (OGRE_HOME)
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OGRE_HOME}/lib/OGRE/cmake)
+ else ()
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /usr/local/lib/OGRE/cmake)
+ endif ()
endif()
-
- IF (NOT OGRE_SOURCE)
- set(OGRE_SOURCE "" CACHE PATH "Path to Ogre sources (set it if you don't have OGRE_HOME or OGRE_SRC environment variables)")
- ENDIF ()
-
- if (NOT OGRE_BUILD)
- set(OGRE_BUILD ${OGRE_SOURCE} CACHE PATH "Path to Ogre build directory (same as OGRE_SOURCE by default)")
+
+ # if user specified OGRE_HOME, try finding Ogre here first
+ if (OGRE_HOME AND NOT WIN32 AND NOT APPLE)
+ MESSAGE(STATUS "Using OGRE from OGRE_HOME path")
+ find_package(OGRE REQUIRED)
+
+ if (OGRE_FOUND)
+ MESSAGE(STATUS "OGRE was found using OGRE_HOME at " ${OGRE_HOME})
+ endif ()
+ else ()
+ IF (NOT OGRE_SOURCE)
+ set(OGRE_SOURCE "" CACHE PATH "Path to Ogre sources (set it if you don't have OGRE_HOME or OGRE_SRC environment variables)")
+ ENDIF ()
+
+ if (NOT OGRE_BUILD)
+ set(OGRE_BUILD ${OGRE_SOURCE} CACHE PATH "Path to Ogre build directory (same as OGRE_SOURCE by default)")
+ endif ()
+
+ if (EXISTS ${OGRE_SOURCE}/CMake)
+ MESSAGE(STATUS "Original FindOGRE.cmake found, trying to use it")
+ set (OGRE_HOME ${OGRE_SOURCE})
+ FIND_PACKAGE(OGRE)
+ endif()
endif ()

- if (EXISTS ${OGRE_SOURCE}/CMake)
- MESSAGE(STATUS "Original FindOGRE.cmake found, trying to use it")
- set (OGRE_HOME ${OGRE_SOURCE})
- FIND_PACKAGE(OGRE)
- endif()
-
if (OGRE_FOUND)
MESSAGE(STATUS "Ogre was found with it's own CMake script")