2009-09-28 19:43:28 +04:00
|
|
|
|
/*============================================================================
|
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-01-11 22:55:47 +03:00
|
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-01-11 22:55:47 +03:00
|
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
See the License for more information.
|
|
|
|
|
============================================================================*/
|
2001-01-18 19:20:24 +03:00
|
|
|
|
#include "cmFindProgramCommand.h"
|
2001-02-19 23:13:48 +03:00
|
|
|
|
#include "cmCacheManager.h"
|
2001-01-05 19:41:20 +03:00
|
|
|
|
#include <stdlib.h>
|
2006-04-13 19:00:52 +04:00
|
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
#endif
|
2010-11-12 18:47:28 +03:00
|
|
|
|
|
|
|
|
|
void cmFindProgramCommand::GenerateDocumentation()
|
2006-03-02 21:30:22 +03:00
|
|
|
|
{
|
2010-11-12 18:47:28 +03:00
|
|
|
|
this->cmFindBase::GenerateDocumentation();
|
2006-03-02 21:30:22 +03:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
2007-10-10 19:47:43 +04:00
|
|
|
|
"FIND_XXX", "find_program");
|
2006-03-02 21:30:22 +03:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"CMAKE_XXX_PATH", "CMAKE_PROGRAM_PATH");
|
2008-01-17 17:02:31 +03:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"CMAKE_XXX_MAC_PATH",
|
|
|
|
|
"CMAKE_APPBUNDLE_PATH");
|
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"CMAKE_SYSTEM_XXX_MAC_PATH",
|
|
|
|
|
"CMAKE_SYSTEM_APPBUNDLE_PATH");
|
2006-03-02 21:30:22 +03:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"XXX_SYSTEM", "");
|
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
2010-11-12 18:47:28 +03:00
|
|
|
|
"CMAKE_SYSTEM_XXX_PATH",
|
|
|
|
|
"CMAKE_SYSTEM_PROGRAM_PATH");
|
2006-03-02 21:30:22 +03:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"SEARCH_XXX_DESC", "program");
|
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"SEARCH_XXX", "program");
|
2007-10-26 17:55:40 +04:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"XXX_SUBDIR", "[s]bin");
|
2011-06-08 16:46:31 +04:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
|
"XXX_EXTRA_PREFIX_ENTRY", "");
|
2007-06-08 19:57:16 +04:00
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
2010-11-12 18:47:28 +03:00
|
|
|
|
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
|
2007-06-08 19:57:16 +04:00
|
|
|
|
"CMAKE_FIND_ROOT_PATH_MODE_PROGRAM");
|
2006-03-02 21:30:22 +03:00
|
|
|
|
}
|
2001-01-05 19:41:20 +03:00
|
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
|
// cmFindProgramCommand
|
2008-01-23 18:28:26 +03:00
|
|
|
|
bool cmFindProgramCommand
|
|
|
|
|
::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
|
2001-01-05 19:41:20 +03:00
|
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
|
this->VariableDocumentation = "Path to a program.";
|
|
|
|
|
this->CMakePathName = "PROGRAM";
|
|
|
|
|
// call cmFindBase::ParseArguments
|
|
|
|
|
if(!this->ParseArguments(argsIn))
|
2001-01-05 19:41:20 +03:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
|
if(this->AlreadyInCache)
|
2001-02-19 23:13:48 +03:00
|
|
|
|
{
|
2006-07-18 23:21:26 +04:00
|
|
|
|
// If the user specifies the entry on the command line without a
|
|
|
|
|
// type we should add the type and docstring but keep the original
|
|
|
|
|
// value.
|
|
|
|
|
if(this->AlreadyInCacheWithoutMetaInfo)
|
|
|
|
|
{
|
|
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName.c_str(), "",
|
|
|
|
|
this->VariableDocumentation.c_str(),
|
|
|
|
|
cmCacheManager::FILEPATH);
|
|
|
|
|
}
|
2001-02-19 23:13:48 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-04-13 19:00:52 +04:00
|
|
|
|
|
|
|
|
|
std::string result = FindProgram(this->Names);
|
2006-03-02 21:30:22 +03:00
|
|
|
|
if(result != "")
|
2001-01-05 19:41:20 +03:00
|
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
|
// Save the value in the cache
|
2006-03-15 19:02:08 +03:00
|
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
|
|
|
|
|
result.c_str(),
|
|
|
|
|
this->VariableDocumentation.c_str(),
|
|
|
|
|
cmCacheManager::FILEPATH);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-03-02 21:30:22 +03:00
|
|
|
|
return true;
|
2001-01-05 19:41:20 +03:00
|
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
|
2006-03-02 21:30:22 +03:00
|
|
|
|
(this->VariableName + "-NOTFOUND").c_str(),
|
|
|
|
|
this->VariableDocumentation.c_str(),
|
2001-08-08 19:54:46 +04:00
|
|
|
|
cmCacheManager::FILEPATH);
|
2001-05-04 19:30:46 +04:00
|
|
|
|
return true;
|
2001-01-05 19:41:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
std::string cmFindProgramCommand::FindProgram(std::vector<std::string> names)
|
|
|
|
|
{
|
|
|
|
|
std::string program = "";
|
|
|
|
|
|
2008-06-09 19:58:29 +04:00
|
|
|
|
if(this->SearchAppBundleFirst || this->SearchAppBundleOnly)
|
2006-04-13 19:00:52 +04:00
|
|
|
|
{
|
|
|
|
|
program = FindAppBundle(names);
|
|
|
|
|
}
|
|
|
|
|
if(program.empty() && !this->SearchAppBundleOnly)
|
|
|
|
|
{
|
|
|
|
|
program = cmSystemTools::FindProgram(names, this->SearchPaths, true);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-09 19:58:29 +04:00
|
|
|
|
if(program.empty() && this->SearchAppBundleLast)
|
|
|
|
|
{
|
|
|
|
|
program = this->FindAppBundle(names);
|
|
|
|
|
}
|
2006-04-13 19:00:52 +04:00
|
|
|
|
return program;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-10 23:46:45 +04:00
|
|
|
|
std::string cmFindProgramCommand
|
|
|
|
|
::FindAppBundle(std::vector<std::string> names)
|
2006-04-13 19:00:52 +04:00
|
|
|
|
{
|
|
|
|
|
for(std::vector<std::string>::const_iterator name = names.begin();
|
|
|
|
|
name != names.end() ; ++name)
|
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
std::string appName = *name + std::string(".app");
|
2012-08-13 21:42:58 +04:00
|
|
|
|
std::string appPath = cmSystemTools::FindDirectory(appName.c_str(),
|
|
|
|
|
this->SearchPaths,
|
2006-05-10 23:46:45 +04:00
|
|
|
|
true);
|
2006-04-13 19:00:52 +04:00
|
|
|
|
|
|
|
|
|
if ( !appPath.empty() )
|
|
|
|
|
{
|
|
|
|
|
std::string executable = GetBundleExecutable(appPath);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
if (!executable.empty())
|
2006-04-13 19:00:52 +04:00
|
|
|
|
{
|
|
|
|
|
return cmSystemTools::CollapseFullPath(executable.c_str());
|
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-04-13 19:00:52 +04:00
|
|
|
|
|
|
|
|
|
// Couldn't find app bundle
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string cmFindProgramCommand::GetBundleExecutable(std::string bundlePath)
|
|
|
|
|
{
|
|
|
|
|
std::string executable = "";
|
2006-04-14 07:24:09 +04:00
|
|
|
|
(void)bundlePath;
|
2006-04-13 19:00:52 +04:00
|
|
|
|
#if defined(__APPLE__)
|
2012-08-13 21:42:58 +04:00
|
|
|
|
// Started with an example on developer.apple.com about finding bundles
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// and modified from that.
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// Get a CFString of the app bundle path
|
|
|
|
|
// XXX - Is it safe to assume everything is in UTF8?
|
2012-08-13 21:42:58 +04:00
|
|
|
|
CFStringRef bundlePathCFS =
|
|
|
|
|
CFStringCreateWithCString(kCFAllocatorDefault ,
|
2006-05-10 23:46:45 +04:00
|
|
|
|
bundlePath.c_str(), kCFStringEncodingUTF8 );
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-05-10 23:46:45 +04:00
|
|
|
|
// Make a CFURLRef from the CFString representation of the
|
|
|
|
|
// bundle’s path.
|
2012-08-13 21:42:58 +04:00
|
|
|
|
CFURLRef bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
2006-04-13 19:00:52 +04:00
|
|
|
|
bundlePathCFS,
|
|
|
|
|
kCFURLPOSIXPathStyle,
|
|
|
|
|
true );
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// Make a bundle instance using the URLRef.
|
|
|
|
|
CFBundleRef appBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// returned executableURL is relative to <appbundle>/Contents/MacOS/
|
|
|
|
|
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
if (executableURL != NULL)
|
|
|
|
|
{
|
|
|
|
|
const int MAX_OSX_PATH_SIZE = 1024;
|
|
|
|
|
char buffer[MAX_OSX_PATH_SIZE];
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// Convert the CFString to a C string
|
2012-08-13 21:42:58 +04:00
|
|
|
|
CFStringGetCString( CFURLGetString(executableURL), buffer,
|
2006-05-10 23:46:45 +04:00
|
|
|
|
MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8 );
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// And finally to a c++ string
|
|
|
|
|
executable = bundlePath + "/Contents/MacOS/" + std::string(buffer);
|
2012-02-25 21:20:36 +04:00
|
|
|
|
// Only release CFURLRef if it's not null
|
|
|
|
|
CFRelease( executableURL );
|
2006-04-13 19:00:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
|
// Any CF objects returned from functions with "create" or
|
2006-04-13 19:00:52 +04:00
|
|
|
|
// "copy" in their names must be released by us!
|
|
|
|
|
CFRelease( bundlePathCFS );
|
|
|
|
|
CFRelease( bundleURL );
|
|
|
|
|
CFRelease( appBundle );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return executable;
|
|
|
|
|
}
|
|
|
|
|
|