xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
paths.cc
浏览该文件的文档.
1#include <filesystem>
2#include <string>
4
5#if defined(_WIN32) || defined(_WIN64)
6# include <windows.h>
7# define GET_EXECUTABLE_PATH() getExecutablePathWindows()
8static std::string getExecutablePathWindows() {
9 char path[MAX_PATH];
10 GetModuleFileName(NULL, path, MAX_PATH);
11 return std::string(path);
12}
13#elif defined(__linux__)
14# include <limits.h>
15# include <unistd.h>
16# define GET_EXECUTABLE_PATH() getExecutablePathLinux()
17static std::string getExecutablePathLinux() {
18 char path[PATH_MAX];
19 ssize_t len = ::readlink("/proc/self/exe", path, sizeof(path) - 1);
20 if (len != -1) {
21 path[len] = '\0';
22 return std::string(path);
23 }
24 return "";
25}
26#elif defined(__APPLE__) || defined(__MACH__)
27# include <objc/objc.h>
28# include <objc/runtime.h>
29# define GET_EXECUTABLE_PATH() getExecutablePathMacOS()
30static std::string getExecutablePathMacOS() {
31 @autoreleasepool {
32 NSString *path = [[NSBundle mainBundle] executablePath];
33 return std::string([path UTF8String]);
34 }
35}
36#else
37# error "Unsupported platform"
38#endif
40const std::string CURRENT_WORKING_DIRECTORY =
41 std::filesystem::current_path().string();
42const std::string EXECUTABLE_PATH = GET_EXECUTABLE_PATH();
43const std::string EXECUTABLE_DIR =
44 std::filesystem::is_directory(EXECUTABLE_PATH)
46 : std::filesystem::path(EXECUTABLE_PATH).parent_path().string();
47} // namespace xcal::utils::paths
const std::string EXECUTABLE_DIR
Get the directory of the executable.
Definition paths.cc:43
const std::string CURRENT_WORKING_DIRECTORY
Get the current working directory.
Definition paths.cc:40
const std::string EXECUTABLE_PATH
Get the path of the executable.
Definition paths.cc:42
This file contains the declaration of paths used in xcal.