aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2018-03-07 15:01:49 -0800
committerRobert Schumacher <roschuma@microsoft.com>2018-03-07 15:01:49 -0800
commit1b4bc5e27eeb037c299d3f57e9bed7e3c20c6d76 (patch)
tree68461361f888880d354fd5fb56d2512c29ea675f /toolsrc/src
parent864ddcd6812bbed805864df0180e8fcab34912f6 (diff)
downloadvcpkg-1b4bc5e27eeb037c299d3f57e9bed7e3c20c6d76.tar.gz
vcpkg-1b4bc5e27eeb037c299d3f57e9bed7e3c20c6d76.zip
[vcpkg] Add case for exe path discovery for macos
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/vcpkg/base/system.cpp14
1 files changed, 13 insertions, 1 deletions
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 <time.h>
+#if defined(__APPLE__)
+# include <mach-o/dyld.h>
+#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<char> 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<char, 1024 * 4> 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.");