Commit 83ec8c35 authored by David Cole's avatar David Cole

ENH: Further refinement of the CPack components functionality from Doug Gregor.

Details:
==========

 - New cpack_add_component, cpack_add_component_group, and
cpack_add_install_type "commands" defined as macros in the CPack
module.
 - Documentation for all of the variables and commands in the CPack module.
 - Added get_cmake_property(... COMPONENTS) to CMake to ask for the
names of all components. Used in the CPack module to automatically
build component-based installers. (Set CPACK_MONOLITHIC_INSTALL to
turn off component-based installation).
 - A group can declare its PARENT_GROUP, to build an arbitrary
hierarchy of groups.
 - New CPack command cpack_configure_downloads, which creates an
installer that downloads only the selected components on-the-fly.
Those components marked DOWNLOADED will be separate packages
downloaded on-the-fly (or, all packages can be marked as such with the
ALL option to cpack_configure_downloads). Individual components are
compressed with ZIP at installer-creation time and
downloaded/uncompressed by the installer as needed. This feature is
only available on Windows with NSIS at the moment.
 - NSIS installers can install themselves and enable the "Change"
button in Add/Remove programs, allowing users to go back and install
or remove components. This can be disabled through
cpack_configure_downloads, because it's only really useful is most of
the application's functionality is in downloaded components.
 - Bug fix: automatically install everything whose COMPONENT was not
