ENH: Implemented FILES and PROGRAMS forms of the INSTALL command as replacements for the INSTALL_FILES and INSTALL_PROGRAMS commands. This addresses the request for absolute path install destinations in bug#2691.

This commit is contained in:
Brad King 2006-02-19 18:47:13 -05:00
parent 4140f4a6fa
commit 518080136d
11 changed files with 243 additions and 59 deletions

View File

@ -117,6 +117,8 @@ SET(SRCS
cmGlobalUnixMakefileGenerator3.h
cmInstallGenerator.h
cmInstallGenerator.cxx
cmInstallFilesGenerator.h
cmInstallFilesGenerator.cxx
cmInstallScriptGenerator.h
cmInstallScriptGenerator.cxx
cmInstallTargetGenerator.h

View File

@ -16,6 +16,7 @@
=========================================================================*/
#include "cmInstallCommand.h"
#include "cmInstallFilesGenerator.h"
#include "cmInstallScriptGenerator.h"
#include "cmInstallTargetGenerator.h"
@ -38,6 +39,14 @@ bool cmInstallCommand::InitialPass(std::vector<std::string> const& args)
{
return this->HandleTargetsMode(args);
}
else if(args[0] == "FILES")
{
return this->HandleFilesMode(args);
}
else if(args[0] == "PROGRAMS")
{
return this->HandleFilesMode(args);
}
// Unknown mode.
cmStdString e = "called with unknown mode ";
@ -283,6 +292,85 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
return true;
}
//----------------------------------------------------------------------------
bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
{
// This is the FILES mode.
bool programs = (args[0] == "PROGRAMS");
bool doing_files = true;
bool doing_destination = false;
std::vector<std::string> files;
const char* destination = 0;
for(unsigned int i=1; i < args.size(); ++i)
{
if(args[i] == "DESTINATION")
{
// Switch to setting the destination property.
doing_files = false;
doing_destination = true;
}
else if(doing_files)
{
// Convert this file to a full path.
std::string file = args[i];
if(!cmSystemTools::FileIsFullPath(file.c_str()))
{
file = m_Makefile->GetCurrentDirectory();
file += "/";
file += args[i];
}
// Make sure the file is not a directory.
if(cmSystemTools::FileIsDirectory(file.c_str()))
{
cmOStringStream e;
e << args[0] << " given directory \"" << args[i] << "\" to install.";
this->SetError(e.str().c_str());
return false;
}
// Store the file for installation.
files.push_back(file);
}
else if(doing_destination)
{
destination = args[i].c_str();
doing_destination = false;
}
else
{
// Unknown argument.
cmOStringStream e;
e << args[0] << " given unknown argument \"" << args[i] << "\".";
this->SetError(e.str().c_str());
return false;
}
}
// Check if there is something to do.
if(files.empty())
{
return true;
}
if(!destination)
{
cmOStringStream e;
e << args[0] << " given no DESTINATION!";
this->SetError(e.str().c_str());
return false;
}
// Compute destination path.
std::string dest;
this->ComputeDestination(destination, dest);
// Create the files install generator.
m_Makefile->AddInstallGenerator(
new cmInstallFilesGenerator(files, dest.c_str(), programs));
return true;
}
//----------------------------------------------------------------------------
void cmInstallCommand::ComputeDestination(const char* destination,
std::string& dest)

View File

