From 239fce5caa59daeaea830aa38e0cb576599221da Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 31 Aug 2006 10:47:00 -0400 Subject: [PATCH] ENH: Do not generate install target unless some INSTALL or INSTALL_* commands have been used. This addresses bug#2827. --- Source/cmGlobalGenerator.cxx | 115 +++++++++++++++------------- Source/cmGlobalGenerator.h | 2 + Source/cmInstallCommand.cxx | 4 + Source/cmInstallFilesCommand.cxx | 5 ++ Source/cmInstallProgramsCommand.cxx | 4 + Source/cmInstallTargetsCommand.cxx | 4 + 6 files changed, 82 insertions(+), 52 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 35bc3b7b0..1b72f400f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -42,6 +42,9 @@ cmGlobalGenerator::cmGlobalGenerator() // Relative paths are not configured in the constructor. this->RelativePathsConfigured = false; + + // Whether an install target is needed. + this->InstallTargetEnabled = false; } cmGlobalGenerator::~cmGlobalGenerator() @@ -927,6 +930,11 @@ void cmGlobalGenerator::AddInstallComponent(const char* component) } } +void cmGlobalGenerator::EnableInstallTarget() +{ + this->InstallTargetEnabled = true; +} + cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator() { cmLocalGenerator *lg = new cmLocalGenerator; @@ -1448,66 +1456,69 @@ void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets) } //Install - std::string cmd; - cpackCommandLines.erase(cpackCommandLines.begin(), cpackCommandLines.end()); - singleLine.erase(singleLine.begin(), singleLine.end()); - depends.erase(depends.begin(), depends.end()); - if ( this->GetPreinstallTargetName() ) + if(this->InstallTargetEnabled) { - depends.push_back(this->GetPreinstallTargetName()); - } - else - { - const char* noall = - mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY"); - if(!noall || cmSystemTools::IsOff(noall)) + std::string cmd; + cpackCommandLines.erase(cpackCommandLines.begin(), cpackCommandLines.end()); + singleLine.erase(singleLine.begin(), singleLine.end()); + depends.erase(depends.begin(), depends.end()); + if ( this->GetPreinstallTargetName() ) { - depends.push_back(this->GetAllTargetName()); + depends.push_back(this->GetPreinstallTargetName()); } - } - if(mf->GetDefinition("CMake_BINARY_DIR")) - { - // We are building CMake itself. We cannot use the original - // executable to install over itself. - cmd = mf->GetDefinition("EXECUTABLE_OUTPUT_PATH"); - if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') + else { - cmd += "/"; - cmd += cmakeCfgIntDir; + const char* noall = + mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY"); + if(!noall || cmSystemTools::IsOff(noall)) + { + depends.push_back(this->GetAllTargetName()); + } } - cmd += "/cmake"; - } - else - { - cmd = cmakeCommand; - } - singleLine.push_back(cmd.c_str()); - if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' ) - { - std::string cfgArg = "-DBUILD_TYPE="; - cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR"); - singleLine.push_back(cfgArg); - } - singleLine.push_back("-P"); - singleLine.push_back("cmake_install.cmake"); - cpackCommandLines.push_back(singleLine); - (*targets)[this->GetInstallTargetName()] = - this->CreateGlobalTarget( - this->GetInstallTargetName(), "Install the project...", - &cpackCommandLines, depends); - - // install_local - if(const char* install_local = this->GetInstallLocalTargetName()) - { - singleLine.insert(singleLine.begin()+1, "-DCMAKE_INSTALL_LOCAL_ONLY=1"); - cpackCommandLines.erase(cpackCommandLines.begin(), - cpackCommandLines.end()); + if(mf->GetDefinition("CMake_BINARY_DIR")) + { + // We are building CMake itself. We cannot use the original + // executable to install over itself. + cmd = mf->GetDefinition("EXECUTABLE_OUTPUT_PATH"); + if(cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.') + { + cmd += "/"; + cmd += cmakeCfgIntDir; + } + cmd += "/cmake"; + } + else + { + cmd = cmakeCommand; + } + singleLine.push_back(cmd.c_str()); + if ( cmakeCfgIntDir && *cmakeCfgIntDir && cmakeCfgIntDir[0] != '.' ) + { + std::string cfgArg = "-DBUILD_TYPE="; + cfgArg += mf->GetDefinition("CMAKE_CFG_INTDIR"); + singleLine.push_back(cfgArg); + } + singleLine.push_back("-P"); + singleLine.push_back("cmake_install.cmake"); cpackCommandLines.push_back(singleLine); - - (*targets)[install_local] = + (*targets)[this->GetInstallTargetName()] = this->CreateGlobalTarget( - install_local, "Installing only the local directory...", + this->GetInstallTargetName(), "Install the project...", &cpackCommandLines, depends); + + // install_local + if(const char* install_local = this->GetInstallLocalTargetName()) + { + singleLine.insert(singleLine.begin()+1, "-DCMAKE_INSTALL_LOCAL_ONLY=1"); + cpackCommandLines.erase(cpackCommandLines.begin(), + cpackCommandLines.end()); + cpackCommandLines.push_back(singleLine); + + (*targets)[install_local] = + this->CreateGlobalTarget( + install_local, "Installing only the local directory...", + &cpackCommandLines, depends); + } } } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index b4ef86f48..7c6caf00d 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -123,6 +123,7 @@ public: void AddLocalGenerator(cmLocalGenerator *lg); void AddInstallComponent(const char* component); + void EnableInstallTarget(); static int s_TryCompileTimeout; @@ -221,6 +222,7 @@ protected: // Set of named installation components requested by the project. std::set InstallComponents; + bool InstallTargetEnabled; // Manifest of all targets that will be built for each configuration. // This is computed just before local generators generate. diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 9cb37c9c3..20081eb4c 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -33,6 +33,10 @@ bool cmInstallCommand::InitialPass(std::vector const& args) return true; } + // Enable the install target. + this->Makefile->GetLocalGenerator() + ->GetGlobalGenerator()->EnableInstallTarget(); + // Switch among the command modes. if(args[0] == "SCRIPT") { diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx index 5b75456c2..12b7fdc70 100644 --- a/Source/cmInstallFilesCommand.cxx +++ b/Source/cmInstallFilesCommand.cxx @@ -25,6 +25,11 @@ bool cmInstallFilesCommand this->SetError("called with incorrect number of arguments"); return false; } + + // Enable the install target. + this->Makefile->GetLocalGenerator() + ->GetGlobalGenerator()->EnableInstallTarget(); + std::vector args; this->Makefile->ExpandSourceListArguments(argsIn, args, 2); diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx index 1830c5e7f..e38f0a6bc 100644 --- a/Source/cmInstallProgramsCommand.cxx +++ b/Source/cmInstallProgramsCommand.cxx @@ -26,6 +26,10 @@ bool cmInstallProgramsCommand return false; } + // Enable the install target. + this->Makefile->GetLocalGenerator() + ->GetGlobalGenerator()->EnableInstallTarget(); + // Create an INSTALL_PROGRAMS target specifically for this path. this->TargetName = "INSTALL_PROGRAMS_"+args[0]; cmTarget& target = this->Makefile->GetTargets()[this->TargetName]; diff --git a/Source/cmInstallTargetsCommand.cxx b/Source/cmInstallTargetsCommand.cxx index 42f83acb8..246b118af 100644 --- a/Source/cmInstallTargetsCommand.cxx +++ b/Source/cmInstallTargetsCommand.cxx @@ -26,6 +26,10 @@ bool cmInstallTargetsCommand return false; } + // Enable the install target. + this->Makefile->GetLocalGenerator() + ->GetGlobalGenerator()->EnableInstallTarget(); + cmTargets &tgts = this->Makefile->GetTargets(); std::vector::const_iterator s = args.begin(); ++s;