From c4a6fa56eacb0f591b97d6c74e12ff2850c3366c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 6 Jun 2010 12:56:46 +0200 Subject: [PATCH 1/4] cmake modifications for out of source build --- CMakeLists.txt | 24 ++++++- cmake/FindOIS.cmake | 71 ++++++++++++++++++ cmake/FindPkgMacros.cmake | 147 ++++++++++++++++++++++++++++++++++++++ game/main.cpp | 10 +-- 4 files changed, 243 insertions(+), 9 deletions(-) create mode 100644 cmake/FindOIS.cmake create mode 100644 cmake/FindPkgMacros.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f9d349d1b..4c7cf27db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,11 +24,31 @@ set(PLATFORM_INCLUDE_DIR "") endif (WIN32) # Dependencies + find_package(OGRE REQUIRED) +find_package(OIS REQUIRED) find_package(Boost REQUIRED) -include_directories("." ${OGRE_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR}) + +include_directories("." + ${OGRE_INCLUDE_DIR} ${OIS_INCLUDE_DIR} ${Boost_INCLUDE_DIR} + ${PLATFORM_INCLUDE_DIR}) + link_directories(${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR}) +# Specify build paths + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OpenMW_BINARY_DIR}/bin") + +# Other files + +if (WIN32) +configure_file(${OpenMW_SOURCE_DIR}/plugins.cfg.win32 + "${OpenMW_BINARY_DIR}/bin/plugins.cfg" COPY_ONLY) +else (WIN32) +configure_file(${OpenMW_SOURCE_DIR}/plugins.cfg.linux + "${OpenMW_BINARY_DIR}/bin/plugins.cfg" COPY_ONLY) +endif (WIN32) + # Main executable add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${INPUT} ${GAME} ${GAMEREND}) -target_link_libraries(openmw ${OGRE_LIBRARIES}) +target_link_libraries(openmw ${OGRE_LIBRARIES} ${OIS_LIBRARIES}) diff --git a/cmake/FindOIS.cmake b/cmake/FindOIS.cmake new file mode 100644 index 000000000..eea7a6839 --- /dev/null +++ b/cmake/FindOIS.cmake @@ -0,0 +1,71 @@ +#------------------------------------------------------------------- +# This file is part of the CMake build system for OGRE +# (Object-oriented Graphics Rendering Engine) +# For the latest info, see http://www.ogre3d.org/ +# +# The contents of this file are placed in the public domain. Feel +# free to make use of it in any way you like. +#------------------------------------------------------------------- + +# - Try to find OIS +# Once done, this will define +# +# OIS_FOUND - system has OIS +# OIS_INCLUDE_DIRS - the OIS include directories +# OIS_LIBRARIES - link these to use OIS + +include(FindPkgMacros) +findpkg_begin(OIS) + +# Get path, convert backslashes as ${ENV_${var}} +getenv_path(OIS_HOME) +getenv_path(OGRE_SDK) +getenv_path(OGRE_HOME) +getenv_path(OGRE_SOURCE) + +# construct search paths +set(OIS_PREFIX_PATH ${OIS_HOME} ${ENV_OIS_HOME} + ${OGRE_SOURCE}/iPhoneDependencies ${ENV_OGRE_SOURCE}/iPhoneDependencies + ${OGRE_SOURCE}/Dependencies ${ENV_OGRE_SOURCE}/Dependencies + ${OGRE_SDK} ${ENV_OGRE_SDK} + ${OGRE_HOME} ${ENV_OGRE_HOME}) +create_search_paths(OIS) +# redo search if prefix path changed +clear_if_changed(OIS_PREFIX_PATH + OIS_LIBRARY_FWK + OIS_LIBRARY_REL + OIS_LIBRARY_DBG + OIS_INCLUDE_DIR +) + +set(OIS_LIBRARY_NAMES OIS) +get_debug_names(OIS_LIBRARY_NAMES) + +use_pkgconfig(OIS_PKGC OIS) + +# For OIS, prefer static library over framework (important when referencing OIS source build) +set(CMAKE_FIND_FRAMEWORK "LAST") + +findpkg_framework(OIS) +if (OIS_HOME) + # OIS uses the 'includes' path for its headers in the source release, not 'include' + set(OIS_INC_SEARCH_PATH ${OIS_INC_SEARCH_PATH} ${OIS_HOME}/includes) +endif() +if (APPLE AND OIS_HOME) + # OIS source build on Mac stores libs in a different location + # Also this is for static build + set(OIS_LIB_SEARCH_PATH ${OIS_LIB_SEARCH_PATH} ${OIS_HOME}/Mac/XCode-2.2/build) +endif() +find_path(OIS_INCLUDE_DIR NAMES OIS.h HINTS ${OIS_INC_SEARCH_PATH} ${OIS_PKGC_INCLUDE_DIRS} PATH_SUFFIXES OIS) +find_library(OIS_LIBRARY_REL NAMES ${OIS_LIBRARY_NAMES} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" release relwithdebinfo minsizerel) +find_library(OIS_LIBRARY_DBG NAMES ${OIS_LIBRARY_NAMES_DBG} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" debug) +make_library_set(OIS_LIBRARY) + + +findpkg_finish(OIS) + +# add parent of OIS folder to support OIS/OIS.h +add_parent_dir(OIS_INCLUDE_DIRS OIS_INCLUDE_DIR) + +# Reset framework finding +set(CMAKE_FIND_FRAMEWORK "FIRST") diff --git a/cmake/FindPkgMacros.cmake b/cmake/FindPkgMacros.cmake new file mode 100644 index 000000000..da3303ac5 --- /dev/null +++ b/cmake/FindPkgMacros.cmake @@ -0,0 +1,147 @@ +#------------------------------------------------------------------- +# This file is part of the CMake build system for OGRE +# (Object-oriented Graphics Rendering Engine) +# For the latest info, see http://www.ogre3d.org/ +# +# The contents of this file are placed in the public domain. Feel +# free to make use of it in any way you like. +#------------------------------------------------------------------- + +################################################################## +# Provides some common functionality for the FindPackage modules +################################################################## + +# Begin processing of package +macro(findpkg_begin PREFIX) + if (NOT ${PREFIX}_FIND_QUIETLY) + message(STATUS "Looking for ${PREFIX}...") + endif () +endmacro(findpkg_begin) + +# Display a status message unless FIND_QUIETLY is set +macro(pkg_message PREFIX) + if (NOT ${PREFIX}_FIND_QUIETLY) + message(STATUS ${ARGN}) + endif () +endmacro(pkg_message) + +# Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes +macro(getenv_path VAR) + set(ENV_${VAR} $ENV{${VAR}}) + # replace won't work if var is blank + if (ENV_${VAR}) + string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} ) + endif () +endmacro(getenv_path) + +# Construct search paths for includes and libraries from a PREFIX_PATH +macro(create_search_paths PREFIX) + foreach(dir ${${PREFIX}_PREFIX_PATH}) + set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH} + ${dir}/include ${dir}/Include ${dir}/include/${PREFIX} ${dir}/Headers) + set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH} + ${dir}/lib ${dir}/Lib ${dir}/lib/${PREFIX} ${dir}/Libs) + set(${PREFIX}_BIN_SEARCH_PATH ${${PREFIX}_BIN_SEARCH_PATH} + ${dir}/bin) + endforeach(dir) + set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH}) +endmacro(create_search_paths) + +# clear cache variables if a certain variable changed +macro(clear_if_changed TESTVAR) + # test against internal check variable + if (NOT "${${TESTVAR}}" STREQUAL "${${TESTVAR}_INT_CHECK}") + message(STATUS "${TESTVAR} changed.") + foreach(var ${ARGN}) + set(${var} "NOTFOUND" CACHE STRING "x" FORCE) + endforeach(var) + endif () + set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE) +endmacro(clear_if_changed) + +# Try to get some hints from pkg-config, if available +macro(use_pkgconfig PREFIX PKGNAME) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif () +endmacro (use_pkgconfig) + +# Couple a set of release AND debug libraries (or frameworks) +macro(make_library_set PREFIX) + if (${PREFIX}_FWK) + set(${PREFIX} ${${PREFIX}_FWK}) + elseif (${PREFIX}_REL AND ${PREFIX}_DBG) + set(${PREFIX} optimized ${${PREFIX}_REL} debug ${${PREFIX}_DBG}) + elseif (${PREFIX}_REL) + set(${PREFIX} ${${PREFIX}_REL}) + elseif (${PREFIX}_DBG) + set(${PREFIX} ${${PREFIX}_DBG}) + endif () +endmacro(make_library_set) + +# Generate debug names from given release names +macro(get_debug_names PREFIX) + foreach(i ${${PREFIX}}) + set(${PREFIX}_DBG ${${PREFIX}_DBG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i}) + endforeach(i) +endmacro(get_debug_names) + +# Add the parent dir from DIR to VAR +macro(add_parent_dir VAR DIR) + get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE) + set(${VAR} ${${VAR}} ${${DIR}_TEMP}) +endmacro(add_parent_dir) + +# Do the final processing for the package find. +macro(findpkg_finish PREFIX) + # skip if already processed during this run + if (NOT ${PREFIX}_FOUND) + if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY) + set(${PREFIX}_FOUND TRUE) + set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR}) + set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY}) + if (NOT ${PREFIX}_FIND_QUIETLY) + message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}") + endif () + else () + if (NOT ${PREFIX}_FIND_QUIETLY) + message(STATUS "Could not locate ${PREFIX}") + endif () + if (${PREFIX}_FIND_REQUIRED) + message(FATAL_ERROR "Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake.") + endif () + endif () + + mark_as_advanced(${PREFIX}_INCLUDE_DIR ${PREFIX}_LIBRARY ${PREFIX}_LIBRARY_REL ${PREFIX}_LIBRARY_DBG ${PREFIX}_LIBRARY_FWK) + endif () +endmacro(findpkg_finish) + + +# Slightly customised framework finder +MACRO(findpkg_framework fwk) + IF(APPLE) + SET(${fwk}_FRAMEWORK_PATH + ${${fwk}_FRAMEWORK_SEARCH_PATH} + ${CMAKE_FRAMEWORK_PATH} + ~/Library/Frameworks + /Library/Frameworks + /System/Library/Frameworks + /Network/Library/Frameworks + /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/ + ${CMAKE_CURRENT_SOURCE_DIR}/../lib/Release + ${CMAKE_CURRENT_SOURCE_DIR}/../lib/Debug + ) + FOREACH(dir ${${fwk}_FRAMEWORK_PATH}) + SET(fwkpath ${dir}/${fwk}.framework) + IF(EXISTS ${fwkpath}) + SET(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES} + ${fwkpath}/Headers ${fwkpath}/PrivateHeaders) + SET(${fwk}_FRAMEWORK_PATH ${dir}) + if (NOT ${fwk}_LIBRARY_FWK) + SET(${fwk}_LIBRARY_FWK "-framework ${fwk}") + endif () + ENDIF(EXISTS ${fwkpath}) + ENDFOREACH(dir) + ENDIF(APPLE) +ENDMACRO(findpkg_framework) diff --git a/game/main.cpp b/game/main.cpp index 81f0f2201..f46a2d2fe 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -12,14 +12,10 @@ using namespace std; void maintest() { - const char* esmFile = "data/Morrowind.esm"; - const char* bsaFile = "data/Morrowind.bsa"; + const char* esmFile = "../data/Morrowind.esm"; + const char* bsaFile = "../data/Morrowind.bsa"; -#ifdef _WIN32 - const char* plugCfg = "plugins.cfg.win32"; -#else - const char* plugCfg = "plugins.cfg.linux"; -#endif + const char* plugCfg = "plugins.cfg"; cout << "Hello, fellow traveler!\n"; From e973270f9b7a134f8f251ee7d0f5288d6d62336c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 6 Jun 2010 13:04:23 +0200 Subject: [PATCH 2/4] fixed minor bug in previous commit; more clean up --- CMakeLists.txt | 8 ++++---- plugins.cfg.linux => files/plugins.cfg.linux | 0 plugins.cfg.win32 => files/plugins.cfg.win32 | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename plugins.cfg.linux => files/plugins.cfg.linux (100%) rename plugins.cfg.win32 => files/plugins.cfg.win32 (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c7cf27db..b2b31239f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,11 +42,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OpenMW_BINARY_DIR}/bin") # Other files if (WIN32) -configure_file(${OpenMW_SOURCE_DIR}/plugins.cfg.win32 - "${OpenMW_BINARY_DIR}/bin/plugins.cfg" COPY_ONLY) +configure_file(${OpenMW_SOURCE_DIR}/files/plugins.cfg.win32 + "${OpenMW_BINARY_DIR}/bin/plugins.cfg" COPYONLY) else (WIN32) -configure_file(${OpenMW_SOURCE_DIR}/plugins.cfg.linux - "${OpenMW_BINARY_DIR}/bin/plugins.cfg" COPY_ONLY) +configure_file(${OpenMW_SOURCE_DIR}/files/plugins.cfg.linux + "${OpenMW_BINARY_DIR}/bin/plugins.cfg" COPYONLY) endif (WIN32) # Main executable diff --git a/plugins.cfg.linux b/files/plugins.cfg.linux similarity index 100% rename from plugins.cfg.linux rename to files/plugins.cfg.linux diff --git a/plugins.cfg.win32 b/files/plugins.cfg.win32 similarity index 100% rename from plugins.cfg.win32 rename to files/plugins.cfg.win32 From aa59d9244fe45f5e0d2895e97ccf647e6a32d6d4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 6 Jun 2010 13:22:37 +0200 Subject: [PATCH 3/4] listed header files, so they will show up in IDE project files (excluding mangle for now) --- CMakeLists.txt | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2b31239f..432bac45f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,14 +7,31 @@ cmake_minimum_required(VERSION 2.6) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/) # Local files + set(BSA bsa/bsa_archive.cpp bsa/bsa_file.cpp) +set(BSA_HEADER bsa/bsa_archive.hpp bsa/bsa_file.hpp) + set(NIF nif/nif_file.cpp nifogre/ogre_nif_loader.cpp) +set(NIF_HEADER nif/controlled.hpp nif/effect.hpp nif/nif_types.hpp nif/record.hpp + nif/controller.hpp nif/extra.hpp nif/node.hpp nif/record_ptr.hpp + nif/data.hpp nif/nif_file.hpp nif/property.hpp) + set(TOOLS tools/stringops.cpp tools/fileops.cpp) +set(TOOLS_HEADER tools/fileops.hpp tools/slice_array.hpp tools/stringops.hpp) + set(MANGLE_VFS mangle/vfs/servers/ogre_vfs.cpp) + set(OGRE ogre/renderer.cpp) +set(OGRE_HEADER ogre/renderer.hpp) + set(INPUT input/oismanager.cpp) +set(INPUT_HEADER input/oismanager.hpp) + set(GAME game/main.cpp game/esm_store/store.cpp game/cell_store.cpp) +set(GAME_HEADER game/cell_store.hpp game/esm_store/reclists.hpp game/esm_store/store.hpp) + set(GAMEREND game/render/mwscene.cpp) +set(GAMEREND_HEADER game/render/cell.hpp game/render/mwscene.hpp) # Platform specific if (WIN32) @@ -50,5 +67,14 @@ configure_file(${OpenMW_SOURCE_DIR}/files/plugins.cfg.linux endif (WIN32) # Main executable -add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${INPUT} ${GAME} ${GAMEREND}) + +add_executable(openmw + ${BSA} ${BSA_HEADER} + ${TOOLS} ${TOOLS_HEADER} + ${OGRE} ${OGRE_HEADER} + ${INPUT} ${INPUT_HEADER} + ${GAME} ${GAME_HEADER} + ${GAMEREND} ${GAMEREND_HEADER}) + target_link_libraries(openmw ${OGRE_LIBRARIES} ${OIS_LIBRARIES}) + From 3bcb86881c1e6b5af8c71cfb32d996885521c4e4 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 6 Jun 2010 13:36:45 +0200 Subject: [PATCH 4/4] removed Ogre.h include; replaced by individual include files and a couple of forward declarations --- game/render/mwscene.cpp | 7 +++++++ game/render/mwscene.hpp | 8 ++++++++ input/oismanager.cpp | 4 +++- ogre/renderer.cpp | 5 +++++ ogre/renderer.hpp | 7 ++++++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/game/render/mwscene.cpp b/game/render/mwscene.cpp index b916e940c..c28dea25a 100644 --- a/game/render/mwscene.cpp +++ b/game/render/mwscene.cpp @@ -2,6 +2,13 @@ #include +#include "OgreRoot.h" +#include "OgreRenderWindow.h" +#include "OgreSceneManager.h" +#include "OgreViewport.h" +#include "OgreCamera.h" +#include "OgreTextureManager.h" + using namespace Render; using namespace Ogre; diff --git a/game/render/mwscene.hpp b/game/render/mwscene.hpp index 9eaba76f7..3aff8c368 100644 --- a/game/render/mwscene.hpp +++ b/game/render/mwscene.hpp @@ -3,6 +3,14 @@ #include "ogre/renderer.hpp" +namespace Ogre +{ + class Camera; + class Viewport; + class SceneManager; + class SceneNode; +} + namespace Render { /** Class responsible for Morrowind-specific interfaces to OGRE. diff --git a/input/oismanager.cpp b/input/oismanager.cpp index 37593c29d..924c94ea3 100644 --- a/input/oismanager.cpp +++ b/input/oismanager.cpp @@ -2,12 +2,14 @@ #include #include #include +#include + +#include "OgreRenderWindow.h" using namespace Input; using namespace Ogre; using namespace OIS; -#include using namespace std; void OISManager::setup(Render::OgreRenderer *rend) diff --git a/ogre/renderer.cpp b/ogre/renderer.cpp index d43109ff2..a7998596d 100644 --- a/ogre/renderer.cpp +++ b/ogre/renderer.cpp @@ -1,5 +1,10 @@ #include "renderer.hpp" +#include "OgreRoot.h" +#include "OgreRenderWindow.h" +#include "OgreLogManager.h" +#include "OgreLog.h" + using namespace Ogre; using namespace Render; diff --git a/ogre/renderer.hpp b/ogre/renderer.hpp index 11eae2576..31937903f 100644 --- a/ogre/renderer.hpp +++ b/ogre/renderer.hpp @@ -5,9 +5,14 @@ Ogre renderer class */ -#include #include +namespace Ogre +{ + class Root; + class RenderWindow; +} + namespace Render { class OgreRenderer