| 308 | } |
| 309 | |
| 310 | std::string cmFindProgramCommand::GetBundleExecutable( |
| 311 | std::string const& bundlePath) |
| 312 | { |
| 313 | std::string executable; |
| 314 | (void)bundlePath; |
| 315 | #if defined(__APPLE__) |
| 316 | // Started with an example on developer.apple.com about finding bundles |
| 317 | // and modified from that. |
| 318 | |
| 319 | // Get a CFString of the app bundle path |
| 320 | // XXX - Is it safe to assume everything is in UTF8? |
| 321 | CFStringRef bundlePathCFS = CFStringCreateWithCString( |
| 322 | kCFAllocatorDefault, bundlePath.c_str(), kCFStringEncodingUTF8); |
| 323 | |
| 324 | // Make a CFURLRef from the CFString representation of the |
| 325 | // bundle’s path. |
| 326 | CFURLRef bundleURL = CFURLCreateWithFileSystemPath( |
| 327 | kCFAllocatorDefault, bundlePathCFS, kCFURLPOSIXPathStyle, true); |
| 328 | |
| 329 | // Make a bundle instance using the URLRef. |
| 330 | CFBundleRef appBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL); |
| 331 | |
| 332 | // returned executableURL is relative to <appbundle>/Contents/MacOS/ |
| 333 | CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle); |
| 334 | |
| 335 | if (executableURL) { |
| 336 | int const MAX_OSX_PATH_SIZE = 1024; |
| 337 | UInt8 buffer[MAX_OSX_PATH_SIZE]; |
| 338 | |
| 339 | if (CFURLGetFileSystemRepresentation(executableURL, false, buffer, |
| 340 | MAX_OSX_PATH_SIZE)) { |
| 341 | executable = cmStrCat(bundlePath, "/Contents/MacOS/", |
| 342 | reinterpret_cast<char const*>(buffer)); |
| 343 | } |
| 344 | // Only release CFURLRef if it's not null |
| 345 | CFRelease(executableURL); |
| 346 | } |
| 347 | |
| 348 | // Any CF objects returned from functions with "create" or |
| 349 | // "copy" in their names must be released by us! |
| 350 | CFRelease(bundlePathCFS); |
| 351 | CFRelease(bundleURL); |
| 352 | CFRelease(appBundle); |
| 353 | #endif |
| 354 | |
| 355 | return executable; |
| 356 | } |
| 357 | |
| 358 | bool cmFindProgram(std::vector<std::string> const& args, |
| 359 | cmExecutionStatus& status) |
no test coverage detected