ENH: Added OPTIONAL option to INSTALL command to allow installation of files if they exist while ignoring them otherwise. This addresses bug#2922.
This commit is contained in:
parent
16b781360c
commit
934c804ea4
|
@ -151,6 +151,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
std::vector<std::string> archive_configurations;
|
std::vector<std::string> archive_configurations;
|
||||||
std::vector<std::string> library_configurations;
|
std::vector<std::string> library_configurations;
|
||||||
std::vector<std::string> runtime_configurations;
|
std::vector<std::string> runtime_configurations;
|
||||||
|
bool archive_optional = false;
|
||||||
|
bool library_optional = false;
|
||||||
|
bool runtime_optional = false;
|
||||||
for(unsigned int i=1; i < args.size(); ++i)
|
for(unsigned int i=1; i < args.size(); ++i)
|
||||||
{
|
{
|
||||||
if(args[i] == "DESTINATION")
|
if(args[i] == "DESTINATION")
|
||||||
|
@ -225,6 +228,27 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
library_settings = false;
|
library_settings = false;
|
||||||
runtime_settings = true;
|
runtime_settings = true;
|
||||||
}
|
}
|
||||||
|
else if(args[i] == "OPTIONAL")
|
||||||
|
{
|
||||||
|
// Set the optional property.
|
||||||
|
doing_targets = false;
|
||||||
|
doing_destination = false;
|
||||||
|
doing_permissions = false;
|
||||||
|
doing_component = false;
|
||||||
|
doing_configurations = false;
|
||||||
|
if(archive_settings)
|
||||||
|
{
|
||||||
|
archive_optional = true;
|
||||||
|
}
|
||||||
|
if(library_settings)
|
||||||
|
{
|
||||||
|
library_optional = true;
|
||||||
|
}
|
||||||
|
if(runtime_settings)
|
||||||
|
{
|
||||||
|
runtime_optional = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(doing_targets)
|
else if(doing_targets)
|
||||||
{
|
{
|
||||||
// Lookup this target in the current directory.
|
// Lookup this target in the current directory.
|
||||||
|
@ -404,7 +428,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
new cmInstallTargetGenerator(target, archive_dest.c_str(), true,
|
new cmInstallTargetGenerator(target, archive_dest.c_str(), true,
|
||||||
archive_permissions.c_str(),
|
archive_permissions.c_str(),
|
||||||
archive_configurations,
|
archive_configurations,
|
||||||
archive_component.c_str()));
|
archive_component.c_str(),
|
||||||
|
archive_optional));
|
||||||
}
|
}
|
||||||
if(runtime_destination)
|
if(runtime_destination)
|
||||||
{
|
{
|
||||||
|
@ -414,7 +439,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
false,
|
false,
|
||||||
runtime_permissions.c_str(),
|
runtime_permissions.c_str(),
|
||||||
runtime_configurations,
|
runtime_configurations,
|
||||||
runtime_component.c_str()));
|
runtime_component.c_str(),
|
||||||
|
runtime_optional));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -428,7 +454,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
false,
|
false,
|
||||||
library_permissions.c_str(),
|
library_permissions.c_str(),
|
||||||
library_configurations,
|
library_configurations,
|
||||||
library_component.c_str()));
|
library_component.c_str(),
|
||||||
|
library_optional));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -450,7 +477,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
new cmInstallTargetGenerator(target, archive_dest.c_str(), false,
|
new cmInstallTargetGenerator(target, archive_dest.c_str(), false,
|
||||||
archive_permissions.c_str(),
|
archive_permissions.c_str(),
|
||||||
archive_configurations,
|
archive_configurations,
|
||||||
archive_component.c_str()));
|
archive_component.c_str(),
|
||||||
|
archive_optional));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -471,7 +499,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
new cmInstallTargetGenerator(target, library_dest.c_str(), false,
|
new cmInstallTargetGenerator(target, library_dest.c_str(), false,
|
||||||
library_permissions.c_str(),
|
library_permissions.c_str(),
|
||||||
library_configurations,
|
library_configurations,
|
||||||
library_component.c_str()));
|
library_component.c_str(),
|
||||||
|
library_optional));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -492,7 +521,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
|
||||||
new cmInstallTargetGenerator(target, runtime_dest.c_str(), false,
|
new cmInstallTargetGenerator(target, runtime_dest.c_str(), false,
|
||||||
runtime_permissions.c_str(),
|
runtime_permissions.c_str(),
|
||||||
runtime_configurations,
|
runtime_configurations,
|
||||||
runtime_component.c_str()));
|
runtime_component.c_str(),
|
||||||
|
runtime_optional));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -540,6 +570,7 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
|
||||||
std::string permissions;
|
std::string permissions;
|
||||||
std::vector<std::string> configurations;
|
std::vector<std::string> configurations;
|
||||||
std::string component;
|
std::string component;
|
||||||
|
bool optional = false;
|
||||||
for(unsigned int i=1; i < args.size(); ++i)
|
for(unsigned int i=1; i < args.size(); ++i)
|
||||||
{
|
{
|
||||||
if(args[i] == "DESTINATION")
|
if(args[i] == "DESTINATION")
|
||||||
|
@ -592,6 +623,17 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
|
||||||
doing_component = false;
|
doing_component = false;
|
||||||
doing_rename = true;
|
doing_rename = true;
|
||||||
}
|
}
|
||||||
|
else if(args[i] == "OPTIONAL")
|
||||||
|
{
|
||||||
|
// Set the optional property.
|
||||||
|
doing_files = false;
|
||||||
|
doing_destination = false;
|
||||||
|
doing_permissions = false;
|
||||||
|
doing_configurations = false;
|
||||||
|
doing_component = false;
|
||||||
|
doing_rename = false;
|
||||||
|
optional = true;
|
||||||
|
}
|
||||||
else if(doing_files)
|
else if(doing_files)
|
||||||
{
|
{
|
||||||
// Convert this file to a full path.
|
// Convert this file to a full path.
|
||||||
|
@ -686,7 +728,8 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
|
||||||
this->Makefile->AddInstallGenerator(
|
this->Makefile->AddInstallGenerator(
|
||||||
new cmInstallFilesGenerator(files, dest.c_str(), programs,
|
new cmInstallFilesGenerator(files, dest.c_str(), programs,
|
||||||
permissions.c_str(), configurations,
|
permissions.c_str(), configurations,
|
||||||
component.c_str(), rename.c_str()));
|
component.c_str(), rename.c_str(),
|
||||||
|
optional));
|
||||||
|
|
||||||
// Tell the global generator about any installation component names
|
// Tell the global generator about any installation component names
|
||||||
// specified.
|
// specified.
|
||||||
|
|
|
@ -93,6 +93,8 @@ public:
|
||||||
"The RENAME argument specifies a name for an installed file that "
|
"The RENAME argument specifies a name for an installed file that "
|
||||||
"may be different from the original file. Renaming is allowed only "
|
"may be different from the original file. Renaming is allowed only "
|
||||||
"when a single file is installed by the command. "
|
"when a single file is installed by the command. "
|
||||||
|
"The OPTIONAL argument specifies that it is not an error if the "
|
||||||
|
"file to be installed does not exist. "
|
||||||
"\n"
|
"\n"
|
||||||
"The TARGETS signature:\n"
|
"The TARGETS signature:\n"
|
||||||
" INSTALL(TARGETS targets...\n"
|
" INSTALL(TARGETS targets...\n"
|
||||||
|
@ -101,6 +103,7 @@ public:
|
||||||
" [PERMISSIONS permissions...]\n"
|
" [PERMISSIONS permissions...]\n"
|
||||||
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
||||||
" [COMPONENT <component>]\n"
|
" [COMPONENT <component>]\n"
|
||||||
|
" [OPTIONAL]\n"
|
||||||
" ] [...])\n"
|
" ] [...])\n"
|
||||||
"The TARGETS form specifies rules for installing targets from a "
|
"The TARGETS form specifies rules for installing targets from a "
|
||||||
"project. There are three kinds of target files that may be "
|
"project. There are three kinds of target files that may be "
|
||||||
|
@ -146,7 +149,7 @@ public:
|
||||||
" [PERMISSIONS permissions...]\n"
|
" [PERMISSIONS permissions...]\n"
|
||||||
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
||||||
" [COMPONENT <component>]\n"
|
" [COMPONENT <component>]\n"
|
||||||
" [RENAME <name>])\n"
|
" [RENAME <name>] [OPTIONAL])\n"
|
||||||
"The FILES form specifies rules for installing files for a "
|
"The FILES form specifies rules for installing files for a "
|
||||||
"project. File names given as relative paths are interpreted with "
|
"project. File names given as relative paths are interpreted with "
|
||||||
"respect to the current source directory. Files installed by this "
|
"respect to the current source directory. Files installed by this "
|
||||||
|
@ -158,7 +161,7 @@ public:
|
||||||
" [PERMISSIONS permissions...]\n"
|
" [PERMISSIONS permissions...]\n"
|
||||||
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
" [CONFIGURATIONS [Debug|Release|...]]\n"
|
||||||
" [COMPONENT <component>]\n"
|
" [COMPONENT <component>]\n"
|
||||||
" [RENAME <name>])\n"
|
" [RENAME <name>] [OPTIONAL])\n"
|
||||||
"The PROGRAMS form is identical to the FILES form except that the "
|
"The PROGRAMS form is identical to the FILES form except that the "
|
||||||
"default permissions for the installed file also include "
|
"default permissions for the installed file also include "
|
||||||
"OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. "
|
"OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. "
|
||||||
|
|
|
@ -25,10 +25,11 @@ cmInstallFilesGenerator
|
||||||
const char* file_permissions,
|
const char* file_permissions,
|
||||||
std::vector<std::string> const& configurations,
|
std::vector<std::string> const& configurations,
|
||||||
const char* component,
|
const char* component,
|
||||||
const char* rename):
|
const char* rename,
|
||||||
|
bool optional):
|
||||||
Files(files), Destination(dest), Programs(programs),
|
Files(files), Destination(dest), Programs(programs),
|
||||||
FilePermissions(file_permissions), Configurations(configurations),
|
FilePermissions(file_permissions), Configurations(configurations),
|
||||||
Component(component), Rename(rename)
|
Component(component), Rename(rename), Optional(optional)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,14 +46,13 @@ void cmInstallFilesGenerator::GenerateScript(std::ostream& os)
|
||||||
for(std::vector<std::string>::const_iterator fi = this->Files.begin();
|
for(std::vector<std::string>::const_iterator fi = this->Files.begin();
|
||||||
fi != this->Files.end(); ++fi)
|
fi != this->Files.end(); ++fi)
|
||||||
{
|
{
|
||||||
bool not_optional = false;
|
|
||||||
const char* no_properties = 0;
|
const char* no_properties = 0;
|
||||||
const char* no_dir_permissions = 0;
|
const char* no_dir_permissions = 0;
|
||||||
this->AddInstallRule(os, this->Destination.c_str(),
|
this->AddInstallRule(os, this->Destination.c_str(),
|
||||||
(this->Programs
|
(this->Programs
|
||||||
? cmTarget::INSTALL_PROGRAMS
|
? cmTarget::INSTALL_PROGRAMS
|
||||||
: cmTarget::INSTALL_FILES), fi->c_str(),
|
: cmTarget::INSTALL_FILES), fi->c_str(),
|
||||||
not_optional, no_properties,
|
this->Optional, no_properties,
|
||||||
this->FilePermissions.c_str(), no_dir_permissions,
|
this->FilePermissions.c_str(), no_dir_permissions,
|
||||||
this->Configurations,
|
this->Configurations,
|
||||||
this->Component.c_str(),
|
this->Component.c_str(),
|
||||||
|
|
|
@ -30,7 +30,8 @@ public:
|
||||||
const char* file_permissions,
|
const char* file_permissions,
|
||||||
std::vector<std::string> const& configurations,
|
std::vector<std::string> const& configurations,
|
||||||
const char* component,
|
const char* component,
|
||||||
const char* rename);
|
const char* rename,
|
||||||
|
bool optional = false);
|
||||||
virtual ~cmInstallFilesGenerator();
|
virtual ~cmInstallFilesGenerator();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -42,6 +43,7 @@ protected:
|
||||||
std::vector<std::string> Configurations;
|
std::vector<std::string> Configurations;
|
||||||
std::string Component;
|
std::string Component;
|
||||||
std::string Rename;
|
std::string Rename;
|
||||||
|
bool Optional;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,10 +27,10 @@ cmInstallTargetGenerator
|
||||||
::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
|
::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
|
||||||
const char* file_permissions,
|
const char* file_permissions,
|
||||||
std::vector<std::string> const& configurations,
|
std::vector<std::string> const& configurations,
|
||||||
const char* component):
|
const char* component, bool optional):
|
||||||
Target(&t), Destination(dest), ImportLibrary(implib),
|
Target(&t), Destination(dest), ImportLibrary(implib),
|
||||||
FilePermissions(file_permissions), Configurations(configurations),
|
FilePermissions(file_permissions), Configurations(configurations),
|
||||||
Component(component)
|
Component(component), Optional(optional)
|
||||||
{
|
{
|
||||||
this->Target->SetHaveInstallRule(true);
|
this->Target->SetHaveInstallRule(true);
|
||||||
}
|
}
|
||||||
|
@ -162,8 +162,9 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
|
||||||
// Write code to install the target file.
|
// Write code to install the target file.
|
||||||
const char* no_dir_permissions = 0;
|
const char* no_dir_permissions = 0;
|
||||||
const char* no_rename = 0;
|
const char* no_rename = 0;
|
||||||
|
bool optional = this->Optional | this->ImportLibrary;
|
||||||
this->AddInstallRule(os, destination.c_str(), type, fromFile.c_str(),
|
this->AddInstallRule(os, destination.c_str(), type, fromFile.c_str(),
|
||||||
this->ImportLibrary, properties,
|
optional, properties,
|
||||||
this->FilePermissions.c_str(), no_dir_permissions,
|
this->FilePermissions.c_str(), no_dir_permissions,
|
||||||
this->Configurations,
|
this->Configurations,
|
||||||
this->Component.c_str(),
|
this->Component.c_str(),
|
||||||
|
|
|
@ -32,7 +32,8 @@ public:
|
||||||
const char* file_permissions = "",
|
const char* file_permissions = "",
|
||||||
std::vector<std::string> const& configurations
|
std::vector<std::string> const& configurations
|
||||||
= std::vector<std::string>(),
|
= std::vector<std::string>(),
|
||||||
const char* component = ""
|
const char* component = "",
|
||||||
|
bool optional = false
|
||||||
);
|
);
|
||||||
virtual ~cmInstallTargetGenerator();
|
virtual ~cmInstallTargetGenerator();
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ protected:
|
||||||
std::string FilePermissions;
|
std::string FilePermissions;
|
||||||
std::vector<std::string> Configurations;
|
std::vector<std::string> Configurations;
|
||||||
std::string Component;
|
std::string Component;
|
||||||
|
bool Optional;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -166,6 +166,9 @@ ELSE(STAGE2)
|
||||||
)
|
)
|
||||||
INSTALL_FILES(/MyTest/include FILES lib3.h)
|
INSTALL_FILES(/MyTest/include FILES lib3.h)
|
||||||
|
|
||||||
|
# Test optional installation.
|
||||||
|
INSTALL(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
|
||||||
|
|
||||||
# Test configuration-specific installation.
|
# Test configuration-specific installation.
|
||||||
INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
|
INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
|
||||||
DESTINATION MyTest/include/Release
|
DESTINATION MyTest/include/Release
|
||||||
|
|
|
@ -166,6 +166,9 @@ ELSE(STAGE2)
|
||||||
)
|
)
|
||||||
INSTALL_FILES(/MyTest/include FILES lib3.h)
|
INSTALL_FILES(/MyTest/include FILES lib3.h)
|
||||||
|
|
||||||
|
# Test optional installation.
|
||||||
|
INSTALL(FILES does_not_exist.h DESTINATION MyTest/include/foo OPTIONAL)
|
||||||
|
|
||||||
# Test configuration-specific installation.
|
# Test configuration-specific installation.
|
||||||
INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
|
INSTALL(FILES lib1.h RENAME lib1release.h CONFIGURATIONS Release
|
||||||
DESTINATION MyTest/include/Release
|
DESTINATION MyTest/include/Release
|
||||||
|
|
Loading…
Reference in New Issue