From 1b4bc5e27eeb037c299d3f57e9bed7e3c20c6d76 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 7 Mar 2018 15:01:49 -0800 Subject: [vcpkg] Add case for exe path discovery for macos --- toolsrc/src/vcpkg/base/system.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/base/system.cpp b/toolsrc/src/vcpkg/base/system.cpp index f71fd8445..e55db9461 100644 --- a/toolsrc/src/vcpkg/base/system.cpp +++ b/toolsrc/src/vcpkg/base/system.cpp @@ -7,6 +7,10 @@ #include +#if defined(__APPLE__) +# include +#endif + #pragma comment(lib, "Advapi32") namespace vcpkg::System @@ -31,7 +35,15 @@ namespace vcpkg::System const int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH); if (bytes == 0) std::abort(); return fs::path(buf, buf + bytes); -#else +#elif __APPLE__ + uint32_t size = 1024 * 32; + char buf[size] = {}; + bool result = _NSGetExecutablePath(buf, &size); + Checks::check_exit(VCPKG_LINE_INFO, result != -1, "Could not determine current executable path."); + std::unique_ptr canonicalPath (realpath(buf, NULL)); + Checks::check_exit(VCPKG_LINE_INFO, result != -1, "Could not determine current executable path."); + return fs::path(std::string(canonicalPath.get())); +#else /* LINUX */ std::array buf; auto written = readlink("/proc/self/exe", buf.data(), buf.size()); Checks::check_exit(VCPKG_LINE_INFO, written != -1, "Could not determine current executable path."); -- cgit v1.2.3