From ad1e9e70782a146bffe036e7eaf4ef07501e4623 Mon Sep 17 00:00:00 2001 From: Ardekantur Date: Fri, 4 Jun 2010 21:44:05 -0400 Subject: [PATCH] boost::filesystem cross-platform config file check * introduces the use of the Boost.System and Boost.Filesystem libraries, which must be built and linked to rather than just compiled into OpenMW. May be a pain in the neck to get working on other platforms, but once it works, we have all of Boost to work with. --- CMakeLists.txt | 3 ++- README.md | 8 ++++---- tools/fileops.cpp | 42 +++--------------------------------------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbe009090..7c879a755 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,10 +23,11 @@ endif (WIN32) # Dependencies find_package(OGRE REQUIRED) -find_package(Boost REQUIRED) +find_package(Boost REQUIRED COMPONENTS system filesystem) include_directories("." ${OGRE_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR}) link_directories(${Boost_LIBRARY_DIRS} ${OGRE_LIB_DIR}) # Main executable add_executable(openmw ${BSA} ${TOOLS} ${OGRE} ${GAME}) target_link_libraries(openmw ${OGRE_LIBRARIES}) +target_link_libraries(openmw ${Boost_LIBRARIES}) diff --git a/README.md b/README.md index 68a66bacc..f287eae52 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ Getting OpenMW Working 1. Clone this repository. 2. Install `bjam` through MacPorts. 3. Download [boost][] 1.43 and install it with the following command: - - $ mkdir build && sudo bjam --build-dir=build --layout=versioned --toolset=darwin --architecture=combined --address-model=32 --link=shared,static install + + $ mkdir build && sudo bjam --build-dir=build --layout=versioned --toolset=darwin architecture=i386 address-model=32 --link=shared,static install 4. Download [Ogre][] 1.7.1 and build and Xcode project with CMake: @@ -28,10 +28,10 @@ Getting OpenMW Working 6. Generate the Makefile for OpenMW as follows: $ mkdir build && cd build && BOOST_INCLUDEDIR=/usr/local/include/boost-1_43 BOOST_LIBRARYDIR=/usr/local/lib CMAKE_OSX_ARCHITECTURES=i386 cmake .. - + 7. Move your Morrowind `Data Files` directory into `build`, renamed as `data`. [boost]: http://www.boost.org [Ogre]: http://www.ogre3d.org [official website]: http://openmw.com -[Will Thimbleby's Ogre Framework]: http://www.thimbleby.net/ogre/ \ No newline at end of file +[Will Thimbleby's Ogre Framework]: http://www.thimbleby.net/ogre/ diff --git a/tools/fileops.cpp b/tools/fileops.cpp index 0e8115662..bb859836b 100644 --- a/tools/fileops.cpp +++ b/tools/fileops.cpp @@ -1,44 +1,8 @@ #include "fileops.hpp" - -// Windows-specific implementation (NOT TESTED) -#ifdef _WIN32 - -#include - -bool isFile(const char *name) -{ - unsigned int stat = GetFileAttributes(name); - return (stat != 0xFFFFFFFF && - (stat & FILE_ATTRIBUTE_DIRECTORY) == 0); -} -#elif __linux__ // Linux implementations - -#include -#include +#include bool isFile(const char *name) { - // Does the file exist? - if(access(name,0) != 0) - return false; - - struct stat st; - if(stat(name, &st)) return false; - return S_ISREG(st.st_mode); -} - -#elif __APPLE__ // Darwin implementations -#include -#include - -bool isFile(const char *name) -{ - // Does the file exist? - if(access(name,0) != 0) - return false; - - struct stat st; - if(stat(name, &st)) return false; - return S_ISREG(st.st_mode); + boost::filesystem::path cfg_file_path(name); + return boost::filesystem::exists(cfg_file_path); } -#endif