@ -64,10 +64,19 @@ public:
"This command generates installation rules for a project. "
"Rules specified by calls to this command within a source directory "
"are executed in order during installation. "
"The order across directories is not defined.\n"
"There are multiple signatures for this command:\n"
"The order across directories is not defined."
"\n"
"There are multiple signatures for this command. Some of them define "
"installation properties for files and targets. Properties common to "
"multiple signatures are covered here. DESTINATION arguments specify "
"the directory on disk to which a file will be installed. "
"If a full path (with a leading slash or drive letter) is given it "
"is used directly. If a relative path is given it is interpreted "
"relative to the value of CMAKE_INSTALL_PREFIX."
"\n"
"The TARGETS signature:\n"
" INSTALL(TARGETS [targets...] [[LIBRARY|RUNTIME]\n"
" [DESTINATION <destination>]\n"
" [DESTINATION <dir>]\n"
" ] [...])\n"
"The TARGETS form specifies rules for installing targets from a "
"project. There are two kinds of target files that may be "
@ -82,12 +91,8 @@ public:
"apply. If neither is given the installation properties apply to "
"both target types. If only one is given then only targets of that "
"type will be installed (which can be used to install just a DLL or "
"just an import library).\n"
"DESTINATION arguments specify the directory on disk to which the "
"target file will be installed. "
"If a full path (with a leading slash or drive letter) is given it "
"is used directly. If a relative path is given it is interpreted "
"relative to the value of CMAKE_INSTALL_PREFIX.\n"
"just an import library)."
"\n"
"One or more groups of properties may be specified in a single call "
"to the TARGETS form of this command. A target may be installed more "
"than once to different locations. Consider hypothetical "
@ -102,12 +107,33 @@ public:
"installed to <prefix>/bin and /some/full/path and its import library "
"will be installed to <prefix>/lib and /some/full/path. On non-DLL "
"platforms mySharedLib will be installed to <prefix>/lib and "
"/some/full/path.\n"
"/some/full/path."
"\n"
"The FILES signature:\n"
" INSTALL(FILES [files...] DESTINATION <dir>)\n"
"The FILES form specifies rules for installing files for a "
"project. File names given as relative paths are interpreted with "
"respect to the current source directory. Files installed by this "
"form are given the same permissions as the original file by default."
"\n"
"The PROGRAMS signature:\n"
" INSTALL(PROGRAMS [files...] DESTINATION <dir>)\n"
"The PROGRAMS form is identical to the FILES form except that the "
"default permissions for the installed file mark it as executable. "
"This form is intended to install programs that are not targets, "
"such as shell scripts. Use the TARGETS form to install targets "
"built within the project."
"\n"
"The SCRIPT signature:\n"
" INSTALL(SCRIPT <file1> [SCRIPT <file2> [...]])\n"
"The SCRIPT form will invoke the given CMake script files during "
"installation.\n"
"installation. If the script file name is a relative path "
"it will be interpreted with respect to the current source directory."
"\n"
"NOTE: This command supercedes the INSTALL_TARGETS command and the "
"target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. "
"It also replaces the FILES forms of the INSTALL_FILES and "
"INSTALL_PROGRAMS commands. "
"The processing order of these install rules relative to those "
"generated by INSTALL_TARGETS, INSTALL_FILES, and INSTALL_PROGRAMS "
"commands is not defined.\n"
@ -119,6 +145,7 @@ public:
private:
bool HandleScriptMode(std::vector<std::string> const& args);
bool HandleTargetsMode(std::vector<std::string> const& args);
bool HandleFilesMode(std::vector<std::string> const& args);
void ComputeDestination(const char* destination, std::string& dest);
};

View File

@ -52,7 +52,7 @@ public:
*/
virtual const char* GetTerseDocumentation()
{
return "Create install rules for files.";
return "Old installation command. Use the INSTALL command.";
}
/**
@ -69,7 +69,12 @@ public:
virtual const char* GetFullDocumentation()
{
return
" INSTALL_FILES(<dir> extension file file ...)\n"
"This command has been superceded by the INSTALL command. It "
"is provided for compatibility with older CMake code. "
"The FILES form is directly replaced by the FILES form of the "
"INSTALL command. The regexp form can be expressed "
"more clearly using the GLOB form of the FILE command.\n"
" INSTALL_FILES(<dir> extension file file ...)\n"
"Create rules to install the listed files with the given extension "
"into the given directory. "
"Only files existing in the current source tree or its corresponding "

View File

@ -0,0 +1,47 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmInstallFilesGenerator.h"
#include "cmTarget.h"
//----------------------------------------------------------------------------
cmInstallFilesGenerator
::cmInstallFilesGenerator(std::vector<std::string> const& files,
const char* dest, bool programs):
Files(files), Destination(dest), Programs(programs)
{
}
//----------------------------------------------------------------------------
cmInstallFilesGenerator
::~cmInstallFilesGenerator()
{
}
//----------------------------------------------------------------------------
void cmInstallFilesGenerator::GenerateScript(std::ostream& os)
{
// Write code to install the files.
for(std::vector<std::string>::const_iterator fi = this->Files.begin();
fi != this->Files.end(); ++fi)
{
this->AddInstallRule(os, this->Destination.c_str(),
(this->Programs
? cmTarget::INSTALL_PROGRAMS
: cmTarget::INSTALL_FILES), fi->c_str());
}
}

View File

@ -0,0 +1,39 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmInstallFilesGenerator_h
#define cmInstallFilesGenerator_h
#include "cmInstallGenerator.h"
/** \class cmInstallFilesGenerator
* \brief Generate file installation rules.
*/
class cmInstallFilesGenerator: public cmInstallGenerator
{
public:
cmInstallFilesGenerator(std::vector<std::string> const& files,
const char* dest, bool programs);
virtual ~cmInstallFilesGenerator();
protected:
virtual void GenerateScript(std::ostream& os);
std::vector<std::string> Files;
std::string Destination;
bool Programs;
};
#endif

View File

