From 6bc59db7213a756460f948ad92455403edab715b Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 13 Oct 2018 21:36:59 -0500 Subject: [PATCH] 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. --- CMakeLists.txt | 4 ++++ src/fish.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+) 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";