2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
#include "cmCPackNSISGenerator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCPackComponentGroup.h"
|
2016-09-07 01:21:35 +03:00
|
|
|
#include "cmCPackGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCPackLog.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmSystemTools.h"
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2016-09-07 01:21:35 +03:00
|
|
|
#include <algorithm>
|
2006-02-16 23:20:23 +03:00
|
|
|
#include <cmsys/Directory.hxx>
|
2006-02-23 17:38:40 +03:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2016-09-07 01:21:35 +03:00
|
|
|
#include <map>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <utility>
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2007-06-18 17:00:33 +04:00
|
|
|
/* NSIS uses different command line syntax on Windows and others */
|
|
|
|
#ifdef _WIN32
|
2016-05-16 17:34:04 +03:00
|
|
|
#define NSIS_OPT "/"
|
2007-06-18 17:00:33 +04:00
|
|
|
#else
|
2016-05-16 17:34:04 +03:00
|
|
|
#define NSIS_OPT "-"
|
2007-06-18 17:00:33 +04:00
|
|
|
#endif
|
|
|
|
|
2012-05-09 23:33:44 +04:00
|
|
|
cmCPackNSISGenerator::cmCPackNSISGenerator(bool nsis64)
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2012-05-09 23:33:44 +04:00
|
|
|
Nsis64 = nsis64;
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackNSISGenerator::~cmCPackNSISGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:48:39 +04:00
|
|
|
int cmCPackNSISGenerator::PackageFiles()
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2010-08-11 21:48:39 +04:00
|
|
|
// TODO: Fix nsis to force out file name
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
std::string nsisInFileName = this->FindTemplate("NSIS.template.in");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (nsisInFileName.empty()) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"CPack error: Could not find NSIS installer template file."
|
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
std::string nsisInInstallOptions =
|
|
|
|
this->FindTemplate("NSIS.InstallOptions.ini.in");
|
|
|
|
if (nsisInInstallOptions.empty()) {
|
2006-04-30 03:22:21 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"CPack error: Could not find NSIS installer options file."
|
|
|
|
<< std::endl);
|
2006-04-30 03:22:21 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-05-14 22:26:15 +04:00
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
std::string tmpFile = nsisFileName;
|
|
|
|
tmpFile += "/NSISOutput.log";
|
2006-04-30 03:22:21 +04:00
|
|
|
std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini";
|
2006-01-02 07:21:05 +03:00
|
|
|
nsisFileName += "/project.nsi";
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream str;
|
2006-02-16 23:20:23 +03:00
|
|
|
std::vector<std::string>::const_iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = files.begin(); it != files.end(); ++it) {
|
2016-09-23 10:28:35 +03:00
|
|
|
std::string outputDir = "$INSTDIR";
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string fileN =
|
|
|
|
cmSystemTools::RelativePath(toplevel.c_str(), it->c_str());
|
|
|
|
if (!this->Components.empty()) {
|
2016-09-23 10:28:35 +03:00
|
|
|
const std::string::size_type pos = fileN.find('/');
|
|
|
|
|
|
|
|
// Use the custom component install directory if we have one
|
|
|
|
if (pos != std::string::npos) {
|
|
|
|
const std::string componentName = fileN.substr(0, pos);
|
|
|
|
outputDir = CustomComponentInstallDirectory(componentName);
|
|
|
|
} else {
|
|
|
|
outputDir = CustomComponentInstallDirectory(fileN);
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
// Strip off the component part of the path.
|
2016-09-23 10:28:35 +03:00
|
|
|
fileN = fileN.substr(pos + 1, std::string::npos);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(fileN.begin(), fileN.end(), '/', '\\');
|
2016-09-23 10:28:35 +03:00
|
|
|
|
|
|
|
str << " Delete \"" << outputDir << "\\" << fileN << "\"" << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " << str.str()
|
|
|
|
<< std::endl);
|
2006-05-02 16:49:01 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str());
|
2006-02-16 23:20:23 +03:00
|
|
|
std::vector<std::string> dirs;
|
2010-08-11 21:48:39 +04:00
|
|
|
this->GetListOfSubdirectories(toplevel.c_str(), dirs);
|
2006-02-16 23:20:23 +03:00
|
|
|
std::vector<std::string>::const_iterator sit;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream dstr;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (sit = dirs.begin(); sit != dirs.end(); ++sit) {
|
2008-06-17 19:39:26 +04:00
|
|
|
std::string componentName;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string fileN =
|
|
|
|
cmSystemTools::RelativePath(toplevel.c_str(), sit->c_str());
|
|
|
|
if (fileN.empty()) {
|
2006-02-16 23:20:23 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!Components.empty()) {
|
2012-08-13 21:42:58 +04:00
|
|
|
// If this is a component installation, strip off the component
|
2008-06-17 19:39:26 +04:00
|
|
|
// part of the path.
|
|
|
|
std::string::size_type slash = fileN.find('/');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (slash != std::string::npos) {
|
2008-10-01 17:04:27 +04:00
|
|
|
// If this is a component installation, determine which component it
|
|
|
|
// is.
|
2008-06-17 19:39:26 +04:00
|
|
|
componentName = fileN.substr(0, slash);
|
|
|
|
|
|
|
|
// Strip off the component part of the path.
|
2016-05-16 17:34:04 +03:00
|
|
|
fileN = fileN.substr(slash + 1, std::string::npos);
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(fileN.begin(), fileN.end(), '/', '\\');
|
2016-09-23 10:28:35 +03:00
|
|
|
|
|
|
|
const std::string componentOutputDir =
|
|
|
|
CustomComponentInstallDirectory(componentName);
|
|
|
|
|
|
|
|
dstr << " RMDir \"" << componentOutputDir << "\\" << fileN << "\""
|
|
|
|
<< std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!componentName.empty()) {
|
2008-06-17 19:39:26 +04:00
|
|
|
this->Components[componentName].Directories.push_back(fileN);
|
2006-02-16 23:20:23 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: " << dstr.str()
|
|
|
|
<< std::endl);
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str());
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
|
|
|
|
<< nsisInFileName << " to " << nsisFileName << std::endl);
|
|
|
|
if (this->IsSet("CPACK_NSIS_MUI_ICON") ||
|
|
|
|
this->IsSet("CPACK_NSIS_MUI_UNIICON")) {
|
2011-01-06 15:35:48 +03:00
|
|
|
std::string installerIconCode;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsSet("CPACK_NSIS_MUI_ICON")) {
|
2011-01-06 15:35:48 +03:00
|
|
|
installerIconCode += "!define MUI_ICON \"";
|
|
|
|
installerIconCode += this->GetOption("CPACK_NSIS_MUI_ICON");
|
|
|
|
installerIconCode += "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->IsSet("CPACK_NSIS_MUI_UNIICON")) {
|
2011-01-06 15:35:48 +03:00
|
|
|
installerIconCode += "!define MUI_UNICON \"";
|
|
|
|
installerIconCode += this->GetOption("CPACK_NSIS_MUI_UNIICON");
|
|
|
|
installerIconCode += "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-10-31 06:02:43 +03:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_ICON_CODE",
|
|
|
|
installerIconCode.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->IsSet("CPACK_PACKAGE_ICON")) {
|
2007-10-31 06:02:43 +03:00
|
|
|
std::string installerIconCode = "!define MUI_HEADERIMAGE_BITMAP \"";
|
|
|
|
installerIconCode += this->GetOption("CPACK_PACKAGE_ICON");
|
|
|
|
installerIconCode += "\"\n";
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_ICON_CODE",
|
|
|
|
installerIconCode.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsSet("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP")) {
|
2015-09-25 23:06:08 +03:00
|
|
|
std::string installerBitmapCode =
|
|
|
|
"!define MUI_WELCOMEFINISHPAGE_BITMAP \"";
|
|
|
|
installerBitmapCode +=
|
|
|
|
this->GetOption("CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP");
|
|
|
|
installerBitmapCode += "\"\n";
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_WELCOMEFINISH_CODE",
|
|
|
|
installerBitmapCode.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-25 23:06:08 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsSet("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP")) {
|
2015-09-25 23:06:08 +03:00
|
|
|
std::string installerBitmapCode =
|
|
|
|
"!define MUI_UNWELCOMEFINISHPAGE_BITMAP \"";
|
|
|
|
installerBitmapCode +=
|
|
|
|
this->GetOption("CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP");
|
|
|
|
installerBitmapCode += "\"\n";
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_UNWELCOMEFINISH_CODE",
|
|
|
|
installerBitmapCode.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-25 23:06:08 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsSet("CPACK_NSIS_MUI_FINISHPAGE_RUN")) {
|
2011-01-06 16:44:50 +03:00
|
|
|
std::string installerRunCode = "!define MUI_FINISHPAGE_RUN \"$INSTDIR\\";
|
|
|
|
installerRunCode += this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY");
|
|
|
|
installerRunCode += "\\";
|
|
|
|
installerRunCode += this->GetOption("CPACK_NSIS_MUI_FINISHPAGE_RUN");
|
|
|
|
installerRunCode += "\"\n";
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_FINISHPAGE_RUN_CODE",
|
|
|
|
installerRunCode.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-01-06 16:44:50 +03:00
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
// Setup all of the component sections
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Components.empty()) {
|
2008-06-17 19:39:26 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES", "");
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC", "");
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_PAGE_COMPONENTS", "");
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_FULL_INSTALL",
|
2008-06-17 19:39:26 +04:00
|
|
|
"File /r \"${INST_DIR}\\*.*\"");
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTIONS", "");
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTION_LIST", "");
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS", "");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-06-17 19:39:26 +04:00
|
|
|
std::string componentCode;
|
|
|
|
std::string sectionList;
|
|
|
|
std::string selectedVarsList;
|
|
|
|
std::string componentDescriptions;
|
|
|
|
std::string groupDescriptions;
|
|
|
|
std::string installTypesCode;
|
2008-07-08 19:52:25 +04:00
|
|
|
std::string defines;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream macrosOut;
|
2008-07-08 19:52:25 +04:00
|
|
|
bool anyDownloadedComponents = false;
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Create installation types. The order is significant, so we first fill
|
|
|
|
// in a vector based on the indices, and print them in that order.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<cmCPackInstallationType*> installTypes(
|
|
|
|
this->InstallationTypes.size());
|
2008-06-17 19:39:26 +04:00
|
|
|
std::map<std::string, cmCPackInstallationType>::iterator installTypeIt;
|
|
|
|
for (installTypeIt = this->InstallationTypes.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
installTypeIt != this->InstallationTypes.end(); ++installTypeIt) {
|
|
|
|
installTypes[installTypeIt->second.Index - 1] = &installTypeIt->second;
|
|
|
|
}
|
|
|
|
std::vector<cmCPackInstallationType*>::iterator installTypeIt2;
|
2008-06-17 19:39:26 +04:00
|
|
|
for (installTypeIt2 = installTypes.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
installTypeIt2 != installTypes.end(); ++installTypeIt2) {
|
2008-06-17 19:39:26 +04:00
|
|
|
installTypesCode += "InstType \"";
|
|
|
|
installTypesCode += (*installTypeIt2)->DisplayName;
|
2008-06-17 20:44:18 +04:00
|
|
|
installTypesCode += "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Create installation groups first
|
|
|
|
std::map<std::string, cmCPackComponentGroup>::iterator groupIt;
|
|
|
|
for (groupIt = this->ComponentGroups.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
groupIt != this->ComponentGroups.end(); ++groupIt) {
|
2016-06-27 23:44:16 +03:00
|
|
|
if (groupIt->second.ParentGroup == CM_NULLPTR) {
|
2012-08-13 21:42:58 +04:00
|
|
|
componentCode +=
|
2008-07-08 19:52:25 +04:00
|
|
|
this->CreateComponentGroupDescription(&groupIt->second, macrosOut);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Add the group description, if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!groupIt->second.Description.empty()) {
|
|
|
|
groupDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" +
|
|
|
|
groupIt->first + "} \"" +
|
|
|
|
this->TranslateNewlines(groupIt->second.Description) + "\"\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Create the remaining components, which aren't associated with groups.
|
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
|
|
|
++compIt) {
|
|
|
|
if (compIt->second.Files.empty()) {
|
2008-07-08 19:52:25 +04:00
|
|
|
// NSIS cannot cope with components that have no files.
|
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
anyDownloadedComponents =
|
|
|
|
anyDownloadedComponents || compIt->second.IsDownloaded;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!compIt->second.Group) {
|
|
|
|
componentCode +=
|
|
|
|
this->CreateComponentDescription(&compIt->second, macrosOut);
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Add this component to the various section lists.
|
|
|
|
sectionList += " !insertmacro \"${MacroName}\" \"";
|
|
|
|
sectionList += compIt->first;
|
|
|
|
sectionList += "\"\n";
|
|
|
|
selectedVarsList += "Var " + compIt->first + "_selected\n";
|
2008-07-08 19:52:25 +04:00
|
|
|
selectedVarsList += "Var " + compIt->first + "_was_installed\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Add the component description, if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!compIt->second.Description.empty()) {
|
|
|
|
componentDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" +
|
|
|
|
compIt->first + "} \"" +
|
|
|
|
this->TranslateNewlines(compIt->second.Description) + "\"\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2008-07-08 19:52:25 +04:00
|
|
|
componentCode += macrosOut.str();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (componentDescriptions.empty() && groupDescriptions.empty()) {
|
2008-06-17 19:39:26 +04:00
|
|
|
// Turn off the "Description" box
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC",
|
2008-06-17 19:39:26 +04:00
|
|
|
"!define MUI_COMPONENTSPAGE_NODESC");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
componentDescriptions = "!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN\n" +
|
|
|
|
componentDescriptions + groupDescriptions +
|
|
|
|
"!insertmacro MUI_FUNCTION_DESCRIPTION_END\n";
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC",
|
2008-06-17 19:39:26 +04:00
|
|
|
componentDescriptions.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (anyDownloadedComponents) {
|
2008-07-08 19:52:25 +04:00
|
|
|
defines += "!define CPACK_USES_DOWNLOAD\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::IsOn(this->GetOption("CPACK_ADD_REMOVE"))) {
|
2008-07-08 19:52:25 +04:00
|
|
|
defines += "!define CPACK_NSIS_ADD_REMOVE\n";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
2008-10-01 17:04:27 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLATION_TYPES",
|
|
|
|
installTypesCode.c_str());
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_PAGE_COMPONENTS",
|
|
|
|
"!insertmacro MUI_PAGE_COMPONENTS");
|
2008-06-17 19:39:26 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_FULL_INSTALL", "");
|
2008-10-01 17:04:27 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTIONS",
|
|
|
|
componentCode.c_str());
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTION_LIST",
|
|
|
|
sectionList.c_str());
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS",
|
2008-10-01 17:04:27 +04:00
|
|
|
selectedVarsList.c_str());
|
2008-07-08 19:52:25 +04:00
|
|
|
this->SetOption("CPACK_NSIS_DEFINES", defines.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
this->ConfigureFile(nsisInInstallOptions.c_str(),
|
2006-05-12 22:44:24 +04:00
|
|
|
nsisInstallOptions.c_str());
|
2006-01-02 07:21:05 +03:00
|
|
|
this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
|
|
|
|
std::string nsisCmd = "\"";
|
|
|
|
nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM");
|
|
|
|
nsisCmd += "\" \"" + nsisFileName + "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
2016-06-27 23:44:16 +03:00
|
|
|
bool res =
|
|
|
|
cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal,
|
|
|
|
CM_NULLPTR, this->GeneratorVerbose, 0);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!res || retVal) {
|
2006-01-02 07:21:05 +03:00
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
2014-03-11 16:35:32 +04:00
|
|
|
ofs << "# Run command: " << nsisCmd << std::endl
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output << std::endl;
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running NSIS command: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< nsisCmd << std::endl
|
|
|
|
<< "Please check " << tmpFile << " for errors"
|
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-01-02 07:21:05 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
int cmCPackNSISGenerator::InitializeInternal()
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::IsOn(
|
|
|
|
this->GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_WARNING,
|
2012-02-05 16:13:48 +04:00
|
|
|
"NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY set. "
|
|
|
|
"This option will be reset to 0 (for this generator only)."
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2016-06-27 23:44:16 +03:00
|
|
|
this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", CM_NULLPTR);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-04-02 19:20:58 +04:00
|
|
|
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
std::vector<std::string> path;
|
|
|
|
std::string nsisPath;
|
2012-10-17 03:45:16 +04:00
|
|
|
bool gotRegValue = false;
|
2007-06-18 17:00:33 +04:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2016-05-16 17:34:04 +03:00
|
|
|
if (Nsis64) {
|
|
|
|
if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue(
|
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode",
|
|
|
|
nsisPath, cmsys::SystemTools::KeyWOW64_64)) {
|
2012-05-09 23:33:44 +04:00
|
|
|
gotRegValue = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue(
|
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath,
|
|
|
|
cmsys::SystemTools::KeyWOW64_64)) {
|
2012-05-09 23:33:44 +04:00
|
|
|
gotRegValue = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue(
|
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode",
|
|
|
|
nsisPath, cmsys::SystemTools::KeyWOW64_32)) {
|
2012-10-17 03:45:16 +04:00
|
|
|
gotRegValue = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!gotRegValue &&
|
|
|
|
cmsys::SystemTools::ReadRegistryValue(
|
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath)) {
|
2012-10-17 03:45:16 +04:00
|
|
|
gotRegValue = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue(
|
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath,
|
|
|
|
cmsys::SystemTools::KeyWOW64_32)) {
|
2012-10-17 03:45:16 +04:00
|
|
|
gotRegValue = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue(
|
|
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath)) {
|
2012-10-17 03:45:16 +04:00
|
|
|
gotRegValue = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-12-17 21:29:10 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (gotRegValue) {
|
2010-12-17 21:29:10 +03:00
|
|
|
path.push_back(nsisPath);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-18 17:00:33 +04:00
|
|
|
#endif
|
2010-12-17 21:29:10 +03:00
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
nsisPath = cmSystemTools::FindProgram("makensis", path, false);
|
2010-12-17 21:29:10 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (nsisPath.empty()) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
2010-12-17 21:29:10 +03:00
|
|
|
"Cannot find NSIS compiler makensis: likely it is not installed, "
|
|
|
|
"or not in your PATH"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
|
|
|
|
|
|
|
if (!gotRegValue) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
|
|
|
"Could not read NSIS registry value. This is usually caused by "
|
|
|
|
"NSIS not being installed. Please install NSIS from "
|
|
|
|
"http://nsis.sourceforge.net"
|
|
|
|
<< std::endl);
|
|
|
|
}
|
2010-12-17 21:29:10 +03:00
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-12-17 21:29:10 +03:00
|
|
|
|
2007-06-18 17:00:33 +04:00
|
|
|
std::string nsisCmd = "\"" + nsisPath + "\" " NSIS_OPT "VERSION";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Test NSIS version: " << nsisCmd
|
|
|
|
<< std::endl);
|
2006-02-23 17:38:40 +03:00
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
2016-06-27 23:44:16 +03:00
|
|
|
bool resS =
|
|
|
|
cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal,
|
|
|
|
CM_NULLPTR, this->GeneratorVerbose, 0);
|
2006-02-23 17:38:40 +03:00
|
|
|
cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)");
|
2013-03-08 17:13:33 +04:00
|
|
|
cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!resS || retVal ||
|
|
|
|
(!versionRex.find(output) && !versionRexCVS.find(output))) {
|
2013-03-08 17:13:33 +04:00
|
|
|
const char* topDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
std::string tmpFile = topDir ? topDir : ".";
|
2006-02-23 17:38:40 +03:00
|
|
|
tmpFile += "/NSISOutput.log";
|
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
2014-03-11 16:35:32 +04:00
|
|
|
ofs << "# Run command: " << nsisCmd << std::endl
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output << std::endl;
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR, "Problem checking NSIS version with command: "
|
|
|
|
<< nsisCmd << std::endl
|
|
|
|
<< "Please check " << tmpFile << " for errors" << std::endl);
|
2006-02-23 17:38:40 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (versionRex.find(output)) {
|
2013-03-08 17:13:33 +04:00
|
|
|
double nsisVersion = atof(versionRex.match(1).c_str());
|
|
|
|
double minNSISVersion = 2.09;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: " << nsisVersion
|
|
|
|
<< std::endl);
|
|
|
|
if (nsisVersion < minNSISVersion) {
|
2013-03-08 17:13:33 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"CPack requires NSIS Version 2.09 or greater. "
|
|
|
|
"NSIS found on the system was: "
|
|
|
|
<< nsisVersion << std::endl);
|
2013-03-08 17:13:33 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (versionRexCVS.find(output)) {
|
2013-03-08 17:13:33 +04:00
|
|
|
// No version check for NSIS cvs build
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: CVS "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< versionRexCVS.match(1) << std::endl);
|
|
|
|
}
|
2006-05-02 16:49:01 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
|
2011-01-06 15:48:47 +03:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_EXECUTABLES_DIRECTORY", "bin");
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackPackageExecutables =
|
|
|
|
this->GetOption("CPACK_PACKAGE_EXECUTABLES");
|
|
|
|
const char* cpackPackageDeskTopLinks =
|
|
|
|
this->GetOption("CPACK_CREATE_DESKTOP_LINKS");
|
|
|
|
const char* cpackNsisExecutablesDirectory =
|
|
|
|
this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY");
|
2007-11-07 21:11:58 +03:00
|
|
|
std::vector<std::string> cpackPackageDesktopLinksVector;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cpackPackageDeskTopLinks) {
|
2007-11-07 21:11:58 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< cpackPackageDeskTopLinks << std::endl);
|
|
|
|
|
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageDeskTopLinks,
|
|
|
|
cpackPackageDesktopLinksVector);
|
|
|
|
for (std::vector<std::string>::iterator i =
|
|
|
|
cpackPackageDesktopLinksVector.begin();
|
|
|
|
i != cpackPackageDesktopLinksVector.end(); ++i) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
|
|
|
"CPACK_CREATE_DESKTOP_LINKS: " << *i << std::endl);
|
2007-11-07 21:11:58 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "not set" << std::endl);
|
|
|
|
}
|
2011-01-07 22:24:04 +03:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream str;
|
|
|
|
std::ostringstream deleteStr;
|
2011-01-07 22:24:04 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cpackPackageExecutables) {
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< cpackPackageExecutables << "." << std::endl);
|
2006-02-14 22:29:15 +03:00
|
|
|
std::vector<std::string> cpackPackageExecutablesVector;
|
2006-03-09 00:33:39 +03:00
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageExecutables,
|
2016-05-16 17:34:04 +03:00
|
|
|
cpackPackageExecutablesVector);
|
|
|
|
if (cpackPackageExecutablesVector.size() % 2 != 0) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
2006-03-09 00:33:39 +03:00
|
|
|
"CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
|
2016-05-16 17:34:04 +03:00
|
|
|
"<icon name>."
|
|
|
|
<< std::endl);
|
2006-02-14 22:29:15 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 22:29:15 +03:00
|
|
|
std::vector<std::string>::iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = cpackPackageExecutablesVector.begin();
|
|
|
|
it != cpackPackageExecutablesVector.end(); ++it) {
|
2006-02-14 22:29:15 +03:00
|
|
|
std::string execName = *it;
|
2016-05-16 17:34:04 +03:00
|
|
|
++it;
|
2006-02-14 22:29:15 +03:00
|
|
|
std::string linkName = *it;
|
2016-05-16 17:34:04 +03:00
|
|
|
str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName
|
|
|
|
<< ".lnk\" \"$INSTDIR\\" << cpackNsisExecutablesDirectory << "\\"
|
|
|
|
<< execName << ".exe\"" << std::endl;
|
2006-03-09 00:33:39 +03:00
|
|
|
deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
|
2016-05-16 17:34:04 +03:00
|
|
|
<< ".lnk\"" << std::endl;
|
2007-09-18 23:16:21 +04:00
|
|
|
// see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
|
|
|
|
// if so add a desktop link
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cpackPackageDesktopLinksVector.empty() &&
|
|
|
|
std::find(cpackPackageDesktopLinksVector.begin(),
|
|
|
|
cpackPackageDesktopLinksVector.end(),
|
|
|
|
execName) != cpackPackageDesktopLinksVector.end()) {
|
2007-09-18 23:16:21 +04:00
|
|
|
str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
str << " CreateShortCut \"$DESKTOP\\" << linkName
|
|
|
|
<< ".lnk\" \"$INSTDIR\\" << cpackNsisExecutablesDirectory << "\\"
|
|
|
|
<< execName << ".exe\"" << std::endl;
|
2007-09-18 23:16:21 +04:00
|
|
|
deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
deleteStr << " Delete \"$DESKTOP\\" << linkName << ".lnk\""
|
|
|
|
<< std::endl;
|
2006-02-14 22:29:15 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-01-07 22:24:04 +03:00
|
|
|
|
|
|
|
this->CreateMenuLinks(str, deleteStr);
|
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_CREATE_ICONS", str.str().c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str());
|
2011-01-07 22:24:04 +03:00
|
|
|
|
2006-10-12 22:59:43 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_NSIS_COMPRESSOR", "lzma");
|
2006-02-14 22:29:15 +03:00
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
return this->Superclass::InitializeInternal();
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|
|
|
|
|
2016-06-08 23:29:15 +03:00
|
|
|
void cmCPackNSISGenerator::CreateMenuLinks(std::ostream& str,
|
|
|
|
std::ostream& deleteStr)
|
2007-10-18 17:40:10 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackMenuLinks = this->GetOption("CPACK_NSIS_MENU_LINKS");
|
|
|
|
if (!cpackMenuLinks) {
|
2007-10-18 17:40:10 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
|
|
|
"The cpackMenuLinks: " << cpackMenuLinks << "." << std::endl);
|
2007-10-18 17:40:10 +04:00
|
|
|
std::vector<std::string> cpackMenuLinksVector;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::ExpandListArgument(cpackMenuLinks, cpackMenuLinksVector);
|
|
|
|
if (cpackMenuLinksVector.size() % 2 != 0) {
|
2007-10-19 20:03:16 +04:00
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
2012-05-28 18:59:51 +04:00
|
|
|
"CPACK_NSIS_MENU_LINKS should contain pairs of <shortcut target> and "
|
2016-05-16 17:34:04 +03:00
|
|
|
"<shortcut label>."
|
|
|
|
<< std::endl);
|
2007-10-18 17:40:10 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-01-07 22:24:04 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static cmsys::RegularExpression urlRegex(
|
|
|
|
"^(mailto:|(ftps?|https?|news)://).*$");
|
2011-01-07 22:24:04 +03:00
|
|
|
|
2007-10-18 17:40:10 +04:00
|
|
|
std::vector<std::string>::iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = cpackMenuLinksVector.begin(); it != cpackMenuLinksVector.end();
|
|
|
|
++it) {
|
2007-10-18 17:40:10 +04:00
|
|
|
std::string sourceName = *it;
|
2011-01-07 22:24:04 +03:00
|
|
|
const bool url = urlRegex.find(sourceName);
|
|
|
|
|
|
|
|
// Convert / to \ in filenames, but not in urls:
|
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!url) {
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(sourceName.begin(), sourceName.end(), '/', '\\');
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-01-07 22:24:04 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
++it;
|
2007-10-18 17:40:10 +04:00
|
|
|
std::string linkName = *it;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!url) {
|
|
|
|
str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName
|
|
|
|
<< ".lnk\" \"$INSTDIR\\" << sourceName << "\"" << std::endl;
|
2007-10-29 15:11:44 +03:00
|
|
|
deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
|
|
|
|
<< ".lnk\"" << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
str << " WriteINIStr \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName
|
|
|
|
<< ".url\" \"InternetShortcut\" \"URL\" \"" << sourceName << "\""
|
2007-10-29 15:11:44 +03:00
|
|
|
<< std::endl;
|
|
|
|
deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
|
|
|
|
<< ".url\"" << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-10-18 17:40:10 +04:00
|
|
|
// see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
|
|
|
|
// if so add a desktop link
|
|
|
|
std::string desktop = "CPACK_CREATE_DESKTOP_LINK_";
|
|
|
|
desktop += linkName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsSet(desktop)) {
|
2007-10-18 17:40:10 +04:00
|
|
|
str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
str << " CreateShortCut \"$DESKTOP\\" << linkName
|
|
|
|
<< ".lnk\" \"$INSTDIR\\" << sourceName << "\"" << std::endl;
|
2007-10-18 17:40:10 +04:00
|
|
|
deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
deleteStr << " Delete \"$DESKTOP\\" << linkName << ".lnk\""
|
|
|
|
<< std::endl;
|
2007-10-18 17:40:10 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-10-18 17:40:10 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCPackNSISGenerator::GetListOfSubdirectories(
|
|
|
|
const char* topdir, std::vector<std::string>& dirs)
|
2006-02-16 23:20:23 +03:00
|
|
|
{
|
|
|
|
cmsys::Directory dir;
|
|
|
|
dir.Load(topdir);
|
|
|
|
size_t fileNum;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) {
|
|
|
|
if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") &&
|
|
|
|
strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), "..")) {
|
2015-01-30 01:19:40 +03:00
|
|
|
std::string fullPath = topdir;
|
2006-02-16 23:20:23 +03:00
|
|
|
fullPath += "/";
|
|
|
|
fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmsys::SystemTools::FileIsDirectory(fullPath) &&
|
|
|
|
!cmsys::SystemTools::FileIsSymlink(fullPath)) {
|
|
|
|
if (!this->GetListOfSubdirectories(fullPath.c_str(), dirs)) {
|
2006-02-16 23:20:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-16 23:20:23 +03:00
|
|
|
dirs.push_back(topdir);
|
|
|
|
return true;
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2012-05-14 22:26:15 +04:00
|
|
|
enum cmCPackGenerator::CPackSetDestdirSupport
|
|
|
|
cmCPackNSISGenerator::SupportsSetDestdir() const
|
|
|
|
{
|
|
|
|
return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED;
|
|
|
|
}
|
|
|
|
|
2012-05-15 01:29:42 +04:00
|
|
|
bool cmCPackNSISGenerator::SupportsAbsoluteDestination() const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return false;
|
2012-05-15 01:29:42 +04:00
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
bool cmCPackNSISGenerator::SupportsComponentInstallation() const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCPackNSISGenerator::CreateComponentDescription(
|
2016-06-08 23:29:15 +03:00
|
|
|
cmCPackComponent* component, std::ostream& macrosOut)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
|
|
|
// Basic description of the component
|
|
|
|
std::string componentCode = "Section ";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (component->IsDisabledByDefault) {
|
2008-06-17 19:39:26 +04:00
|
|
|
componentCode += "/o ";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
componentCode += "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (component->IsHidden) {
|
2008-06-17 19:39:26 +04:00
|
|
|
componentCode += "-";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
componentCode += component->DisplayName + "\" " + component->Name + "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (component->IsRequired) {
|
2008-06-17 19:39:26 +04:00
|
|
|
componentCode += " SectionIn RO\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!component->InstallationTypes.empty()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream out;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<cmCPackInstallationType*>::iterator installTypeIter;
|
2008-06-17 19:39:26 +04:00
|
|
|
for (installTypeIter = component->InstallationTypes.begin();
|
|
|
|
installTypeIter != component->InstallationTypes.end();
|
2016-05-16 17:34:04 +03:00
|
|
|
++installTypeIter) {
|
2008-06-17 19:39:26 +04:00
|
|
|
out << " " << (*installTypeIter)->Index;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
componentCode += " SectionIn" + out.str() + "\n";
|
|
|
|
}
|
2016-09-23 10:28:35 +03:00
|
|
|
|
|
|
|
const std::string componentOutputDir =
|
|
|
|
CustomComponentInstallDirectory(component->Name);
|
|
|
|
componentCode += " SetOutPath \"" + componentOutputDir + "\"\n";
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
// Create the actual installation commands
|
2016-05-16 17:34:04 +03:00
|
|
|
if (component->IsDownloaded) {
|
|
|
|
if (component->ArchiveFile.empty()) {
|
2008-07-08 19:52:25 +04:00
|
|
|
// Compute the name of the archive.
|
|
|
|
std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
packagesDir += ".dummy";
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream out;
|
2016-05-16 17:34:04 +03:00
|
|
|
out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-"
|
|
|
|
<< component->Name << ".zip";
|
2008-07-08 19:52:25 +04:00
|
|
|
component->ArchiveFile = out.str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
// Create the directory for the upload area
|
2012-08-13 21:42:58 +04:00
|
|
|
const char* userUploadDirectory =
|
2008-10-01 17:04:27 +04:00
|
|
|
this->GetOption("CPACK_UPLOAD_DIRECTORY");
|
2008-07-08 19:52:25 +04:00
|
|
|
std::string uploadDirectory;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (userUploadDirectory && *userUploadDirectory) {
|
2008-07-08 19:52:25 +04:00
|
|
|
uploadDirectory = userUploadDirectory;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
uploadDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
|
2008-07-08 19:52:25 +04:00
|
|
|
uploadDirectory += "/CPackUploads";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!cmSystemTools::FileExists(uploadDirectory.c_str())) {
|
|
|
|
if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) {
|
2008-07-08 19:52:25 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Unable to create NSIS upload directory "
|
|
|
|
<< uploadDirectory << std::endl);
|
2008-07-08 19:52:25 +04:00
|
|
|
return "";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
// Remove the old archive, if one exists
|
|
|
|
std::string archiveFile = uploadDirectory + '/' + component->ArchiveFile;
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"- Building downloaded component archive: " << archiveFile
|
|
|
|
<< std::endl);
|
|
|
|
if (cmSystemTools::FileExists(archiveFile.c_str(), true)) {
|
|
|
|
if (!cmSystemTools::RemoveFile(archiveFile)) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to remove archive file "
|
|
|
|
<< archiveFile << std::endl);
|
2008-07-08 19:52:25 +04:00
|
|
|
return "";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
// Find a ZIP program
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IsSet("ZIP_EXECUTABLE")) {
|
2008-07-08 19:52:25 +04:00
|
|
|
this->ReadListFile("CPackZIP.cmake");
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IsSet("ZIP_EXECUTABLE")) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to find ZIP program"
|
|
|
|
<< std::endl);
|
2008-07-08 19:52:25 +04:00
|
|
|
return "";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
// The directory where this component's files reside
|
|
|
|
std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
dirName += '/';
|
|
|
|
dirName += component->Name;
|
|
|
|
dirName += '/';
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
// Build the list of files to go into this archive, and determine the
|
2008-07-08 19:52:25 +04:00
|
|
|
// size of the installed component.
|
|
|
|
std::string zipListFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
zipListFileName += "/winZip.filelist";
|
2016-05-16 17:34:04 +03:00
|
|
|
bool needQuotesInFile =
|
|
|
|
cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES"));
|
2008-07-08 19:52:25 +04:00
|
|
|
unsigned long totalSize = 0;
|
|
|
|
{ // the scope is needed for cmGeneratedFileStream
|
|
|
|
cmGeneratedFileStream out(zipListFileName.c_str());
|
|
|
|
std::vector<std::string>::iterator fileIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (fileIt = component->Files.begin(); fileIt != component->Files.end();
|
|
|
|
++fileIt) {
|
|
|
|
if (needQuotesInFile) {
|
2008-07-08 19:52:25 +04:00
|
|
|
out << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
out << *fileIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needQuotesInFile) {
|
2008-07-08 19:52:25 +04:00
|
|
|
out << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
out << std::endl;
|
|
|
|
|
2014-11-23 13:05:50 +03:00
|
|
|
totalSize += cmSystemTools::FileLength(dirName + *fileIt);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the archive in the upload area
|
|
|
|
std::string cmd = this->GetOption("CPACK_ZIP_COMMAND");
|
|
|
|
cmsys::SystemTools::ReplaceString(cmd, "<ARCHIVE>", archiveFile.c_str());
|
2012-08-13 21:42:58 +04:00
|
|
|
cmsys::SystemTools::ReplaceString(cmd, "<FILELIST>",
|
2008-07-08 19:52:25 +04:00
|
|
|
zipListFileName.c_str());
|
|
|
|
std::string output;
|
|
|
|
int retVal = -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output,
|
|
|
|
&retVal, dirName.c_str(),
|
|
|
|
cmSystemTools::OUTPUT_NONE, 0);
|
|
|
|
if (!res || retVal) {
|
2008-07-08 19:52:25 +04:00
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
tmpFile += "/CompressZip.log";
|
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
2014-03-11 16:35:32 +04:00
|
|
|
ofs << "# Run command: " << cmd << std::endl
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output << std::endl;
|
2008-07-08 19:52:25 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running zip command: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< cmd << std::endl
|
|
|
|
<< "Please check " << tmpFile << " for errors"
|
|
|
|
<< std::endl);
|
2008-07-08 19:52:25 +04:00
|
|
|
return "";
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-07-08 19:52:25 +04:00
|
|
|
// Create the NSIS code to download this file on-the-fly.
|
2010-06-27 19:22:05 +04:00
|
|
|
unsigned long totalSizeInKbytes = (totalSize + 512) / 1024;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (totalSizeInKbytes == 0) {
|
2008-07-08 19:52:25 +04:00
|
|
|
totalSizeInKbytes = 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream out;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2008-07-08 19:52:25 +04:00
|
|
|
out << " AddSize " << totalSizeInKbytes << "\n"
|
|
|
|
<< " Push \"" << component->ArchiveFile << "\"\n"
|
|
|
|
<< " Call DownloadFile\n"
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " ZipDLL::extractall \"$INSTDIR\\"
|
2008-07-08 19:52:25 +04:00
|
|
|
<< component->ArchiveFile << "\" \"$INSTDIR\"\n"
|
|
|
|
<< " Pop $2 ; error message\n"
|
|
|
|
" StrCmp $2 \"success\" +2 0\n"
|
|
|
|
" MessageBox MB_OK \"Failed to unzip $2\"\n"
|
|
|
|
" Delete $INSTDIR\\$0\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2008-07-08 19:52:25 +04:00
|
|
|
componentCode += out.str();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
componentCode +=
|
|
|
|
" File /r \"${INST_DIR}\\" + component->Name + "\\*.*\"\n";
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
componentCode += "SectionEnd\n";
|
|
|
|
|
|
|
|
// Macro used to remove the component
|
2008-07-08 19:52:25 +04:00
|
|
|
macrosOut << "!macro Remove_${" << component->Name << "}\n";
|
|
|
|
macrosOut << " IntCmp $" << component->Name << "_was_installed 0 noremove_"
|
|
|
|
<< component->Name << "\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
std::vector<std::string>::iterator pathIt;
|
2009-01-20 22:29:41 +03:00
|
|
|
std::string path;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (pathIt = component->Files.begin(); pathIt != component->Files.end();
|
|
|
|
++pathIt) {
|
2009-01-20 22:29:41 +03:00
|
|
|
path = *pathIt;
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(path.begin(), path.end(), '/', '\\');
|
2016-09-23 10:28:35 +03:00
|
|
|
macrosOut << " Delete \"" << componentOutputDir << "\\" << path << "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-20 22:29:41 +03:00
|
|
|
for (pathIt = component->Directories.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
pathIt != component->Directories.end(); ++pathIt) {
|
2009-01-20 22:29:41 +03:00
|
|
|
path = *pathIt;
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(path.begin(), path.end(), '/', '\\');
|
2016-09-23 10:28:35 +03:00
|
|
|
macrosOut << " RMDir \"" << componentOutputDir << "\\" << path << "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
macrosOut << " noremove_" << component->Name << ":\n";
|
|
|
|
macrosOut << "!macroend\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Macro used to select each of the components that this component
|
|
|
|
// depends on.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::set<cmCPackComponent*> visited;
|
2008-07-08 19:52:25 +04:00
|
|
|
macrosOut << "!macro Select_" << component->Name << "_depends\n";
|
|
|
|
macrosOut << CreateSelectionDependenciesDescription(component, visited);
|
|
|
|
macrosOut << "!macroend\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
// Macro used to deselect each of the components that depend on this
|
|
|
|
// component.
|
|
|
|
visited.clear();
|
2008-07-08 19:52:25 +04:00
|
|
|
macrosOut << "!macro Deselect_required_by_" << component->Name << "\n";
|
|
|
|
macrosOut << CreateDeselectionDependenciesDescription(component, visited);
|
|
|
|
macrosOut << "!macroend\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
return componentCode;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription(
|
|
|
|
cmCPackComponent* component, std::set<cmCPackComponent*>& visited)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
|
|
|
// Don't visit a component twice
|
2016-05-16 17:34:04 +03:00
|
|
|
if (visited.count(component)) {
|
2008-06-17 19:39:26 +04:00
|
|
|
return std::string();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
visited.insert(component);
|
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream out;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<cmCPackComponent*>::iterator dependIt;
|
2008-06-17 19:39:26 +04:00
|
|
|
for (dependIt = component->Dependencies.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
dependIt != component->Dependencies.end(); ++dependIt) {
|
2008-06-17 19:39:26 +04:00
|
|
|
// Write NSIS code to select this dependency
|
|
|
|
out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n";
|
|
|
|
out << " IntOp $0 $0 | ${SF_SELECTED}\n";
|
|
|
|
out << " SectionSetFlags ${" << (*dependIt)->Name << "} $0\n";
|
2008-10-01 17:04:27 +04:00
|
|
|
out << " IntOp $" << (*dependIt)->Name
|
|
|
|
<< "_selected 0 + ${SF_SELECTED}\n";
|
2008-06-17 19:39:26 +04:00
|
|
|
// Recurse
|
|
|
|
out << CreateSelectionDependenciesDescription(*dependIt, visited).c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription(
|
|
|
|
cmCPackComponent* component, std::set<cmCPackComponent*>& visited)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
|
|
|
// Don't visit a component twice
|
2016-05-16 17:34:04 +03:00
|
|
|
if (visited.count(component)) {
|
2008-06-17 19:39:26 +04:00
|
|
|
return std::string();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
visited.insert(component);
|
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream out;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<cmCPackComponent*>::iterator dependIt;
|
2008-06-17 19:39:26 +04:00
|
|
|
for (dependIt = component->ReverseDependencies.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
dependIt != component->ReverseDependencies.end(); ++dependIt) {
|
2008-06-17 19:39:26 +04:00
|
|
|
// Write NSIS code to deselect this dependency
|
|
|
|
out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n";
|
|
|
|
out << " IntOp $1 ${SF_SELECTED} ~\n";
|
|
|
|
out << " IntOp $0 $0 & $1\n";
|
|
|
|
out << " SectionSetFlags ${" << (*dependIt)->Name << "} $0\n";
|
|
|
|
out << " IntOp $" << (*dependIt)->Name << "_selected 0 + 0\n";
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
// Recurse
|
2016-05-16 17:34:04 +03:00
|
|
|
out
|
|
|
|
<< CreateDeselectionDependenciesDescription(*dependIt, visited).c_str();
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCPackNSISGenerator::CreateComponentGroupDescription(
|
2016-06-08 23:29:15 +03:00
|
|
|
cmCPackComponentGroup* group, std::ostream& macrosOut)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (group->Components.empty() && group->Subgroups.empty()) {
|
2008-06-17 19:39:26 +04:00
|
|
|
// Silently skip empty groups. NSIS doesn't support them.
|
|
|
|
return std::string();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
std::string code = "SectionGroup ";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (group->IsExpandedByDefault) {
|
2008-06-17 19:39:26 +04:00
|
|
|
code += "/e ";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (group->IsBold) {
|
2008-06-17 19:39:26 +04:00
|
|
|
code += "\"!" + group->DisplayName + "\" " + group->Name + "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-06-17 19:39:26 +04:00
|
|
|
code += "\"" + group->DisplayName + "\" " + group->Name + "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
std::vector<cmCPackComponentGroup*>::iterator groupIt;
|
|
|
|
for (groupIt = group->Subgroups.begin(); groupIt != group->Subgroups.end();
|
2016-05-16 17:34:04 +03:00
|
|
|
++groupIt) {
|
2008-07-08 19:52:25 +04:00
|
|
|
code += this->CreateComponentGroupDescription(*groupIt, macrosOut);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::vector<cmCPackComponent*>::iterator comp;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (comp = group->Components.begin(); comp != group->Components.end();
|
|
|
|
++comp) {
|
|
|
|
if ((*comp)->Files.empty()) {
|
2008-07-08 19:52:25 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-07-08 19:52:25 +04:00
|
|
|
|
|
|
|
code += this->CreateComponentDescription(*comp, macrosOut);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
code += "SectionGroupEnd\n";
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2016-09-23 10:28:35 +03:00
|
|
|
std::string cmCPackNSISGenerator::CustomComponentInstallDirectory(
|
|
|
|
const std::string& componentName)
|
|
|
|
{
|
|
|
|
const char* outputDir =
|
|
|
|
this->GetOption("CPACK_NSIS_" + componentName + "_INSTALL_DIRECTORY");
|
|
|
|
const std::string componentOutputDir = (outputDir ? outputDir : "$INSTDIR");
|
|
|
|
return componentOutputDir;
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::string cmCPackNSISGenerator::TranslateNewlines(std::string str)
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(str, "\n", "$\\r$\\n");
|
|
|
|
return str;
|
|
|
|
}
|