From ad58361e6efe5f38d8418259fddecb45f16da5fa Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Thu, 3 Jul 2014 22:08:56 -0400 Subject: [PATCH] Consider /../ as a candidate for data dir autodetection Makes it so /../ (non-Windows) or /../ (Windows) are also considered possible data directories if they contain a data/_main.cfg file. This is mostly intended to help people running cmake builds so they don't have to type out .. in the Wesnoth command line every time or use a hard link sitting on the data dir. Notice that scons people already benefited from the simpler version of this autodetection, which only considered /./ as a candidate. This has been the case since version 1.5.4 (more specifically, commit 43431bc3a79d8be4fef2c102167e5982a74aa71a). Because of this, most of the code for this feature was already in place and I only rearranged it to add some helpful annotations. --- changelog | 3 +++ src/wesnoth.cpp | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 59ce44d14c32..356ac6f41b27 100644 --- a/changelog +++ b/changelog @@ -227,6 +227,9 @@ Version 1.13.0-dev: * Fix an inefficient implementation of unit::invisible, in an effort to address slow performance problems: http://forums.wesnoth.org/viewtopic.php?f=4&t=12139&start=180#p569931 (Also see gfgtdf's commits trying to optimize the minimap loop) + * Made it so /../ (non-Windows) or /../ + (Windows) are also considered possible data directories if they contain a + data/_main.cfg file, intended to help with cmake builds. Version 1.11.11: * Add-ons server: diff --git a/src/wesnoth.cpp b/src/wesnoth.cpp index c3d54b228506..3988c11e5646 100644 --- a/src/wesnoth.cpp +++ b/src/wesnoth.cpp @@ -791,11 +791,28 @@ int main(int argc, char** argv) const time_t t = time(NULL); std::cerr << "Started on " << ctime(&t) << "\n"; - const std::string exe_dir = get_exe_dir(); - if(!exe_dir.empty() && file_exists(exe_dir + "/data/_main.cfg")) { - std::cerr << "Automatically found a possible data directory at " - << exe_dir << '\n'; - game_config::path = exe_dir; + const std::string& exe_dir = get_exe_dir(); + if(!exe_dir.empty()) { + // Try to autodetect the location of the game data dir. Note that + // the root of the source tree currently doubles as the data dir. + std::string auto_dir; + + // scons leaves the resulting binaries at the root of the source + // tree by default. + if(file_exists(exe_dir + "/data/_main.cfg")) { + auto_dir = exe_dir; + } + // cmake encourages creating a subdir at the root of the source + // tree for the build, and the resulting binaries are found in it. + else if(file_exists(exe_dir + "/../data/_main.cfg")) { + auto_dir = normalize_path(exe_dir + "/.."); + } + + if(!auto_dir.empty()) { + std::cerr << "Automatically found a possible data directory at " + << auto_dir << '\n'; + game_config::path = auto_dir; + } } const int res = do_gameloop(argc,argv);