Skip to content

Commit

Permalink
Improve datadir handling; fixes SuperTux#394
Browse files Browse the repository at this point in the history
  • Loading branch information
maths22 authored and tobbi committed Jul 10, 2016
1 parent 36dd8eb commit 757132a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
34 changes: 20 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ INCLUDE(ExternalProject)
## For autopackage
SET(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games/supertux2")

SET(BUILD_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
SET(BUILD_CONFIG_DATA_DIR "${CMAKE_BINARY_DIR}/data")
## Check endianess

INCLUDE(TestBigEndian)
Expand Down Expand Up @@ -288,6 +290,9 @@ SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/supertux/title_scree
PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/src/addon/addon_manager.cpp
PROPERTIES OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/version.h")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/levels/misc/menu.stl.in ${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl )

## Check platform-dependent build options

INCLUDE(ConfigureChecks)
Expand Down Expand Up @@ -546,9 +551,6 @@ ENDIF(GENERATE_WRAPPER)

#SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
IF(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
CONFIGURE_FILES(${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/data)
ENDIF(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})

## Add target for supertux binary

Expand Down Expand Up @@ -716,26 +718,30 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/credits.stxt DESTINATION ${INSTAL

INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/supertux2.appdata.xml DESTINATION "share/appdata" )

INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/data/images
${CMAKE_BINARY_DIR}/data/fonts
${CMAKE_BINARY_DIR}/data/music
${CMAKE_BINARY_DIR}/data/scripts
${CMAKE_BINARY_DIR}/data/speech
${CMAKE_BINARY_DIR}/data/sounds
${CMAKE_BINARY_DIR}/data/locale
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/images
${CMAKE_CURRENT_SOURCE_DIR}/data/fonts
${CMAKE_CURRENT_SOURCE_DIR}/data/music
${CMAKE_CURRENT_SOURCE_DIR}/data/scripts
${CMAKE_CURRENT_SOURCE_DIR}/data/speech
${CMAKE_CURRENT_SOURCE_DIR}/data/sounds
${CMAKE_CURRENT_SOURCE_DIR}/data/locale
DESTINATION ${INSTALL_SUBDIR_SHARE})

IF(CMAKE_BUILD_TYPE MATCHES Release)
INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/data/levels
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
DESTINATION ${INSTALL_SUBDIR_SHARE}
PATTERN "data/levels/test" EXCLUDE
PATTERN "data/levels/test_old" EXCLUDE
PATTERN "data/levels/incubator" EXCLUDE)
PATTERN "data/levels/incubator" EXCLUDE
PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
ELSE()
INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/data/levels
DESTINATION ${INSTALL_SUBDIR_SHARE})
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/levels
DESTINATION ${INSTALL_SUBDIR_SHARE}
PATTERN "data/levels/misc/menu.stl.in" EXCLUDE)
ENDIF()

INSTALL(FILES "${CMAKE_BINARY_DIR}/data/levels/misc/menu.stl" DESTINATION "${INSTALL_SUBDIR_SHARE}/levels/misc")

## Create config.h now that INSTALL_SUBDIR_* have been set.

configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
Expand Down
4 changes: 4 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@

#cmakedefine HAVE_LIBCURL

#define BUILD_DATA_DIR "${BUILD_DATA_DIR}"

#define BUILD_CONFIG_DATA_DIR "${BUILD_CONFIG_DATA_DIR}"

#endif /*CONFIG_H*/
20 changes: 5 additions & 15 deletions src/supertux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,13 @@ class PhysfsSubsystem
std::string basepath = basepath_c ? basepath_c : "./";
SDL_free(basepath_c);

// If we are on windows, the data directory is one directory above the binary
#ifdef WIN32
const std::array<std::string, 2> subdirs = { { "data", "../data" } };
#else
const std::array<std::string, 1> subdirs = { { "data" } };
#endif
bool found = false;
for (const std::string &subdir : subdirs)
if (FileSystem::exists(FileSystem::join(BUILD_DATA_DIR, "credits.stxt")))
{
datadir = FileSystem::join(basepath, subdir);
if (FileSystem::exists(FileSystem::join(datadir, "credits.stxt")))
{
found = true;
break;
}
datadir = BUILD_DATA_DIR;
//Add config dir for supplemental files
PHYSFS_mount(BUILD_CONFIG_DATA_DIR, NULL, 1);
}
if (!found)
else
{
// if the game is not run from the source directory, try to find
// the global install location
Expand Down

0 comments on commit 757132a

Please sign in to comment.