Detect when running out of cmake build directory

Load fish docs and configuration out of the source and/or build
directories rather from the installed paths when running directly out
of the cmake build directory.

Closes #5255.
This commit is contained in:
Mahmoud Al-Qudsi 2018-10-13 21:36:59 -05:00
parent f212518d3e
commit 6bc59db721
2 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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";