http://www.cnitblog.com/buf/archive/2011/04/20/73380.html
从http://code.google.com/p/ogre-paged/downloads/list下载源码包,解压后发现没有.sln和.vcproj,需要用cmake进行配置来生成这些文件。
按照机器上OGRE相关include和lib目录的实际位置,修改CMakeDependenciesConfig.txt文件中Ogre_INCLUDE_DIRS、Ogre_LIBRARY_DIRS等变量的定义,我的设置是这样:
IF
(WIN32)
set (Ogre_INCLUDE_DIRS " E:/Ogre/project/OGRE_1.7.2/include/OGRE " CACHE PATH " The ogre include path to use " )
set (Ogre_LIBRARY_DIRS " E:/Ogre/project/OGRE_1.7.2/lib " CACHE PATH " The ogre lib path to use " )
set (Ogre_LIBRARIES " OgreMain " CACHE STRING " The ogre lib to link against " )
set (Ois_INCLUDE_DIRS " E:/Ogre/project/OGRE_1.7.2/include/ois " CACHE PATH " The OIS include path to use " )
set (Ois_LIBRARY_DIRS " E:/Ogre/project/OGRE_1.7.2/lib " CACHE PATH " The OIS lib path to use " )
set (Ois_LIBRARIES " ois " CACHE STRING " The ogre lib to link against " )
# add includes to check directories
set (CMAKE_REQUIRED_INCLUDES ${Ogre_INCLUDE_DIRS} ${Ois_INCLUDE_DIRS})
# check for libs and include files we want to use
CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_INCLUDES)
if ( NOT HAVE_WINDOWS_INCLUDES)
message(FATAL_ERROR " could not find the windows platform includes. Please install them. " )
endif()
set (BOOST_PATH " E:/Ogre/project/OGRE_1.7.2/boost_1_42 " CACHE PATH " The BOOST root path to use " )
include_directories(${BOOST_PATH})
link_directories (${BOOST_PATH} / lib)
ELSEIF (UNIX)
find_package(PkgConfig)
PKG_CHECK_MODULES (Ogre OGRE REQUIRED)
PKG_CHECK_MODULES (Ois OIS REQUIRED)
# add includes to check directories
set (CMAKE_REQUIRED_INCLUDES ${Ogre_INCLUDE_DIRS} ${Ois_INCLUDE_DIRS})
# check for libs and include files we want to use
# check below not working!?
#CHECK_LIBRARY_EXISTS(libOgreMain.so loadPlugins "" HAVE_OGRE_LIBS)
# if ( NOT HAVE_OGRE_LIBS)
# message(FATAL_ERROR " could not link against Ogre, please check of you have the required libraries installed " )
#endif()
ENDIF(WIN32)
IF ( NOT WIN32)
# XXX TODO: fix the checks for windows!
# add this so the checks work
set (CMAKE_REQUIRED_INCLUDES ${Ogre_INCLUDE_DIRS} ${Ois_INCLUDE_DIRS})
# cross platform checks
# check for libs and include files we want to use
CHECK_INCLUDE_FILE_CXX(OgrePrerequisites.h HAVE_OGRE_INCLUDES)
if ( NOT HAVE_OGRE_INCLUDES)
message( " could not find the Ogre includes. Please install them. " )
endif()
CHECK_INCLUDE_FILE_CXX(OIS / OIS.h HAVE_OIS_DIR_INCLUDES)
if (HAVE_OIS_DIR_INCLUDES)
set (OIS_INCLUDE " OIS/OIS.h " )
endif()
CHECK_INCLUDE_FILE_CXX(OIS.h HAVE_OIS_INCLUDES)
if (HAVE_OIS_INCLUDES)
set (OIS_INCLUDE " OIS.h " )
endif()
if ( NOT HAVE_OIS_DIR_INCLUDES AND NOT HAVE_OIS_INCLUDES)
message( " could not find the OIS includes. Please install them. " )
endif()
if (HAVE_OIS_DIR_INCLUDES AND NOT HAVE_OIS_INCLUDES)
set (OIS_USING_DIR TRUE )
else ()
set (OIS_USING_DIR FALSE )
endif()
endif()
set (Ogre_INCLUDE_DIRS " E:/Ogre/project/OGRE_1.7.2/include/OGRE " CACHE PATH " The ogre include path to use " )
set (Ogre_LIBRARY_DIRS " E:/Ogre/project/OGRE_1.7.2/lib " CACHE PATH " The ogre lib path to use " )
set (Ogre_LIBRARIES " OgreMain " CACHE STRING " The ogre lib to link against " )
set (Ois_INCLUDE_DIRS " E:/Ogre/project/OGRE_1.7.2/include/ois " CACHE PATH " The OIS include path to use " )
set (Ois_LIBRARY_DIRS " E:/Ogre/project/OGRE_1.7.2/lib " CACHE PATH " The OIS lib path to use " )
set (Ois_LIBRARIES " ois " CACHE STRING " The ogre lib to link against " )
# add includes to check directories
set (CMAKE_REQUIRED_INCLUDES ${Ogre_INCLUDE_DIRS} ${Ois_INCLUDE_DIRS})
# check for libs and include files we want to use
CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_INCLUDES)
if ( NOT HAVE_WINDOWS_INCLUDES)
message(FATAL_ERROR " could not find the windows platform includes. Please install them. " )
endif()
set (BOOST_PATH " E:/Ogre/project/OGRE_1.7.2/boost_1_42 " CACHE PATH " The BOOST root path to use " )
include_directories(${BOOST_PATH})
link_directories (${BOOST_PATH} / lib)
ELSEIF (UNIX)
find_package(PkgConfig)
PKG_CHECK_MODULES (Ogre OGRE REQUIRED)
PKG_CHECK_MODULES (Ois OIS REQUIRED)
# add includes to check directories
set (CMAKE_REQUIRED_INCLUDES ${Ogre_INCLUDE_DIRS} ${Ois_INCLUDE_DIRS})
# check for libs and include files we want to use
# check below not working!?
#CHECK_LIBRARY_EXISTS(libOgreMain.so loadPlugins "" HAVE_OGRE_LIBS)
# if ( NOT HAVE_OGRE_LIBS)
# message(FATAL_ERROR " could not link against Ogre, please check of you have the required libraries installed " )
#endif()
ENDIF(WIN32)
IF ( NOT WIN32)
# XXX TODO: fix the checks for windows!
# add this so the checks work
set (CMAKE_REQUIRED_INCLUDES ${Ogre_INCLUDE_DIRS} ${Ois_INCLUDE_DIRS})
# cross platform checks
# check for libs and include files we want to use
CHECK_INCLUDE_FILE_CXX(OgrePrerequisites.h HAVE_OGRE_INCLUDES)
if ( NOT HAVE_OGRE_INCLUDES)
message( " could not find the Ogre includes. Please install them. " )
endif()
CHECK_INCLUDE_FILE_CXX(OIS / OIS.h HAVE_OIS_DIR_INCLUDES)
if (HAVE_OIS_DIR_INCLUDES)
set (OIS_INCLUDE " OIS/OIS.h " )
endif()
CHECK_INCLUDE_FILE_CXX(OIS.h HAVE_OIS_INCLUDES)
if (HAVE_OIS_INCLUDES)
set (OIS_INCLUDE " OIS.h " )
endif()
if ( NOT HAVE_OIS_DIR_INCLUDES AND NOT HAVE_OIS_INCLUDES)
message( " could not find the OIS includes. Please install them. " )
endif()
if (HAVE_OIS_DIR_INCLUDES AND NOT HAVE_OIS_INCLUDES)
set (OIS_USING_DIR TRUE )
else ()
set (OIS_USING_DIR FALSE )
endif()
endif()
需要注意的是要把路径名中的'\'替换为'/',否则会被cmake作为转义符处理。
改完以后用VS2005打开.sln就可以编译了。一个小小的问题是Ogre_LIBRARIES和Ois_LIBRARIES没有按照Debug和Release分别定义,因此编译Debug版本的时候还需要改一下Example工程的link选项。
效果还不错,速度很快。
不过,我的机器(Windows XP SP3 / Ogre 1.7.2 / Galaxy GTS450)上启动不了Example9/10,会出现runtime error。估计可能是某些依赖库的版本问题,尚未解决。