specified (it's a hidden, required group)
 - Bug fix: fixed removal of components when re-running the NSIS
installer and unchecking components
 - Bug fix: NSIS installers now only install/remove the minimal
number of files when re-run to update the installation (or by clicking
"Change" in Add/Remove programs)
parent 75154920
This diff is collapsed.
......@@ -37,6 +37,8 @@
;Set compression
SetCompressor @CPACK_NSIS_COMPRESSOR@
@CPACK_NSIS_DEFINES@
!include Sections.nsh
;--- Component support macros: ---
......@@ -60,6 +62,11 @@ Var AR_RegFlags
IntOp $R0 0 + $${VarName}
!macroend
; Sets the value of a variable
!macro StoreVar VarName IntValue
IntOp $${VarName} 0 + ${IntValue}
!macroend
!macro InitSection SecName
; This macro reads component installed flag from the registry and
;changes checked state of the section on the components page.
......@@ -76,9 +83,13 @@ Var AR_RegFlags
IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off
IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit
; Note whether this component was installed before
!insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags
IntOp $R0 $AR_RegFlags & $AR_RegFlags
;Writing modified flags
SectionSetFlags ${${SecName}} $AR_SecFlags
"default_${SecName}:"
!insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected
!macroend
......@@ -460,6 +471,33 @@ Function ConditionalAddToRegisty
ConditionalAddToRegisty_EmptyString:
FunctionEnd
;--------------------------------
!ifdef CPACK_USES_DOWNLOAD
Function DownloadFile
IfFileExists $INSTDIR\* +2
CreateDirectory $INSTDIR
Pop $0
; Skip if already downloaded
IfFileExists $INSTDIR\$0 0 +2
Return
StrCpy $1 "@CPACK_DOWNLOAD_SITE@"
try_again:
NSISdl::download "$1/$0" "$INSTDIR\$0"
Pop $1
StrCmp $1 "success" success
StrCmp $1 "Cancelled" cancel
MessageBox MB_OK "Download failed: $1"
cancel:
Return
success:
FunctionEnd
!endif
;--------------------------------
; Installation types
@CPACK_NSIS_INSTALLATION_TYPES@
......@@ -519,7 +557,7 @@ Section "-Core installation"
;list of directories here in sync with the RMDir commands below.
SetOutPath "$INSTDIR"
@CPACK_NSIS_FULL_INSTALL@
;Store installation folder
WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR
......@@ -537,7 +575,20 @@ Section "-Core installation"
Push "UninstallString"
Push "$INSTDIR\Uninstall.exe"
Call ConditionalAddToRegisty
Push "NoRepair"
Push "1"
Call ConditionalAddToRegisty
!ifdef CPACK_NSIS_ADD_REMOVE
;Create add/remove functionality
Push "ModifyPath"
Push "$INSTDIR\AddRemove.exe"
Call ConditionalAddToRegisty
!else
Push "NoModify"
Push "1"
Call ConditionalAddToRegisty
!endif
; Optional registration
Push "DisplayIcon"
......@@ -640,6 +691,23 @@ FunctionEnd
Section -FinishComponents
;Removes unselected components and writes component status to registry
!insertmacro SectionList "FinishSection"
!ifdef CPACK_NSIS_ADD_REMOVE
; Get the name of the installer executable
System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
StrCpy $R3 $R0
; Strip off the last 13 characters, to see if we have AddRemove.exe
StrLen $R1 $R0
IntOp $R1 $R0 - 13
StrCpy $R2 $R0 13 $R1
StrCmp $R2 "AddRemove.exe" addremove_installed
; We're not running AddRemove.exe, so install it
CopyFiles $R3 $INSTDIR\AddRemove.exe
addremove_installed:
!endif
SectionEnd
;--- End of Add/Remove callback functions ---
......@@ -674,6 +742,11 @@ Section "Uninstall"
@CPACK_NSIS_DELETE_FILES@
@CPACK_NSIS_DELETE_DIRECTORIES@
!ifdef CPACK_NSIS_ADD_REMOVE
;Remove the add/remove program
Delete "$INSTDIR\AddRemove.exe"
!endif
;Remove the uninstaller itself.
Delete "$INSTDIR\Uninstall.exe"
DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
......
......@@ -70,12 +70,20 @@ public:
/// Whether this component defaults to "disabled".
bool IsDisabledByDefault : 1;
/// Whether this component should be downloaded on-the-fly. If false,
/// the component will be a part of the installation package.
bool IsDownloaded : 1;
/// A description of this component.
std::string Description;
/// The installation types that this component is a part of.
std::vector<cmCPackInstallationType *> InstallationTypes;
/// If IsDownloaded is true, the name of the archive file that
/// contains the files that are part of this component.
std::string ArchiveFile;
/// The components that this component depends on.
std::vector<cmCPackComponent *> Dependencies;
......@@ -95,6 +103,8 @@ public:
class cmCPackComponentGroup
{
public:
cmCPackComponentGroup() : ParentGroup(0) { }
/// The name of the group (used to reference the group).
std::string Name;
......@@ -112,6 +122,12 @@ public:
/// The components within this group.
std::vector<cmCPackComponent*> Components;
/// The parent group of this component group (if any).
cmCPackComponentGroup *ParentGroup;
/// The subgroups of this group.
std::vector<cmCPackComponentGroup*> Subgroups;
};
#endif
......@@ -653,6 +653,14 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
}
mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
{
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem creating temporary directory: "
<< dir << std::endl);
return 0;
}
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
<< std::endl);
......@@ -664,6 +672,14 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
{
mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
if ( !cmsys::SystemTools::MakeDirectory(tempInstallDirectory.c_str()))
{
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem creating temporary directory: "
<< tempInstallDirectory << std::endl);
return 0;
}
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"- Using non-DESTDIR install... (mf->AddDefinition)" << std::endl);
cmCPackLogger(cmCPackLog::LOG_DEBUG,
......@@ -1255,6 +1271,16 @@ cmCPackGenerator::GetComponent(const char *projectName, const char *name)
= this->IsSet((macroPrefix + "_REQUIRED").c_str());
component->IsDisabledByDefault
= this->IsSet((macroPrefix + "_DISABLED").c_str());
component->IsDownloaded
= this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
|| cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
const char* archiveFile = this->GetOption((macroPrefix + "_ARCHIVE_FILE").c_str());
if (archiveFile && *archiveFile)
{
component->ArchiveFile = archiveFile;
}
const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
if (groupName && *groupName)
{
......@@ -1344,6 +1370,17 @@ cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
= this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
group->IsExpandedByDefault
= this->IsSet((macroPrefix + "_EXPANDED").c_str());
const char* parentGroupName
= this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
if (parentGroupName && *parentGroupName)
{
group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
group->ParentGroup->Subgroups.push_back(group);
}
else
{
group->ParentGroup = 0;
}
}
return group;
}
This diff is collapsed.
......@@ -53,24 +53,30 @@ protected:
virtual bool SupportsComponentInstallation() const;
/// Produce a string that contains the NSIS code to describe a
/// particular component.
std::string CreateComponentDescription(cmCPackComponent *component) const;
/// particular component. Any added macros will be emitted via
/// macrosOut.
std::string
CreateComponentDescription(cmCPackComponent *component,
cmOStringStream& macrosOut);
/// Produce NSIS code that selects all of the components that this component
/// depends on, recursively.
std::string CreateSelectionDependenciesDescription
(cmCPackComponent *component,
std::set<cmCPackComponent *>& visited) const;
std::set<cmCPackComponent *>& visited);
/// Produce NSIS code that de-selects all of the components that are dependent
/// on this component, recursively.
std::string CreateDeselectionDependenciesDescription
(cmCPackComponent *component,
std::set<cmCPackComponent *>& visited) const;
std::set<cmCPackComponent *>& visited);
/// Produce a string that contains the NSIS code to describe a
/// particular component group, including its components.
std::string CreateComponentGroupDescription(cmCPackComponentGroup *group) const;
/// particular component group, including its components. Any
/// added macros will be emitted via macrosOut.
std::string
CreateComponentGroupDescription(cmCPackComponentGroup *group,
cmOStringStream& macrosOut);
/// Translations any newlines found in the string into \r\n, so that the
/// resulting string can be used within NSIS.
......
......@@ -580,7 +580,10 @@ WriteDistributionFile(const char* metapackageFile)
groupIt != this->ComponentGroups.end();
++groupIt)
{
CreateChoiceOutline(groupIt->second, choiceOut);
if (groupIt->second.ParentGroup == 0)
{
CreateChoiceOutline(groupIt->second, choiceOut);
}
}
// Emit the outline for the non-grouped components
......@@ -622,6 +625,13 @@ cmCPackPackageMakerGenerator::
CreateChoiceOutline(const cmCPackComponentGroup& group, cmOStringStream& out)
{
out << "<line choice=\"" << group.Name << "Choice\">" << std::endl;
std::vector<cmCPackComponentGroup*>::const_iterator groupIt;
for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end();
++groupIt)
{
CreateChoiceOutline(**groupIt, out);
}
std::vector<cmCPackComponent*>::const_iterator compIt;
for (compIt = group.Components.begin(); compIt != group.Components.end();
++compIt)
......
......@@ -49,6 +49,22 @@ bool cmGetCMakePropertyCommand
{
this->Makefile->GetListOfMacros(output);
}
else if ( args[1] == "COMPONENTS" )
{
const std::set<cmStdString>* components
= this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->GetInstallComponents();
std::set<cmStdString>::const_iterator compIt;
output = "";
for (compIt = components->begin(); compIt != components->end(); ++compIt)
{
if (compIt != components->begin())
{
output += ";";
}
output += *compIt;
}
}
else
{
const char *prop =
......
......@@ -62,7 +62,8 @@ public:
"Get a property from the CMake instance. The value of the "
"property is stored in the variable VAR. If the property is "
"not found, CMake will report an error. Some supported properties "
"include: VARIABLES, CACHE_VARIABLES, COMMANDS, and MACROS.";
"include: VARIABLES, CACHE_VARIABLES, COMMANDS, MACROS, and "
"COMPONENTS.";
}
cmTypeMacro(cmGetCMakePropertyCommand, cmCommand);
......
......@@ -139,6 +139,9 @@ public:
void AddInstallComponent(const char* component);
const std::set<cmStdString>* GetInstallComponents() const
{ return &InstallComponents; }
///! Add one installed target to the sets of the exports
void AddTargetToExports(const char* exportSet, cmTarget* target,
cmInstallTargetGenerator* archive,
......
......@@ -384,6 +384,17 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
}
// Keep track of whether we will be performing an installation of
// any files of the given type.
bool installsArchive = false;
bool installsLibrary = false;
bool installsRuntime = false;
bool installsFramework = false;
bool installsBundle = false;
bool installsPrivateHeader = false;
bool installsPublicHeader = false;
bool installsResource = false;
// Generate install script code to install the given targets.
for(std::vector<cmTarget*>::iterator ti = targets.begin();
ti != targets.end(); ++ti)
......@@ -691,6 +702,16 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
}
// Keep track of whether we're installing anything in each category
installsArchive = installsArchive || archiveGenerator != 0;
installsLibrary = installsLibrary || libraryGenerator != 0;
installsRuntime = installsRuntime || runtimeGenerator != 0;
installsFramework = installsFramework || frameworkGenerator != 0;
installsBundle = installsBundle || bundleGenerator != 0;
installsPrivateHeader = installsPrivateHeader || privateHeaderGenerator != 0;
installsPublicHeader = installsPublicHeader || publicHeaderGenerator != 0;
installsResource = installsResource || resourceGenerator;
this->Makefile->AddInstallGenerator(archiveGenerator);
this->Makefile->AddInstallGenerator(libraryGenerator);
this->Makefile->AddInstallGenerator(runtimeGenerator);
......@@ -713,22 +734,46 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
// Tell the global generator about any installation component names specified
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(archiveArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(libraryArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(runtimeArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(frameworkArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(bundleArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(resourceArgs.GetComponent().c_str());
if (installsArchive)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(archiveArgs.GetComponent().c_str());
}
if (installsLibrary)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(libraryArgs.GetComponent().c_str());
}
if (installsRuntime)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(runtimeArgs.GetComponent().c_str());
}
if (installsFramework)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(frameworkArgs.GetComponent().c_str());
}
if (installsBundle)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(bundleArgs.GetComponent().c_str());
}
if (installsPrivateHeader)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
}
if (installsPublicHeader)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
}
if (installsResource)
{
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent(resourceArgs.GetComponent().c_str());
}
return true;
}
......
......@@ -59,6 +59,9 @@ bool cmInstallFilesCommand
}
}
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent("Unspecified");
return true;
}
......@@ -126,7 +129,7 @@ void cmInstallFilesCommand::CreateInstallGenerator() const
// Use a file install generator.
const char* no_permissions = "";
const char* no_rename = "";
const char* no_component = "";
const char* no_component = "Unspecified";
std::vector<std::string> no_configurations;
this->Makefile->AddInstallGenerator(
new cmInstallFilesGenerator(this->Files,
......
......@@ -38,6 +38,9 @@ bool cmInstallProgramsCommand
this->FinalArgs.push_back(*s);
}
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent("Unspecified");
return true;
}
......@@ -87,7 +90,7 @@ void cmInstallProgramsCommand::FinalPass()
// Use a file install generator.
const char* no_permissions = "";
const char* no_rename = "";
const char* no_component = "";
const char* no_component = "Unspecified";
std::vector<std::string> no_configurations;
this->Makefile->AddInstallGenerator(
new cmInstallFilesGenerator(this->Files,
......
......@@ -31,7 +31,7 @@ public:
const char* file_permissions = "",
std::vector<std::string> const& configurations
= std::vector<std::string>(),
const char* component = "",
const char* component = "Unspecified",
bool optional = false
);
virtual ~cmInstallTargetGenerator();
......
......@@ -62,6 +62,9 @@ bool cmInstallTargetsCommand
}
}
this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->AddInstallComponent("Unspecified");
return true;
}
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