diff --git a/CMakeLists.txt b/CMakeLists.txt index 405343e50..a5d6526a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,10 @@ ADD_DEFINITIONS(-D_UNICODE=1 # This defines the FBVF variable. INCLUDE(Version) +# Let fish pick up when we're running out of the build directory without installing +ADD_DEFINITIONS(-DCMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}") +ADD_DEFINITIONS(-DCMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}") + # Teach fish_version.o to rebuild when FBVF changes. # The standard C++ include detection machinery misses this. SET_SOURCE_FILES_PROPERTIES(src/fish_version.cpp diff --git a/src/fish.cpp b/src/fish.cpp index de90cd2a3..1746aed50 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -95,6 +95,20 @@ static struct config_paths_t determine_config_directory_paths(const char *argv0) std::string exec_path = get_executable_path(argv0); if (get_realpath(exec_path)) { debug(2, L"exec_path: '%s'", exec_path.c_str()); + +#ifdef CMAKE_BINARY_DIR + // Detect if we're running right out of the CMAKE build directory + if (exec_path == std::string(CMAKE_BINARY_DIR) + "/fish") { + debug(2, "Running out of build directory, falling back to source paths"); + + done = true; + paths.data = wcstring{L"" CMAKE_SOURCE_DIR} + L"/share"; + paths.sysconf = L"" SYSCONFDIR "/fish"; + paths.doc = L"" DOCDIR; + paths.bin = L"" BINDIR; + } +#endif + if (!done) { // The next check is that we are in a reloctable directory tree const char *installed_suffix = "/bin/fish";