Commit d1526f82 authored by Brad King's avatar Brad King
Browse files

Refactor internal resource location APIs and initialization

Rename cmSystemTools::FindExecutableDirectory to FindCMakeResources.
Teach it to compute the locations of cmake, ctest, cpack, ccmake, and
cmake-gui executables, and the location of CMAKE_ROOT.  Provide this
information from static cmSystemTools::Get<resource>() methods.
Refactor code that needs these locations to use the new APIs.

Teach FindCMakeResources to use the OS X system API to lookup the
executable location.  When running from the CMake build tree itself,
leave a file in the tree that FindCMakeResources can use to read the
location of the source tree.  This avoids the need to compile the source
tree location into a binary that may be installed and used without the
source tree.

Teach the QtDialog on OS X to create a "cmake-gui" symlink in the build
tree next to "cmake" and the other tools, as is already done in the
install tree for the application bundle.  This ensures a consistent set
of executables are available in one directory.
parent 9fc158b6
......@@ -38,6 +38,12 @@ configure_file(
"${CMake_BINARY_DIR}/Source/CPack/cmCPackConfigure.h"
)
# Tell CMake executable in the build tree where to find the source tree.
configure_file(
"${CMake_SOURCE_DIR}/Source/CMakeSourceDir.txt.in"
"${CMake_BINARY_DIR}/CMakeFiles/CMakeSourceDir.txt" @ONLY
)
# add the include path to find the .h
include_directories(
"${CMake_BINARY_DIR}/Source"
......
......@@ -1143,12 +1143,6 @@ int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf)
{
this->MakefileMap = mf;
this->Name = name;
if ( !this->SetCMakeRoot() )
{
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Cannot initialize the generator" << std::endl);
return 0;
}
// set the running generator name
this->SetOption("CPACK_GENERATOR", this->Name.c_str());
// Load the project specific config file
......@@ -1204,32 +1198,6 @@ const char* cmCPackGenerator::GetOption(const char* op) const
return ret;
}
//----------------------------------------------------------------------
int cmCPackGenerator::SetCMakeRoot()
{
// use the CMAKE_ROOT from cmake which should have been
// found by now
const char* root=
this->MakefileMap->GetDefinition("CMAKE_ROOT");
if(root)
{
this->CMakeRoot = root;
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
<< this->CMakeRoot.c_str() << std::endl);
this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
return 1;
}
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Could not find CMAKE_ROOT !!!"
<< std::endl
<< "CMake has most likely not been installed correctly."
<< std::endl
<<"Modules directory not found in"
<< std::endl);
return 0;
}
//----------------------------------------------------------------------
int cmCPackGenerator::PackageFiles()
{
......
......@@ -105,9 +105,6 @@ public:
bool IsSet(const char* name) const;
bool IsOn(const char* name) const;
//! Set all the variables
int SetCMakeRoot();
//! Set the logger
void SetLogger(cmCPackLog* log) { this->Logger = log; }
......@@ -285,10 +282,6 @@ protected:
*/
std::vector<std::string> files;
std::string CPackSelf;
std::string CMakeSelf;
std::string CMakeRoot;
std::map<std::string, cmCPackInstallationType> InstallationTypes;
/**
* The set of components.
......
......@@ -99,7 +99,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
// this is CPack.
int main (int argc, char *argv[])
{
cmSystemTools::FindExecutableDirectory(argv[0]);
cmSystemTools::FindCMakeResources(argv[0]);
cmCPackLog log;
log.SetErrorPrefix("CPack Error: ");
......@@ -228,7 +228,6 @@ int main (int argc, char *argv[])
// This part is used for cpack documentation lookup as well.
cminst.AddCMakePaths();
doc.SetCMakeRoot(cminst.GetCacheDefinition("CMAKE_ROOT"));
if ( parsed && !help )
{
......
......@@ -59,7 +59,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
{
unsigned int k;
std::vector<std::string> args;
args.push_back(this->CTest->GetCMakeExecutable());
args.push_back(cmSystemTools::GetCMakeCommand());
args.push_back(this->SourceDir);
if(this->BuildGenerator.size())
{
......
......@@ -86,7 +86,7 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
}
std::string cmakeConfigureCommand = "\"";
cmakeConfigureCommand += this->CTest->GetCMakeExecutable();
cmakeConfigureCommand += cmSystemTools::GetCMakeCommand();
cmakeConfigureCommand += "\"";
std::vector<std::string>::const_iterator it;
......
......@@ -222,13 +222,13 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
// execute the script passing in the arguments to the script as well as the
// arguments from this invocation of cmake
std::vector<const char*> argv;
argv.push_back(this->CTest->GetCTestExecutable());
argv.push_back(cmSystemTools::GetCTestCommand().c_str());
argv.push_back("-SR");
argv.push_back(total_script_arg.c_str());
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Executable for CTest is: " <<
this->CTest->GetCTestExecutable() << "\n");
cmSystemTools::GetCTestCommand() << "\n");
// now pass through all the other arguments
std::vector<cmStdString> &initArgs =
......@@ -397,9 +397,9 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
this->Makefile->AddDefinition("CTEST_SCRIPT_NAME",
cmSystemTools::GetFilenameName(script).c_str());
this->Makefile->AddDefinition("CTEST_EXECUTABLE_NAME",
this->CTest->GetCTestExecutable());
cmSystemTools::GetCTestCommand().c_str());
this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME",
this->CTest->GetCMakeExecutable());
cmSystemTools::GetCMakeCommand().c_str());
this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", true);
this->UpdateElapsedTime();
......
......@@ -80,14 +80,13 @@ void CMakeErrorHandler(const char* message, const char* title, bool&, void* clie
int main(int argc, char** argv)
{
cmSystemTools::FindExecutableDirectory(argv[0]);
cmSystemTools::FindCMakeResources(argv[0]);
cmDocumentation doc;
doc.addCMakeStandardDocSections();
if(doc.CheckOptions(argc, argv))
{
cmake hcm;
hcm.AddCMakePaths();
doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
std::vector<cmDocumentationEntry> generators;
hcm.GetGeneratorDocumentation(generators);
doc.SetName("ccmake");
......
......@@ -43,14 +43,14 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
this->HelpMessage.push_back("");
this->HelpMessage.push_back(s_ConstHelpMessage);
this->CMakeInstance = new cmake;
this->CMakeInstance->SetCMakeEditCommand("ccmake");
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeCursesCommand());
// create the arguments for the cmake object
std::string whereCMake = cmSystemTools::GetProgramPath(this->Args[0].c_str());
whereCMake += "/cmake";
this->Args[0] = whereCMake;
this->CMakeInstance->SetArgs(this->Args);
this->CMakeInstance->SetCMakeCommand(whereCMake.c_str());
this->SearchString = "";
this->OldSearchString = "";
this->SearchMode = false;
......
......@@ -118,6 +118,13 @@ if(APPLE)
# TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "Copyright 2000-2013 Kitware, Inc."
)
# Create a symlink in the build tree to provide a "cmake-gui" next
# to the "cmake" executable that refers to the application bundle.
add_custom_command(TARGET cmake-gui POST_BUILD
COMMAND ln -sf ${CMAKE_BUNDLE_NAME}.app/Contents/MacOS/${CMAKE_BUNDLE_NAME}
$<TARGET_FILE_DIR:cmake>/cmake-gui
)
endif()
set(CMAKE_INSTALL_DESTINATION_ARGS
BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}")
......
......@@ -48,7 +48,7 @@ static const char * cmDocumentationOptions[][2] =
int main(int argc, char** argv)
{
cmSystemTools::FindExecutableDirectory(argv[0]);
cmSystemTools::FindCMakeResources(argv[0]);
// check docs first so that X is not need to get docs
// do docs, if args were given
cmDocumentation doc;
......@@ -58,7 +58,6 @@ int main(int argc, char** argv)
// Construct and print requested documentation.
cmake hcm;
hcm.AddCMakePaths();
doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
std::vector<cmDocumentationEntry> generators;
hcm.GetGeneratorDocumentation(generators);
......
......@@ -33,34 +33,13 @@ QCMake::QCMake(QObject* p)
qRegisterMetaType<QCMakeProperty>();
qRegisterMetaType<QCMakePropertyList>();
QDir execDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_MAC)
if(execDir.exists("../bin/cmake"))
{
execDir.cd("../bin");
}
else
{
execDir.cd("../../../"); // path to cmake in build directory (need to fix for deployment)
}
#endif
QString cmakeCommand = QString("cmake")+QString::fromLocal8Bit(cmSystemTools::GetExecutableExtension());
cmakeCommand = execDir.filePath(cmakeCommand);
cmSystemTools::DisableRunCommandOutput();
cmSystemTools::SetRunCommandHideConsole(true);
cmSystemTools::SetErrorCallback(QCMake::errorCallback, this);
cmSystemTools::FindExecutableDirectory(cmakeCommand.toLocal8Bit().data());
this->CMakeInstance = new cmake;
this->CMakeInstance->SetCMakeCommand(cmakeCommand.toLocal8Bit().data());
#if defined(Q_OS_MAC)
this->CMakeInstance->SetCMakeEditCommand("cmake-gui.app/Contents/MacOS/cmake-gui");
#else
this->CMakeInstance->SetCMakeEditCommand("cmake-gui");
#endif
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeGUICommand());
this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
......
......@@ -1298,7 +1298,8 @@ int cmCTest::RunTest(std::vector<const char*> argv,
}
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
"Test timeout computed to be: " << timeout << "\n");
if(cmSystemTools::SameFile(argv[0], this->CTestSelf.c_str()) &&
if(cmSystemTools::SameFile(
argv[0], cmSystemTools::GetCTestCommand().c_str()) &&
!this->ForceNewCTestProcess)
{
cmCTest inst;
......@@ -2257,7 +2258,6 @@ bool cmCTest::AddVariableDefinition(const std::string &arg)
// the main entry point of ctest, called from main
int cmCTest::Run(std::vector<std::string> &args, std::string* output)
{
this->FindRunningCMake();
const char* ctestExec = "ctest";
bool cmakeAndTest = false;
bool executeTests = true;
......@@ -2497,29 +2497,6 @@ int cmCTest::Run(std::vector<std::string> &args, std::string* output)
return 1;
}
//----------------------------------------------------------------------
void cmCTest::FindRunningCMake()
{
// Find our own executable.
this->CTestSelf = cmSystemTools::GetExecutableDirectory();
this->CTestSelf += "/ctest";
this->CTestSelf += cmSystemTools::GetExecutableExtension();
if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
{
cmSystemTools::Error("CTest executable cannot be found at ",
this->CTestSelf.c_str());
}
this->CMakeSelf = cmSystemTools::GetExecutableDirectory();
this->CMakeSelf += "/cmake";
this->CMakeSelf += cmSystemTools::GetExecutableExtension();
if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
{
cmSystemTools::Error("CMake executable cannot be found at ",
this->CMakeSelf.c_str());
}
}
//----------------------------------------------------------------------
void cmCTest::SetNotesFiles(const char* notes)
{
......
......@@ -287,10 +287,6 @@ public:
//source directory, it will become /.../relative/path/to/file
std::string GetShortPathToFile(const char* fname);
//! Get the path to CTest
const char* GetCTestExecutable() { return this->CTestSelf.c_str(); }
const char* GetCMakeExecutable() { return this->CMakeSelf.c_str(); }
enum {
EXPERIMENTAL,
NIGHTLY,
......@@ -490,8 +486,6 @@ private:
int CompatibilityMode;
// information for the --build-and-test options
std::string CMakeSelf;
std::string CTestSelf;
std::string BinaryDir;
std::string NotesFiles;
......@@ -546,9 +540,6 @@ private:
int GenerateCTestNotesOutput(std::ostream& os,
const VectorOfStrings& files);
///! Find the running cmake
void FindRunningCMake();
//! Check if the argument is the one specified
bool CheckArgument(const std::string& arg, const char* varg1,
const char* varg2 = 0);
......
......@@ -16,6 +16,4 @@
#cmakedefine HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE
#cmakedefine HAVE_UNSETENV
#cmakedefine CMAKE_USE_ELF_PARSER
#define CMAKE_ROOT_DIR "${CMake_SOURCE_DIR}"
#define CMAKE_BUILD_DIR "${CMake_BINARY_DIR}"
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"
......@@ -605,7 +605,8 @@ void cmDocumentation::GlobHelp(std::vector<std::string>& files,
std::string const& pattern)
{
cmsys::Glob gl;
std::string findExpr = this->CMakeRoot + "/Help/" + pattern + ".rst";
std::string findExpr =
cmSystemTools::GetCMakeRoot() + "/Help/" + pattern + ".rst";
if(gl.FindFiles(findExpr))
{
files = gl.GetFiles();
......@@ -649,7 +650,7 @@ bool cmDocumentation::PrintFiles(std::ostream& os,
std::vector<std::string> files;
this->GlobHelp(files, pattern);
std::sort(files.begin(), files.end());
cmRST r(os, this->CMakeRoot + "/Help");
cmRST r(os, cmSystemTools::GetCMakeRoot() + "/Help");
for (std::vector<std::string>::const_iterator i = files.begin();
i != files.end(); ++i)
{
......
......@@ -83,9 +83,6 @@ public:
void AppendSection(const char *sectionName,
cmDocumentationEntry &docs);
/** Set cmake root so we can find installed files */
void SetCMakeRoot(const char* root) { this->CMakeRoot = root? root:"";}
/** Add common (to all tools) documentation section(s) */
void addCommonStandardDocSections();
......@@ -127,7 +124,6 @@ private:
std::string NameString;
std::map<std::string,cmDocumentationSection*> AllSections;
std::string CMakeRoot;
std::string CurrentArgument;
struct RequestedHelpItem
......
......@@ -2068,7 +2068,7 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
cmCustomCommandLines cpackCommandLines;
std::vector<std::string> depends;
cmCustomCommandLine singleLine;
singleLine.push_back(this->GetCMakeInstance()->GetCPackCommand());
singleLine.push_back(cmSystemTools::GetCPackCommand());
if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' )
{
singleLine.push_back("-C");
......@@ -2109,7 +2109,7 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
cpackCommandLines.end());
singleLine.erase(singleLine.begin(), singleLine.end());
depends.erase(depends.begin(), depends.end());
singleLine.push_back(this->GetCMakeInstance()->GetCPackCommand());
singleLine.push_back(cmSystemTools::GetCPackCommand());
singleLine.push_back("--config");
configFile = mf->GetStartOutputDirectory();;
configFile += "/CPackSourceConfig.cmake";
......@@ -2135,7 +2135,7 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets)
cpackCommandLines.end());
singleLine.erase(singleLine.begin(), singleLine.end());
depends.erase(depends.begin(), depends.end());
singleLine.push_back(this->GetCMakeInstance()->GetCTestCommand());
singleLine.push_back(cmSystemTools::GetCTestCommand());
singleLine.push_back("--force-new-ctest-process");
if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.')
{
......
......@@ -3072,7 +3072,6 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
cm.SetHomeOutputDirectory(bindir);
cm.SetStartDirectory(srcdir);
cm.SetStartOutputDirectory(bindir);
cm.SetCMakeCommand(cmakeCommand.c_str());
cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset());
cm.LoadCache();
if(!gg->IsMultiConfig())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment