ENH: Added PERMISSIONS option to the TARGETS mode of the INSTALL command.

This commit is contained in:
Brad King 2006-03-03 19:29:35 -05:00
parent a2e136fd17
commit 06846c4c07
6 changed files with 69 additions and 12 deletions

View File

@ -98,11 +98,14 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// This is the TARGETS mode.
bool doing_targets = true;
bool doing_destination = false;
bool doing_permissions = false;
bool library_settings = true;
bool runtime_settings = true;
std::vector<cmTarget*> targets;
const char* library_destination = 0;
const char* runtime_destination = 0;
std::string library_permissions;
std::string runtime_permissions;
for(unsigned int i=1; i < args.size(); ++i)
{
if(args[i] == "DESTINATION")
@ -110,12 +113,21 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Switch to setting the destination property.
doing_targets = false;
doing_destination = true;
doing_permissions = false;
}
else if(args[i] == "PERMISSIONS")
{
// Switch to setting the permissions property.
doing_targets = false;
doing_destination = false;
doing_permissions = true;
}
else if(args[i] == "LIBRARY")
{
// Switch to setting only library properties.
doing_targets = false;
doing_destination = false;
doing_permissions = false;
library_settings = true;
runtime_settings = false;
}
@ -124,6 +136,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Switch to setting only runtime properties.
doing_targets = false;
doing_destination = false;
doing_permissions = false;
library_settings = false;
runtime_settings = true;
}
@ -171,6 +184,34 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
doing_destination = false;
}
else if(doing_permissions)
{
// Set the permissions in the active set(s) of properties.
if(library_settings)
{
// Check the requested permission.
if(!this->CheckPermissions(args[i], library_permissions))
{
cmOStringStream e;
e << args[0] << " given invalid permission \""
<< args[i] << "\".";
this->SetError(e.str().c_str());
return false;
}
}
if(runtime_settings)
{
// Check the requested permission.
if(!this->CheckPermissions(args[i], runtime_permissions))
{
cmOStringStream e;
e << args[0] << " given invalid permission \""
<< args[i] << "\".";
this->SetError(e.str().c_str());
return false;
}
}
}
else
{
// Unknown argument.
@ -218,13 +259,15 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
{
// The import library uses the LIBRARY properties.
m_Makefile->AddInstallGenerator(
new cmInstallTargetGenerator(target, library_dest.c_str(), true));
new cmInstallTargetGenerator(target, library_dest.c_str(), true,
library_permissions.c_str()));
}
if(runtime_destination)
{
// The DLL uses the RUNTIME properties.
m_Makefile->AddInstallGenerator(
new cmInstallTargetGenerator(target, runtime_dest.c_str(), false));
new cmInstallTargetGenerator(target, runtime_dest.c_str(), false,
runtime_permissions.c_str()));
}
#else
// This is a non-DLL platform.
@ -232,7 +275,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
{
// The shared library uses the LIBRARY properties.
m_Makefile->AddInstallGenerator(
new cmInstallTargetGenerator(target, library_dest.c_str()));
new cmInstallTargetGenerator(target, library_dest.c_str(), false,
library_permissions.c_str()));
}
#endif
}
@ -244,7 +288,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if(library_destination)
{
m_Makefile->AddInstallGenerator(
new cmInstallTargetGenerator(target, library_dest.c_str()));
new cmInstallTargetGenerator(target, library_dest.c_str(), false,
library_permissions.c_str()));
}
else
{
@ -270,7 +315,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if(runtime_destination)
{
m_Makefile->AddInstallGenerator(
new cmInstallTargetGenerator(target, runtime_dest.c_str()));
new cmInstallTargetGenerator(target, runtime_dest.c_str(), false,
runtime_permissions.c_str()));
}
else
{

View File

@ -90,6 +90,7 @@ public:
"The TARGETS signature:\n"
" INSTALL(TARGETS targets... [[LIBRARY|RUNTIME]\n"
" [DESTINATION <dir>]\n"
" [PERMISSIONS permissions...]\n"
" ] [...])\n"
"The TARGETS form specifies rules for installing targets from a "
"project. There are two kinds of target files that may be "

View File

@ -23,8 +23,10 @@
//----------------------------------------------------------------------------
cmInstallTargetGenerator
::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib):
Target(&t), Destination(dest), ImportLibrary(implib)
::cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
const char* permissions):
Target(&t), Destination(dest), ImportLibrary(implib),
Permissions(permissions)
{
this->Target->SetHaveInstallRule(true);
}
@ -158,7 +160,8 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
// Write code to install the target file.
this->AddInstallRule(os, destination.c_str(), type, fromFile.c_str(),
this->ImportLibrary, properties);
this->ImportLibrary, properties,
this->Permissions.c_str());
// Fix the install_name settings in installed binaries.
if(type == cmTarget::SHARED_LIBRARY ||

View File

@ -27,8 +27,8 @@ class cmTarget;
class cmInstallTargetGenerator: public cmInstallGenerator
{
public:
cmInstallTargetGenerator(cmTarget& t, const char* dest,
bool implib = false);
cmInstallTargetGenerator(cmTarget& t, const char* dest, bool implib,
const char* permissions = "");
virtual ~cmInstallTargetGenerator();
protected:
@ -42,6 +42,7 @@ protected:
cmTarget* Target;
std::string Destination;
bool ImportLibrary;
std::string Permissions;
};
#endif

View File

@ -92,8 +92,11 @@ ELSE(STAGE2)
ADD_DEPENDENCIES(test2 test3)
ADD_DEPENDENCIES(test4 test2)
INSTALL(TARGETS SimpleInstall test1 test2 test3 test4
INSTALL(TARGETS SimpleInstall test1 test2 test3
RUNTIME DESTINATION bin LIBRARY DESTINATION lib)
INSTALL(TARGETS test4
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
LIBRARY DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE)
INSTALL(FILES lib1.h DESTINATION include/foo)
INSTALL(FILES lib2.h
DESTINATION include/foo

View File

@ -92,8 +92,11 @@ ELSE(STAGE2)
ADD_DEPENDENCIES(test2 test3)
ADD_DEPENDENCIES(test4 test2)
INSTALL(TARGETS SimpleInstall test1 test2 test3 test4
INSTALL(TARGETS SimpleInstall test1 test2 test3
RUNTIME DESTINATION bin LIBRARY DESTINATION lib)
INSTALL(TARGETS test4
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
LIBRARY DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE)
INSTALL(FILES lib1.h DESTINATION include/foo)
INSTALL(FILES lib2.h
DESTINATION include/foo