@ -52,7 +52,7 @@ public:
*/
virtual const char* GetTerseDocumentation()
{
return "Create install rules for programs.";
return "Old installation command. Use the INSTALL command.";
}
/**
@ -69,6 +69,11 @@ public:
virtual const char* GetFullDocumentation()
{
return
"This command has been superceded by the INSTALL command. It "
"is provided for compatibility with older CMake code. "
"The FILES form is directly replaced by the PROGRAMS form of the "
"INSTALL command. The regexp form can be expressed more clearly "
"using the GLOB form of the FILE command.\n"
" INSTALL_PROGRAMS(<dir> file1 file2 [file3 ...])\n"
" INSTALL_PROGRAMS(<dir> FILES file1 [file2 ...])\n"
"Create rules to install the listed programs into the given directory. "
@ -78,7 +83,8 @@ public:
"In the second form any program in the current source directory that "
"matches the regular expression will be installed.\n"
"This command is intended to install programs that are not built "
"by cmake, such as shell scripts. See INSTALL_TARGETS to "
"by cmake, such as shell scripts. See the TARGETS form of "
"the INSTALL command to "
"create installation rules for targets built by cmake.\n"
"The directory <dir> is relative to the installation prefix, which "
"is stored in the variable CMAKE_INSTALL_PREFIX.";

View File

@ -19,6 +19,7 @@
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmInstallGenerator.h"
#include "cmInstallFilesGenerator.h"
#include "cmInstallScriptGenerator.h"
#include "cmInstallTargetGenerator.h"
#include "cmMakefile.h"
@ -1679,52 +1680,18 @@ cmLocalGenerator
break;
case cmTarget::INSTALL_FILES:
{
std::string sourcePath = m_Makefile->GetCurrentDirectory();
std::string binaryPath = m_Makefile->GetCurrentOutputDirectory();
sourcePath += "/";
binaryPath += "/";
const std::vector<std::string> &sf = l->second.GetSourceLists();
std::vector<std::string>::const_iterator i;
for (i = sf.begin(); i != sf.end(); ++i)
{
std::string f = *i;
if(f.substr(0, sourcePath.length()) == sourcePath)
{
f = f.substr(sourcePath.length());
}
else if(f.substr(0, binaryPath.length()) == binaryPath)
{
f = f.substr(binaryPath.length());
}
cmInstallGenerator::AddInstallRule(os, destination.c_str(),
cmTarget::INSTALL_FILES,
i->c_str());
}
// Use a file install generator.
cmInstallFilesGenerator g(l->second.GetSourceLists(),
destination.c_str(), false);
g.Generate(os, config, configurationTypes);
}
break;
case cmTarget::INSTALL_PROGRAMS:
{
std::string sourcePath = m_Makefile->GetCurrentDirectory();
std::string binaryPath = m_Makefile->GetCurrentOutputDirectory();
sourcePath += "/";
binaryPath += "/";
const std::vector<std::string> &sf = l->second.GetSourceLists();
std::vector<std::string>::const_iterator i;
for (i = sf.begin(); i != sf.end(); ++i)
{
std::string f = *i;
if(f.substr(0, sourcePath.length()) == sourcePath)
{
f = f.substr(sourcePath.length());
}
else if(f.substr(0, binaryPath.length()) == binaryPath)
{
f = f.substr(binaryPath.length());
}
cmInstallGenerator::AddInstallRule(os, destination.c_str(),
cmTarget::INSTALL_PROGRAMS,
i->c_str());
}
// Use a file install generator.
cmInstallFilesGenerator g(l->second.GetSourceLists(),
destination.c_str(), true);
g.Generate(os, config, configurationTypes);
}
break;
case cmTarget::UTILITY:

View File

@ -90,7 +90,8 @@ ELSE(STAGE2)
INSTALL(TARGETS SimpleInstall test1 test2 test3 test4
RUNTIME DESTINATION bin LIBRARY DESTINATION lib)
INSTALL_FILES(/include FILES lib1.h lib2.h lib3.h)
INSTALL(FILES lib1.h lib2.h DESTINATION include)
INSTALL_FILES(/include FILES lib3.h)
# Test user-specified install scripts.
INSTALL(

View File

@ -90,7 +90,8 @@ ELSE(STAGE2)
INSTALL(TARGETS SimpleInstall test1 test2 test3 test4
RUNTIME DESTINATION bin LIBRARY DESTINATION lib)
INSTALL_FILES(/include FILES lib1.h lib2.h lib3.h)
INSTALL(FILES lib1.h lib2.h DESTINATION include)
INSTALL_FILES(/include FILES lib3.h)
# Test user-specified install scripts.
INSTALL(

View File

@ -98,6 +98,7 @@ CMAKE_CXX_SOURCES="\
cmGlob \
cmLocalGenerator \
cmInstallGenerator \
cmInstallFilesGenerator \
cmInstallScriptGenerator \
cmInstallTargetGenerator \
cmSourceFile \