| 3018 | #endif |
| 3019 | |
| 3020 | std::string FindOwnExecutable(char const* argv0) |
| 3021 | { |
| 3022 | #if defined(_WIN32) && !defined(__CYGWIN__) |
| 3023 | static_cast<void>(argv0); |
| 3024 | wchar_t modulepath[_MAX_PATH]; |
| 3025 | ::GetModuleFileNameW(nullptr, modulepath, sizeof(modulepath)); |
| 3026 | std::string exe = cmsys::Encoding::ToNarrow(modulepath); |
| 3027 | #elif defined(__APPLE__) |
| 3028 | static_cast<void>(argv0); |
| 3029 | # define CM_EXE_PATH_LOCAL_SIZE 16384 |
| 3030 | char exe_path_local[CM_EXE_PATH_LOCAL_SIZE]; |
| 3031 | # if defined(MAC_OS_X_VERSION_10_3) && !defined(MAC_OS_X_VERSION_10_4) |
| 3032 | unsigned long exe_path_size = CM_EXE_PATH_LOCAL_SIZE; |
| 3033 | # else |
| 3034 | uint32_t exe_path_size = CM_EXE_PATH_LOCAL_SIZE; |
| 3035 | # endif |
| 3036 | # undef CM_EXE_PATH_LOCAL_SIZE |
| 3037 | char* exe_path = exe_path_local; |
| 3038 | if (_NSGetExecutablePath(exe_path, &exe_path_size) < 0) { |
| 3039 | exe_path = static_cast<char*>(malloc(exe_path_size)); |
| 3040 | _NSGetExecutablePath(exe_path, &exe_path_size); |
| 3041 | } |
| 3042 | std::string exe = exe_path; |
| 3043 | if (exe_path != exe_path_local) { |
| 3044 | free(exe_path); |
| 3045 | } |
| 3046 | if (IsCMakeAppBundleExe(exe)) { |
| 3047 | // The executable is inside an application bundle. |
| 3048 | // The install tree has "..<CMAKE_BIN_DIR>/cmake-gui". |
| 3049 | // The build tree has '../../../cmake-gui". |
| 3050 | std::string dir = cmSystemTools::GetFilenamePath(exe); |
| 3051 | dir = cmSystemTools::GetFilenamePath(dir); |
| 3052 | exe = cmStrCat(dir, CMAKE_BIN_DIR "/cmake-gui"); |
| 3053 | if (!cmSystemTools::PathExists(exe)) { |
| 3054 | dir = cmSystemTools::GetFilenamePath(dir); |
| 3055 | dir = cmSystemTools::GetFilenamePath(dir); |
| 3056 | exe = cmStrCat(dir, "/cmake-gui"); |
| 3057 | } |
| 3058 | } |
| 3059 | #else |
| 3060 | std::string exe = cmsys::SystemTools::FindProgram(argv0); |
| 3061 | #endif |
| 3062 | exe = cmSystemTools::ToNormalizedPathOnDisk(std::move(exe)); |
| 3063 | return exe; |
| 3064 | } |
| 3065 | |
| 3066 | #ifndef CMAKE_BOOTSTRAP |
| 3067 | bool ResolveSymlinkToOwnExecutable(std::string& exe, std::string& exe_dir) |
no test coverage detected
searching dependent graphs…