Skip to content

Commit

Permalink
core::path functions can now use boost.filesystem (portable library).
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfmaster committed Dec 7, 2013
1 parent eeae8d3 commit 8728865
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ set(FFMPEG_LIBRARIES "${FFMPEG_LIBRARIES};/usr/lib/libswscale.so")
include(CheckIncludeFiles)
check_include_files("sys/types.h;sys/stat.h" HAVE_SYSSTAT_H)
check_include_files("dirent.h" HAVE_DIRENT_H)

find_package(Boost COMPONENTS filesystem)
if(Boost_FILESYSTEM_FOUND)
set(HAVE_BOOST_FILESYSTEM 1)
else()
set(HAVE_BOOST_FILESYSTEM 0)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#cmakedefine HAVE_SYSSTAT_H
#cmakedefine HAVE_DIRENT_H
#cmakedefine HAVE_BOOST_FILESYSTEM

#endif//DEF_CONFIG

1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable(${exe}
target_link_libraries(
${exe}
${Boost_REGEX_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDLMIXER_LIBRARY}
Expand Down
34 changes: 30 additions & 4 deletions src/core/pathParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
#ifdef HAVE_SYSSTAT_H
# include <sys/types.h>
# include <sys/stat.h>
#elif defined(HAVE_BOOST_FILESYSTEM)
# include <boost/filesystem/path.hpp>
# include <boost/filesystem/operations.hpp>
# include <fstream>
#else
# error "sys/stat.h is needed."
#endif

#ifdef HAVE_DIRENT_H
# include <dirent.h>
#elif defined(HAVE_BOOST_FILESYSTEM)
# include <boost/filesystem/path.hpp>
# include <boost/filesystem/operations.hpp>
#else
# error "dirent.h is needed."
#endif
Expand Down Expand Up @@ -157,14 +164,28 @@ namespace core
return Type::Socket;
else
return Type::Unknown;
#endif//HAVE_SYSSTAT_H

#elif defined(HAVE_BOOST_FILESYSTEM)
/** @todo Handle sockets. */
boost::filesystem::path path(p);
if(!boost::filesystem::exists(path))
return Type::Unexistant;
else if(boost::filesystem::is_directory(path))
return Type::Dir;
else {
std::fstream fs(p);
if(fs)
return Type::Reg;
else
return Type::Unknown;
}
#endif
}

std::vector<std::string> dirContents(const std::string& dir)
{
#ifdef HAVE_DIRENT_H
std::vector<std::string> contents;

#ifdef HAVE_DIRENT_H
DIR* d = opendir(dir.c_str());
if(d == NULL)
return contents;
Expand All @@ -177,8 +198,13 @@ namespace core
}

closedir(d);

#elif defined(HAVE_BOOST_FILESYSTEM)
boost::filesystem::path p(dir);
for(boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it)
contents.push_back(it->string());
#endif
return contents;
#endif//HAVE_DIRENT_H
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/pathParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ namespace core
Unknown, /**< @brief Other */
Unexistant /**< @brief The path does not exists */
};
/** @brief Indicate the type of the path.
* @todo Only works under Linux for now, find a more portable implementation.
*/
/** @brief Indicate the type of the path. */
Type type(const std::string& p);

/** @brief List a directory contents.
Expand Down
2 changes: 1 addition & 1 deletion tests/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ link_directories(${DEMO_BINARY_DIR}/tests/audio)

# Each test here
add_executable(audio-test audio-test.cpp)
target_link_libraries(audio-test libaudio libcore libgraphics ${SDLMIXER_LIBRARY} libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_REGEX_LIBRARY})
target_link_libraries(audio-test libaudio libcore libgraphics ${SDLMIXER_LIBRARY} libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_REGEX_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})

6 changes: 3 additions & 3 deletions tests/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ link_directories(${DEMO_BINARY_DIR}/tests/core)

# Each test here
add_executable(fakefs-test fakefs-test.cpp)
target_link_libraries(fakefs-test libcore ${Boost_REGEX_LIBRARY})
target_link_libraries(fakefs-test libcore ${Boost_REGEX_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})
add_executable(pathParser-test pathParser-test.cpp)
target_link_libraries(pathParser-test libcore)
target_link_libraries(pathParser-test libcore ${Boost_FILESYSTEM_LIBRARY})
add_executable(systemTime-test systemTime-test.cpp)
target_link_libraries(systemTime-test libcore)
add_executable(logger-test logger-test.cpp)
target_link_libraries(logger-test libcore)
add_executable(config-test config-test.cpp)
target_link_libraries(config-test libcore ${Boost_REGEX_LIBRARY})
target_link_libraries(config-test libcore ${Boost_REGEX_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})


4 changes: 2 additions & 2 deletions tests/events/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ link_directories(${DEMO_BINARY_DIR}/tests/core)

# Each test here
add_executable(events-test events-test.cpp)
target_link_libraries(events-test libevents libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES})
target_link_libraries(events-test libevents libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY})
add_executable(joysticks-test joysticks-test.cpp)
target_link_libraries(joysticks-test libevents libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES})
target_link_libraries(joysticks-test libevents libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY})

2 changes: 1 addition & 1 deletion tests/gameplay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ link_directories(${DEMO_BINARY_DIR}/tests/gameplay)

# Each test here
add_executable(save-test save-test.cpp)
target_link_libraries(save-test libgameplay libcore ${Boost_REGEX_LIBRARY})
target_link_libraries(save-test libgameplay libcore ${Boost_REGEX_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})


4 changes: 2 additions & 2 deletions tests/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ link_directories(${DEMO_BINARY_DIR}/tests/graphics)

# Each test here
add_executable(graphics-test graphics-test.cpp)
target_link_libraries(graphics-test libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES})
target_link_libraries(graphics-test libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY})
add_executable(movie-test movie-test.cpp)
target_link_libraries(movie-test libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES})
target_link_libraries(movie-test libgraphics libcore libgeometry ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY})
add_executable(color-test color-test.cpp)
target_link_libraries(color-test libgraphics ${SDL2_LIBRARIES})

Expand Down
4 changes: 2 additions & 2 deletions tests/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ link_directories(${DEMO_BINARY_DIR}/tests/lua)
add_executable(script-test script-test.cpp)
target_link_libraries(script-test libcore liblua liblua5.2)
add_executable(saveexposure-test saveexposure-test.cpp)
target_link_libraries(saveexposure-test libgameplay libcore liblua liblua5.2 ${Boost_REGEX_LIBRARY})
target_link_libraries(saveexposure-test libgameplay libcore liblua liblua5.2 ${Boost_REGEX_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})
add_executable(graphicsexposure-test graphicsexposure-test.cpp)
target_link_libraries(graphicsexposure-test libevents libgraphics libgeometry libcore liblua liblua5.2 ${Boost_REGEX_LIBRARY} ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES})
target_link_libraries(graphicsexposure-test libevents libgraphics libgeometry libcore liblua liblua5.2 ${Boost_REGEX_LIBRARY} ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${FFMPEG_LIBRARIES} ${GLEW_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY})


1 comment on commit 8728865

@dwarfmaster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The program should now compile under Windows and MacOS.

Please sign in to comment.