2012-10-03 18:08:49 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
2015-02-13 13:57:20 +03:00
|
|
|
Copyright 2012-2015 Kitware, Inc., Insight Software Consortium
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmCPackWIXGenerator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <CPack/cmCPackComponentGroup.h>
|
|
|
|
#include <CPack/cmCPackLog.h>
|
2013-10-11 00:49:33 +04:00
|
|
|
#include <cmCryptoHash.h>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmGeneratedFileStream.h>
|
2014-05-17 00:43:56 +04:00
|
|
|
#include <cmInstalledFile.h>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmSystemTools.h>
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
#include "cmWIXDirectoriesSourceWriter.h"
|
|
|
|
#include "cmWIXFeaturesSourceWriter.h"
|
|
|
|
#include "cmWIXFilesSourceWriter.h"
|
2012-10-03 18:08:49 +04:00
|
|
|
#include "cmWIXRichTextFormatWriter.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmWIXSourceWriter.h"
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
#include <cmsys/Directory.hxx>
|
2013-12-05 09:17:24 +04:00
|
|
|
#include <cmsys/Encoding.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/SystemTools.hxx>
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
#include <rpc.h> // for GUID generation
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackWIXGenerator::cmCPackWIXGenerator()
|
|
|
|
: Patch(0)
|
2014-02-04 21:40:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-19 00:45:30 +04:00
|
|
|
cmCPackWIXGenerator::~cmCPackWIXGenerator()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Patch) {
|
2014-04-19 00:45:30 +04:00
|
|
|
delete this->Patch;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-04-19 00:45:30 +04:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
int cmCPackWIXGenerator::InitializeInternal()
|
|
|
|
{
|
|
|
|
componentPackageMethod = ONE_PACKAGE;
|
2014-04-19 00:45:30 +04:00
|
|
|
this->Patch = new cmWIXPatch(this->Logger);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string logFileName = this->CPackTopLevel + "/wix.log";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Running WiX command: " << command
|
|
|
|
<< std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string output;
|
|
|
|
|
|
|
|
int returnValue = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output,
|
|
|
|
&output, &returnValue, 0,
|
|
|
|
cmSystemTools::OUTPUT_NONE);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream logFile(logFileName.c_str(), std::ios::app);
|
2012-10-03 18:08:49 +04:00
|
|
|
logFile << command << std::endl;
|
|
|
|
logFile << output;
|
|
|
|
logFile.close();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!status || returnValue) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running WiX candle. "
|
|
|
|
"Please check '"
|
|
|
|
<< logFileName << "' for errors." << std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCPackWIXGenerator::RunCandleCommand(std::string const& sourceFile,
|
|
|
|
std::string const& objectFile)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string executable;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::stringstream command;
|
|
|
|
command << QuotePath(executable);
|
|
|
|
command << " -nologo";
|
|
|
|
command << " -arch " << GetArchitecture();
|
|
|
|
command << " -out " << QuotePath(objectFile);
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (extension_set_t::const_iterator i = CandleExtensions.begin();
|
|
|
|
i != CandleExtensions.end(); ++i) {
|
2013-11-10 22:48:29 +04:00
|
|
|
command << " -ext " << QuotePath(*i);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
|
|
|
|
AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
command << " " << QuotePath(sourceFile);
|
|
|
|
|
|
|
|
return RunWiXCommand(command.str());
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string executable;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::stringstream command;
|
|
|
|
command << QuotePath(executable);
|
|
|
|
command << " -nologo";
|
|
|
|
command << " -out " << QuotePath(packageFileNames.at(0));
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (extension_set_t::const_iterator i = this->LightExtensions.begin();
|
|
|
|
i != this->LightExtensions.end(); ++i) {
|
2013-11-10 22:48:29 +04:00
|
|
|
command << " -ext " << QuotePath(*i);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2013-05-06 19:21:42 +04:00
|
|
|
const char* const cultures = GetOption("CPACK_WIX_CULTURES");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cultures) {
|
2013-05-06 19:21:42 +04:00
|
|
|
command << " -cultures:" << cultures;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
|
|
|
|
AddCustomFlags("CPACK_WIX_LIGHT_EXTRA_FLAGS", command);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
command << " " << objectFiles;
|
|
|
|
|
|
|
|
return RunWiXCommand(command.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCPackWIXGenerator::PackageFiles()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag()) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Fatal WiX Generator Error"
|
|
|
|
<< std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::InitializeWiXConfiguration()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ReadListFile("CPackWIX.cmake")) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while executing CPackWIX.cmake"
|
|
|
|
<< std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_WIX_PRODUCT_GUID") == 0) {
|
2012-10-03 18:08:49 +04:00
|
|
|
std::string guid = GenerateGUID();
|
|
|
|
SetOption("CPACK_WIX_PRODUCT_GUID", guid.c_str());
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . "
|
|
|
|
<< std::endl);
|
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_WIX_UPGRADE_GUID") == 0) {
|
2012-10-03 18:08:49 +04:00
|
|
|
std::string guid = GenerateGUID();
|
|
|
|
SetOption("CPACK_WIX_UPGRADE_GUID", guid.c_str());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_WARNING, "CPACK_WIX_UPGRADE_GUID implicitly set to "
|
|
|
|
<< guid << " . "
|
|
|
|
"Please refer to the documentation on how and why "
|
|
|
|
"you might want to set this explicitly."
|
|
|
|
<< std::endl);
|
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_TOPLEVEL_DIRECTORY", this->CPackTopLevel)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_WIX_LICENSE_RTF") == 0) {
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string licenseFilename = this->CPackTopLevel + "/License.rtf";
|
2012-10-03 18:08:49 +04:00
|
|
|
SetOption("CPACK_WIX_LICENSE_RTF", licenseFilename.c_str());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!CreateLicenseFile()) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_PACKAGE_VENDOR") == 0) {
|
2013-11-10 22:48:29 +04:00
|
|
|
std::string defaultVendor = "Humanity";
|
|
|
|
SetOption("CPACK_PACKAGE_VENDOR", defaultVendor.c_str());
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2013-11-10 22:48:29 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"CPACK_PACKAGE_VENDOR implicitly set to "
|
|
|
|
<< defaultVendor << " . " << std::endl);
|
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_WIX_UI_REF") == 0) {
|
2013-11-20 00:38:09 +04:00
|
|
|
std::string defaultRef = "WixUI_InstallDir";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Components.empty()) {
|
2013-11-20 00:38:09 +04:00
|
|
|
defaultRef = "WixUI_FeatureTree";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
|
|
|
SetOption("CPACK_WIX_UI_REF", defaultRef.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2014-03-02 02:13:35 +04:00
|
|
|
const char* packageContact = GetOption("CPACK_PACKAGE_CONTACT");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (packageContact != 0 && GetOption("CPACK_WIX_PROPERTY_ARPCONTACT") == 0) {
|
2014-03-02 02:13:35 +04:00
|
|
|
SetOption("CPACK_WIX_PROPERTY_ARPCONTACT", packageContact);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-02 02:13:35 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
CollectExtensions("CPACK_WIX_EXTENSIONS", this->CandleExtensions);
|
|
|
|
CollectExtensions("CPACK_WIX_CANDLE_EXTENSIONS", this->CandleExtensions);
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->LightExtensions.insert("WixUIExtension");
|
|
|
|
CollectExtensions("CPACK_WIX_EXTENSIONS", this->LightExtensions);
|
|
|
|
CollectExtensions("CPACK_WIX_LIGHT_EXTENSIONS", this->LightExtensions);
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2013-12-17 01:30:11 +04:00
|
|
|
const char* patchFilePath = GetOption("CPACK_WIX_PATCH_FILE");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (patchFilePath) {
|
2015-12-15 01:04:41 +03:00
|
|
|
std::vector<std::string> patchFilePaths;
|
|
|
|
cmSystemTools::ExpandListArgument(patchFilePath, patchFilePaths);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < patchFilePaths.size(); ++i) {
|
|
|
|
if (!this->Patch->LoadFragments(patchFilePaths[i])) {
|
2015-12-15 01:04:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-12-17 01:30:11 +04:00
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::PackageFilesImpl()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!InitializeWiXConfiguration()) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
CreateWiXVariablesIncludeFile();
|
2014-03-02 02:13:35 +04:00
|
|
|
CreateWiXPropertiesIncludeFile();
|
2015-02-13 13:57:20 +03:00
|
|
|
CreateWiXProductFragmentIncludeFile();
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!CreateWiXSourceFiles()) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2013-10-13 15:16:54 +04:00
|
|
|
AppendUserSuppliedExtraSources();
|
|
|
|
|
2015-03-06 16:19:30 +03:00
|
|
|
std::set<std::string> usedBaseNames;
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
std::stringstream objectFiles;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < this->WixSources.size(); ++i) {
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& sourceFilename = this->WixSources[i];
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2015-03-06 16:19:30 +03:00
|
|
|
std::string baseName =
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(sourceFilename);
|
|
|
|
|
|
|
|
unsigned int counter = 0;
|
|
|
|
std::string uniqueBaseName = baseName;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
while (usedBaseNames.find(uniqueBaseName) != usedBaseNames.end()) {
|
2015-03-06 16:19:30 +03:00
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << baseName << ++counter;
|
|
|
|
uniqueBaseName = tmp.str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-03-06 16:19:30 +03:00
|
|
|
|
|
|
|
usedBaseNames.insert(uniqueBaseName);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
std::string objectFilename =
|
2015-03-06 16:19:30 +03:00
|
|
|
this->CPackTopLevel + "/" + uniqueBaseName + ".wixobj";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCandleCommand(sourceFilename, objectFilename)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
objectFiles << " " << QuotePath(objectFilename);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2013-10-13 15:16:54 +04:00
|
|
|
AppendUserSuppliedExtraObjects(objectFiles);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
return RunLightCommand(objectFiles.str());
|
|
|
|
}
|
|
|
|
|
2013-10-13 15:16:54 +04:00
|
|
|
void cmCPackWIXGenerator::AppendUserSuppliedExtraSources()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES");
|
|
|
|
if (!cpackWixExtraSources)
|
|
|
|
return;
|
2013-10-13 15:16:54 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
cmSystemTools::ExpandListArgument(cpackWixExtraSources, this->WixSources);
|
2013-10-13 15:16:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS");
|
|
|
|
if (!cpackWixExtraObjects)
|
|
|
|
return;
|
2013-10-13 15:16:54 +04:00
|
|
|
|
|
|
|
std::vector<std::string> expandedExtraObjects;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::ExpandListArgument(cpackWixExtraObjects,
|
|
|
|
expandedExtraObjects);
|
2013-10-13 15:16:54 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < expandedExtraObjects.size(); ++i) {
|
2014-02-25 02:21:12 +04:00
|
|
|
stream << " " << QuotePath(expandedExtraObjects[i]);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-13 15:16:54 +04:00
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile()
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string includeFilename = this->CPackTopLevel + "/cpack_variables.wxi";
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXSourceWriter includeFile(this->Logger, includeFilename, true);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID");
|
|
|
|
CopyDefinition(includeFile, "CPACK_PACKAGE_VENDOR");
|
|
|
|
CopyDefinition(includeFile, "CPACK_PACKAGE_NAME");
|
|
|
|
CopyDefinition(includeFile, "CPACK_PACKAGE_VERSION");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_LICENSE_RTF");
|
2012-12-15 00:50:18 +04:00
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_ICON");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UI_BANNER");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UI_DIALOG");
|
2013-03-01 06:09:58 +04:00
|
|
|
SetOptionIfNotSet("CPACK_WIX_PROGRAM_MENU_FOLDER",
|
2016-05-16 17:34:04 +03:00
|
|
|
GetOption("CPACK_PACKAGE_NAME"));
|
2013-03-01 06:09:58 +04:00
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_PROGRAM_MENU_FOLDER");
|
2013-11-20 00:38:09 +04:00
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UI_REF");
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
2014-03-02 02:13:35 +04:00
|
|
|
void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string includeFilename = this->CPackTopLevel + "/properties.wxi";
|
2014-03-02 02:13:35 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXSourceWriter includeFile(this->Logger, includeFilename, true);
|
2014-03-02 02:13:35 +04:00
|
|
|
|
|
|
|
std::string prefix = "CPACK_WIX_PROPERTY_";
|
|
|
|
std::vector<std::string> options = GetOptions();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < options.size(); ++i) {
|
2014-03-02 02:13:35 +04:00
|
|
|
std::string const& name = options[i];
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.length() > prefix.length() &&
|
|
|
|
name.substr(0, prefix.length()) == prefix) {
|
2014-03-02 02:13:35 +04:00
|
|
|
std::string id = name.substr(prefix.length());
|
|
|
|
std::string value = GetOption(name.c_str());
|
|
|
|
|
|
|
|
includeFile.BeginElement("Property");
|
|
|
|
includeFile.AddAttribute("Id", id);
|
|
|
|
includeFile.AddAttribute("Value", value);
|
|
|
|
includeFile.EndElement("Property");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-20 00:42:36 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_WIX_PROPERTY_ARPINSTALLLOCATION") == 0) {
|
2014-09-20 00:42:36 +04:00
|
|
|
includeFile.BeginElement("Property");
|
|
|
|
includeFile.AddAttribute("Id", "INSTALL_ROOT");
|
|
|
|
includeFile.AddAttribute("Secure", "yes");
|
|
|
|
|
|
|
|
includeFile.BeginElement("RegistrySearch");
|
|
|
|
includeFile.AddAttribute("Id", "FindInstallLocation");
|
|
|
|
includeFile.AddAttribute("Root", "HKLM");
|
2016-05-16 17:34:04 +03:00
|
|
|
includeFile.AddAttribute(
|
|
|
|
"Key", "Software\\Microsoft\\Windows\\"
|
|
|
|
"CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]");
|
2014-09-20 00:42:36 +04:00
|
|
|
includeFile.AddAttribute("Name", "InstallLocation");
|
|
|
|
includeFile.AddAttribute("Type", "raw");
|
|
|
|
includeFile.EndElement("RegistrySearch");
|
|
|
|
includeFile.EndElement("Property");
|
|
|
|
|
|
|
|
includeFile.BeginElement("SetProperty");
|
|
|
|
includeFile.AddAttribute("Id", "ARPINSTALLLOCATION");
|
|
|
|
includeFile.AddAttribute("Value", "[INSTALL_ROOT]");
|
|
|
|
includeFile.AddAttribute("After", "CostFinalize");
|
|
|
|
includeFile.EndElement("SetProperty");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-02 02:13:35 +04:00
|
|
|
}
|
|
|
|
|
2015-02-13 13:57:20 +03:00
|
|
|
void cmCPackWIXGenerator::CreateWiXProductFragmentIncludeFile()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string includeFilename = this->CPackTopLevel + "/product_fragment.wxi";
|
2015-02-13 13:57:20 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXSourceWriter includeFile(this->Logger, includeFilename, true);
|
2015-02-13 13:57:20 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Patch->ApplyFragment("#PRODUCT", includeFile);
|
2015-02-13 13:57:20 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCPackWIXGenerator::CopyDefinition(cmWIXSourceWriter& source,
|
|
|
|
std::string const& name)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
const char* value = GetOption(name.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (value) {
|
2012-10-03 18:08:49 +04:00
|
|
|
AddDefinition(source, name, value);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source,
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& name,
|
|
|
|
std::string const& value)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << name << "=\"" << value << '"';
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
source.AddProcessingInstruction(
|
|
|
|
"define", cmWIXSourceWriter::CMakeEncodingToUtf8(tmp.str()));
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::CreateWiXSourceFiles()
|
|
|
|
{
|
|
|
|
std::string directoryDefinitionsFilename =
|
2014-02-25 02:21:12 +04:00
|
|
|
this->CPackTopLevel + "/directories.wxs";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->WixSources.push_back(directoryDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXDirectoriesSourceWriter directoryDefinitions(
|
|
|
|
this->Logger, directoryDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
directoryDefinitions.BeginElement("Fragment");
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string installRoot;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", installRoot)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.BeginElement("Directory");
|
|
|
|
directoryDefinitions.AddAttribute("Id", "TARGETDIR");
|
|
|
|
directoryDefinitions.AddAttribute("Name", "SourceDir");
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
size_t installRootSize =
|
|
|
|
directoryDefinitions.BeginInstallationPrefixDirectory(
|
|
|
|
GetProgramFilesFolderId(), installRoot);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string fileDefinitionsFilename = this->CPackTopLevel + "/files.wxs";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->WixSources.push_back(fileDefinitionsFilename);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXFilesSourceWriter fileDefinitions(this->Logger,
|
|
|
|
fileDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
fileDefinitions.BeginElement("Fragment");
|
|
|
|
|
|
|
|
std::string featureDefinitionsFilename =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CPackTopLevel + "/features.wxs";
|
2014-02-25 02:21:12 +04:00
|
|
|
|
|
|
|
this->WixSources.push_back(featureDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXFeaturesSourceWriter featureDefinitions(this->Logger,
|
|
|
|
featureDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
featureDefinitions.BeginElement("Fragment");
|
|
|
|
|
|
|
|
featureDefinitions.BeginElement("Feature");
|
|
|
|
featureDefinitions.AddAttribute("Id", "ProductFeature");
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.AddAttribute("Display", "expand");
|
2015-11-09 19:50:21 +03:00
|
|
|
featureDefinitions.AddAttribute("Absent", "disallow");
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.AddAttribute("ConfigurableDirectory", "INSTALL_ROOT");
|
|
|
|
|
|
|
|
std::string cpackPackageName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) {
|
2013-11-20 00:38:09 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.AddAttribute("Title", cpackPackageName);
|
2012-10-03 18:08:49 +04:00
|
|
|
featureDefinitions.AddAttribute("Level", "1");
|
2015-03-06 22:40:53 +03:00
|
|
|
this->Patch->ApplyFragment("#PRODUCTFEATURE", featureDefinitions);
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
const char* package = GetOption("CPACK_WIX_CMAKE_PACKAGE_REGISTRY");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (package) {
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.CreateCMakePackageRegistryEntry(
|
2016-05-16 17:34:04 +03:00
|
|
|
package, GetOption("CPACK_WIX_UPGRADE_GUID"));
|
|
|
|
}
|
2014-01-08 04:28:24 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!CreateFeatureHierarchy(featureDefinitions)) {
|
2014-01-08 04:28:24 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
featureDefinitions.EndElement("Feature");
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
std::set<cmWIXShortcuts::Type> emittedShortcutTypes;
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
cmWIXShortcuts globalShortcuts;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (Components.empty()) {
|
|
|
|
AddComponentsToFeature(toplevel, "ProductFeature", directoryDefinitions,
|
|
|
|
fileDefinitions, featureDefinitions,
|
|
|
|
globalShortcuts);
|
2015-02-21 14:38:14 +03:00
|
|
|
|
|
|
|
globalShortcuts.AddShortcutTypes(emittedShortcutTypes);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
for (std::map<std::string, cmCPackComponent>::const_iterator i =
|
|
|
|
this->Components.begin();
|
|
|
|
i != this->Components.end(); ++i) {
|
2013-11-20 00:38:09 +04:00
|
|
|
cmCPackComponent const& component = i->second;
|
|
|
|
|
|
|
|
std::string componentPath = toplevel;
|
|
|
|
componentPath += "/";
|
|
|
|
componentPath += component.Name;
|
|
|
|
|
|
|
|
std::string componentFeatureId = "CM_C_" + component.Name;
|
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
cmWIXShortcuts featureShortcuts;
|
2013-11-20 00:38:09 +04:00
|
|
|
AddComponentsToFeature(componentPath, componentFeatureId,
|
2016-05-16 17:34:04 +03:00
|
|
|
directoryDefinitions, fileDefinitions,
|
|
|
|
featureDefinitions, featureShortcuts);
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
featureShortcuts.AddShortcutTypes(emittedShortcutTypes);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!CreateShortcuts(component.Name, componentFeatureId,
|
|
|
|
featureShortcuts, false, fileDefinitions,
|
|
|
|
featureDefinitions)) {
|
2015-02-21 14:38:14 +03:00
|
|
|
return false;
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool emitUninstallShortcut =
|
|
|
|
emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) !=
|
|
|
|
emittedShortcutTypes.end();
|
2015-02-21 14:38:14 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!CreateShortcuts(std::string(), "ProductFeature", globalShortcuts,
|
|
|
|
emitUninstallShortcut, fileDefinitions,
|
|
|
|
featureDefinitions)) {
|
2015-02-21 14:38:14 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-05-08 18:39:32 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
featureDefinitions.EndElement("Fragment");
|
|
|
|
fileDefinitions.EndElement("Fragment");
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
directoryDefinitions.EndInstallationPrefixDirectory(installRootSize);
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emittedShortcutTypes.find(cmWIXShortcuts::START_MENU) !=
|
|
|
|
emittedShortcutTypes.end()) {
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.EmitStartMenuFolder(
|
|
|
|
GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"));
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emittedShortcutTypes.find(cmWIXShortcuts::DESKTOP) !=
|
|
|
|
emittedShortcutTypes.end()) {
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.EmitDesktopFolder();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-04 21:40:45 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emittedShortcutTypes.find(cmWIXShortcuts::STARTUP) !=
|
|
|
|
emittedShortcutTypes.end()) {
|
2015-02-21 20:07:36 +03:00
|
|
|
directoryDefinitions.EmitStartupFolder();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-21 20:07:36 +03:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
directoryDefinitions.EndElement("Directory");
|
|
|
|
directoryDefinitions.EndElement("Fragment");
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!GenerateMainSourceFileFromTemplate()) {
|
2014-02-25 02:21:12 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2014-04-19 00:45:30 +04:00
|
|
|
return this->Patch->CheckForUnappliedFragments();
|
2014-02-25 02:21:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GetProgramFilesFolderId() const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetArchitecture() == "x86") {
|
2014-02-25 02:21:12 +04:00
|
|
|
return "ProgramFilesFolder";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-02-25 02:21:12 +04:00
|
|
|
return "ProgramFiles64Folder";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-25 02:21:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate()
|
|
|
|
{
|
2012-10-03 18:08:49 +04:00
|
|
|
std::string wixTemplate = FindTemplate("WIX.template.in");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (GetOption("CPACK_WIX_TEMPLATE") != 0) {
|
2013-07-03 02:19:31 +04:00
|
|
|
wixTemplate = GetOption("CPACK_WIX_TEMPLATE");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (wixTemplate.empty()) {
|
2012-10-03 18:08:49 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Could not find CPack WiX template file WIX.template.in"
|
|
|
|
<< std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath.c_str())) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed creating '"
|
|
|
|
<< mainSourceFilePath << "'' from template." << std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->WixSources.push_back(mainSourceFilePath);
|
2014-01-08 04:28:24 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
bool cmCPackWIXGenerator::CreateFeatureHierarchy(
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions)
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, cmCPackComponentGroup>::const_iterator i =
|
|
|
|
ComponentGroups.begin();
|
|
|
|
i != ComponentGroups.end(); ++i) {
|
2013-11-20 00:38:09 +04:00
|
|
|
cmCPackComponentGroup const& group = i->second;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (group.ParentGroup == 0) {
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitFeatureForComponentGroup(group);
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<std::string, cmCPackComponent>::const_iterator i =
|
|
|
|
this->Components.begin();
|
|
|
|
i != this->Components.end(); ++i) {
|
2013-11-20 00:38:09 +04:00
|
|
|
cmCPackComponent const& component = i->second;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!component.Group) {
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitFeatureForComponent(component);
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::AddComponentsToFeature(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& rootPath, std::string const& featureId,
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXDirectoriesSourceWriter& directoryDefinitions,
|
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions, cmWIXShortcuts& shortcuts)
|
2013-10-23 14:14:39 +04:00
|
|
|
{
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.BeginElement("FeatureRef");
|
|
|
|
featureDefinitions.AddAttribute("Id", featureId);
|
|
|
|
|
|
|
|
std::vector<std::string> cpackPackageExecutablesList;
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES");
|
|
|
|
if (cpackPackageExecutables) {
|
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageExecutables,
|
|
|
|
cpackPackageExecutablesList);
|
|
|
|
if (cpackPackageExecutablesList.size() % 2 != 0) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
|
|
|
"CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
|
|
|
|
"<text label>."
|
|
|
|
<< std::endl);
|
|
|
|
return false;
|
2013-10-23 14:14:39 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2014-02-04 21:40:45 +04:00
|
|
|
std::vector<std::string> cpackPackageDesktopLinksList;
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackPackageDesktopLinks =
|
2014-02-04 21:40:45 +04:00
|
|
|
GetOption("CPACK_CREATE_DESKTOP_LINKS");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cpackPackageDesktopLinks) {
|
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks,
|
|
|
|
cpackPackageDesktopLinksList);
|
|
|
|
}
|
2014-02-04 21:40:45 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
AddDirectoryAndFileDefinitons(rootPath, "INSTALL_ROOT", directoryDefinitions,
|
|
|
|
fileDefinitions, featureDefinitions,
|
|
|
|
cpackPackageExecutablesList,
|
|
|
|
cpackPackageDesktopLinksList, shortcuts);
|
2013-11-20 00:38:09 +04:00
|
|
|
|
|
|
|
featureDefinitions.EndElement("FeatureRef");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
bool cmCPackWIXGenerator::CreateShortcuts(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& cpackComponentName, std::string const& featureId,
|
|
|
|
cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut,
|
2015-02-21 14:38:14 +03:00
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!shortcuts.empty(cmWIXShortcuts::START_MENU)) {
|
|
|
|
if (!this->CreateShortcutsOfSpecificType(
|
|
|
|
cmWIXShortcuts::START_MENU, cpackComponentName, featureId, "",
|
|
|
|
shortcuts, emitUninstallShortcut, fileDefinitions,
|
|
|
|
featureDefinitions)) {
|
2015-02-21 14:38:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-21 14:38:14 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!shortcuts.empty(cmWIXShortcuts::DESKTOP)) {
|
|
|
|
if (!this->CreateShortcutsOfSpecificType(
|
|
|
|
cmWIXShortcuts::DESKTOP, cpackComponentName, featureId, "DESKTOP",
|
|
|
|
shortcuts, false, fileDefinitions, featureDefinitions)) {
|
2015-02-21 14:38:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-21 14:38:14 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!shortcuts.empty(cmWIXShortcuts::STARTUP)) {
|
|
|
|
if (!this->CreateShortcutsOfSpecificType(
|
|
|
|
cmWIXShortcuts::STARTUP, cpackComponentName, featureId, "STARTUP",
|
|
|
|
shortcuts, false, fileDefinitions, featureDefinitions)) {
|
2015-02-21 20:07:36 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-21 20:07:36 +03:00
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmWIXShortcuts::Type type, std::string const& cpackComponentName,
|
|
|
|
std::string const& featureId, std::string const& idPrefix,
|
|
|
|
cmWIXShortcuts const& shortcuts, bool emitUninstallShortcut,
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions)
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
2015-02-21 14:38:14 +03:00
|
|
|
std::string directoryId;
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (type) {
|
2015-02-21 14:38:14 +03:00
|
|
|
case cmWIXShortcuts::START_MENU:
|
|
|
|
directoryId = "PROGRAM_MENU_FOLDER";
|
|
|
|
break;
|
|
|
|
case cmWIXShortcuts::DESKTOP:
|
|
|
|
directoryId = "DesktopFolder";
|
|
|
|
break;
|
2015-02-21 20:07:36 +03:00
|
|
|
case cmWIXShortcuts::STARTUP:
|
|
|
|
directoryId = "StartupFolder";
|
|
|
|
break;
|
2015-02-21 14:38:14 +03:00
|
|
|
default:
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-04 21:40:45 +04:00
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.BeginElement("FeatureRef");
|
|
|
|
featureDefinitions.AddAttribute("Id", featureId);
|
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
std::string cpackVendor;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_PACKAGE_VENDOR", cpackVendor)) {
|
2013-10-23 14:14:39 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
|
|
|
std::string cpackPackageName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName)) {
|
2013-10-23 14:14:39 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
std::string idSuffix;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cpackComponentName.empty()) {
|
|
|
|
idSuffix += "_";
|
|
|
|
idSuffix += cpackComponentName;
|
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2015-02-21 14:38:14 +03:00
|
|
|
std::string componentId = "CM_SHORTCUT";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (idPrefix.size()) {
|
2015-02-21 14:38:14 +03:00
|
|
|
componentId += "_" + idPrefix;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-21 14:38:14 +03:00
|
|
|
|
|
|
|
componentId += idSuffix;
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
fileDefinitions.BeginElement("DirectoryRef");
|
2015-02-21 14:38:14 +03:00
|
|
|
fileDefinitions.AddAttribute("Id", directoryId);
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
fileDefinitions.BeginElement("Component");
|
2013-11-20 00:38:09 +04:00
|
|
|
fileDefinitions.AddAttribute("Id", componentId);
|
2013-10-23 14:14:39 +04:00
|
|
|
fileDefinitions.AddAttribute("Guid", "*");
|
|
|
|
|
2015-12-12 02:39:08 +03:00
|
|
|
this->Patch->ApplyFragment(componentId, fileDefinitions);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string registryKey =
|
|
|
|
std::string("Software\\") + cpackVendor + "\\" + cpackPackageName;
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
shortcuts.EmitShortcuts(type, registryKey, cpackComponentName,
|
|
|
|
fileDefinitions);
|
2014-02-04 21:40:45 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (type == cmWIXShortcuts::START_MENU) {
|
|
|
|
fileDefinitions.EmitRemoveFolder("CM_REMOVE_PROGRAM_MENU_FOLDER" +
|
|
|
|
idSuffix);
|
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emitUninstallShortcut) {
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitUninstallShortcut(cpackPackageName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
|
|
|
fileDefinitions.EndElement("Component");
|
|
|
|
fileDefinitions.EndElement("DirectoryRef");
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.EndElement("FeatureRef");
|
2013-10-23 14:14:39 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
bool cmCPackWIXGenerator::CreateLicenseFile()
|
|
|
|
{
|
|
|
|
std::string licenseSourceFilename;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string licenseDestinationFilename;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string extension = GetRightmostExtension(licenseSourceFilename);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (extension == ".rtf") {
|
|
|
|
cmSystemTools::CopyAFile(licenseSourceFilename.c_str(),
|
|
|
|
licenseDestinationFilename.c_str());
|
|
|
|
} else if (extension == ".txt") {
|
2012-10-03 18:08:49 +04:00
|
|
|
cmWIXRichTextFormatWriter rtfWriter(licenseDestinationFilename);
|
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream licenseSource(licenseSourceFilename.c_str());
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (std::getline(licenseSource, line)) {
|
2012-10-03 18:08:49 +04:00
|
|
|
rtfWriter.AddText(line);
|
|
|
|
rtfWriter.AddText("\n");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-10-03 18:08:49 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"unsupported WiX License file extension '"
|
|
|
|
<< extension << "'" << std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& topdir, std::string const& directoryId,
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXDirectoriesSourceWriter& directoryDefinitions,
|
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions,
|
2015-02-21 19:30:31 +03:00
|
|
|
std::vector<std::string> const& packageExecutables,
|
|
|
|
std::vector<std::string> const& desktopExecutables,
|
2015-02-21 14:38:14 +03:00
|
|
|
cmWIXShortcuts& shortcuts)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
cmsys::Directory dir;
|
|
|
|
dir.Load(topdir.c_str());
|
|
|
|
|
2014-09-27 19:34:39 +04:00
|
|
|
std::string relativeDirectoryPath =
|
|
|
|
cmSystemTools::RelativePath(toplevel.c_str(), topdir.c_str());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (relativeDirectoryPath.empty()) {
|
2014-10-03 17:10:51 +04:00
|
|
|
relativeDirectoryPath = ".";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-03 17:10:51 +04:00
|
|
|
|
2015-12-10 19:38:18 +03:00
|
|
|
cmInstalledFile const* directoryInstalledFile = this->GetInstalledFile(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->RelativePathWithoutComponentPrefix(relativeDirectoryPath));
|
2014-09-27 19:34:39 +04:00
|
|
|
|
|
|
|
bool emptyDirectory = dir.GetNumberOfFiles() == 2;
|
|
|
|
bool createDirectory = false;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emptyDirectory) {
|
2014-09-27 19:34:39 +04:00
|
|
|
createDirectory = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-27 19:34:39 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (directoryInstalledFile) {
|
|
|
|
if (directoryInstalledFile->HasProperty("CPACK_WIX_ACL")) {
|
2014-09-27 19:34:39 +04:00
|
|
|
createDirectory = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-02 03:51:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (createDirectory) {
|
2014-09-27 19:34:39 +04:00
|
|
|
std::string componentId = fileDefinitions.EmitComponentCreateFolder(
|
|
|
|
directoryId, GenerateGUID(), directoryInstalledFile);
|
2014-03-02 03:51:42 +04:00
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-02 03:51:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emptyDirectory) {
|
2014-03-02 03:51:42 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-02 03:51:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < dir.GetNumberOfFiles(); ++i) {
|
2012-10-03 18:08:49 +04:00
|
|
|
std::string fileName = dir.GetFile(static_cast<unsigned long>(i));
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fileName == "." || fileName == "..") {
|
2012-10-03 18:08:49 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string fullPath = topdir + "/" + fileName;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string relativePath =
|
|
|
|
cmSystemTools::RelativePath(toplevel.c_str(), fullPath.c_str());
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
std::string id = PathToId(relativePath);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(fullPath.c_str())) {
|
2013-10-11 00:49:33 +04:00
|
|
|
std::string subDirectoryId = std::string("CM_D") + id;
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
directoryDefinitions.BeginElement("Directory");
|
|
|
|
directoryDefinitions.AddAttribute("Id", subDirectoryId);
|
|
|
|
directoryDefinitions.AddAttribute("Name", fileName);
|
|
|
|
|
|
|
|
AddDirectoryAndFileDefinitons(
|
2016-05-16 17:34:04 +03:00
|
|
|
fullPath, subDirectoryId, directoryDefinitions, fileDefinitions,
|
|
|
|
featureDefinitions, packageExecutables, desktopExecutables, shortcuts);
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2014-04-19 00:45:30 +04:00
|
|
|
this->Patch->ApplyFragment(subDirectoryId, directoryDefinitions);
|
2013-10-23 14:14:39 +04:00
|
|
|
directoryDefinitions.EndElement("Directory");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-12-10 19:38:18 +03:00
|
|
|
cmInstalledFile const* installedFile = this->GetInstalledFile(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->RelativePathWithoutComponentPrefix(relativePath));
|
2014-05-17 00:43:56 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (installedFile) {
|
2015-02-21 19:30:31 +03:00
|
|
|
shortcuts.CreateFromProperties(id, directoryId, *installedFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-21 19:30:31 +03:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string componentId = fileDefinitions.EmitComponentFile(
|
2014-05-17 00:43:56 +04:00
|
|
|
directoryId, id, fullPath, *(this->Patch), installedFile);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t j = 0; j < packageExecutables.size(); ++j) {
|
2013-10-23 14:14:39 +04:00
|
|
|
std::string const& executableName = packageExecutables[j++];
|
|
|
|
std::string const& textLabel = packageExecutables[j];
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::LowerCase(fileName) ==
|
|
|
|
cmSystemTools::LowerCase(executableName) + ".exe") {
|
2015-02-21 14:38:14 +03:00
|
|
|
cmWIXShortcut shortcut;
|
2016-05-16 17:34:04 +03:00
|
|
|
shortcut.label = textLabel;
|
2013-10-23 14:14:39 +04:00
|
|
|
shortcut.workingDirectoryId = directoryId;
|
2015-02-21 14:38:14 +03:00
|
|
|
shortcuts.insert(cmWIXShortcuts::START_MENU, id, shortcut);
|
2014-02-04 21:40:45 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!desktopExecutables.empty() &&
|
|
|
|
std::find(desktopExecutables.begin(), desktopExecutables.end(),
|
|
|
|
executableName) != desktopExecutables.end()) {
|
|
|
|
shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut);
|
2013-03-01 06:09:58 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCPackWIXGenerator::RequireOption(std::string const& name,
|
|
|
|
std::string& value) const
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
const char* tmp = GetOption(name.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tmp) {
|
2012-10-03 18:08:49 +04:00
|
|
|
value = tmp;
|
|
|
|
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Required variable "
|
|
|
|
<< name << " not set" << std::endl);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GetArchitecture() const
|
|
|
|
{
|
|
|
|
std::string void_p_size;
|
|
|
|
RequireOption("CPACK_WIX_SIZEOF_VOID_P", void_p_size);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (void_p_size == "8") {
|
2012-10-03 18:08:49 +04:00
|
|
|
return "x64";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-10-03 18:08:49 +04:00
|
|
|
return "x86";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GenerateGUID()
|
|
|
|
{
|
|
|
|
UUID guid;
|
|
|
|
UuidCreate(&guid);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
unsigned short* tmp = 0;
|
2013-12-05 09:17:24 +04:00
|
|
|
UuidToStringW(&guid, &tmp);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
std::string result =
|
|
|
|
cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(tmp));
|
|
|
|
RpcStringFreeW(&tmp);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return cmSystemTools::UpperCase(result);
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmCPackWIXGenerator::QuotePath(std::string const& path)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
return std::string("\"") + path + '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GetRightmostExtension(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& filename)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string extension;
|
|
|
|
|
|
|
|
std::string::size_type i = filename.rfind(".");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != std::string::npos) {
|
2012-10-03 18:08:49 +04:00
|
|
|
extension = filename.substr(i);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return cmSystemTools::LowerCase(extension);
|
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmCPackWIXGenerator::PathToId(std::string const& path)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
id_map_t::const_iterator i = PathToIdMap.find(path);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != PathToIdMap.end())
|
|
|
|
return i->second;
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
std::string id = CreateNewIdForPath(path);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> components;
|
|
|
|
cmSystemTools::SplitPath(path.c_str(), components, false);
|
|
|
|
|
|
|
|
size_t replacementCount = 0;
|
|
|
|
|
|
|
|
std::string identifier;
|
|
|
|
std::string currentComponent;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 1; i < components.size(); ++i) {
|
|
|
|
if (i != 1)
|
|
|
|
identifier += '.';
|
2013-10-11 00:49:33 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
currentComponent =
|
|
|
|
NormalizeComponentForId(components[i], replacementCount);
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
identifier += currentComponent;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
std::string idPrefix = "P";
|
|
|
|
size_t replacementPercent = replacementCount * 100 / identifier.size();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (replacementPercent > 33 || identifier.size() > 60) {
|
2013-10-11 00:49:33 +04:00
|
|
|
identifier = CreateHashedId(path, currentComponent);
|
|
|
|
idPrefix = "H";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
std::stringstream result;
|
|
|
|
result << idPrefix << "_" << identifier;
|
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
size_t ambiguityCount = ++IdAmbiguityCounter[identifier];
|
2013-10-11 00:49:33 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ambiguityCount > 999) {
|
2013-10-11 00:49:33 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Error while trying to generate a unique Id for '"
|
|
|
|
<< path << "'" << std::endl);
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
return std::string();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (ambiguityCount > 1) {
|
2013-10-11 00:49:33 +04:00
|
|
|
result << "_" << ambiguityCount;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
std::string resultString = result.str();
|
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
PathToIdMap[path] = resultString;
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
return resultString;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::CreateHashedId(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& path, std::string const& normalizedFilename)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmCryptoHash> sha1 = cmCryptoHash::New("SHA1");
|
|
|
|
std::string hash = sha1->HashString(path.c_str());
|
|
|
|
|
|
|
|
std::string identifier;
|
|
|
|
identifier += hash.substr(0, 7) + "_";
|
|
|
|
|
|
|
|
const size_t maxFileNameLength = 52;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (normalizedFilename.length() > maxFileNameLength) {
|
2013-10-11 00:49:33 +04:00
|
|
|
identifier += normalizedFilename.substr(0, maxFileNameLength - 3);
|
|
|
|
identifier += "...";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-11 00:49:33 +04:00
|
|
|
identifier += normalizedFilename;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
return identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::NormalizeComponentForId(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& component, size_t& replacementCount)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
result.resize(component.size());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < component.size(); ++i) {
|
2013-10-11 00:49:33 +04:00
|
|
|
char c = component[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (IsLegalIdCharacter(c)) {
|
2013-10-11 00:49:33 +04:00
|
|
|
result[i] = c;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-11 00:49:33 +04:00
|
|
|
result[i] = '_';
|
2016-05-16 17:34:04 +03:00
|
|
|
++replacementCount;
|
2013-10-11 00:49:33 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::IsLegalIdCharacter(char c)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
|
|
|
|
(c >= 'A' && c <= 'Z') || c == '_' || c == '.';
|
2013-10-11 00:49:33 +04:00
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCPackWIXGenerator::CollectExtensions(std::string const& variableName,
|
|
|
|
extension_set_t& extensions)
|
2013-11-10 22:48:29 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* variableContent = GetOption(variableName.c_str());
|
|
|
|
if (!variableContent)
|
|
|
|
return;
|
2013-11-10 22:48:29 +04:00
|
|
|
|
|
|
|
std::vector<std::string> list;
|
|
|
|
cmSystemTools::ExpandListArgument(variableContent, list);
|
2014-11-25 18:33:00 +03:00
|
|
|
extensions.insert(list.begin(), list.end());
|
2013-11-10 22:48:29 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName,
|
|
|
|
std::ostream& stream)
|
2013-11-10 22:48:29 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* variableContent = GetOption(variableName.c_str());
|
|
|
|
if (!variableContent)
|
|
|
|
return;
|
2013-11-10 22:48:29 +04:00
|
|
|
|
|
|
|
std::vector<std::string> list;
|
|
|
|
cmSystemTools::ExpandListArgument(variableContent, list);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i = list.begin();
|
|
|
|
i != list.end(); ++i) {
|
|
|
|
stream << " " << QuotePath(*i);
|
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
}
|
2015-12-10 19:38:18 +03:00
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::RelativePathWithoutComponentPrefix(
|
|
|
|
std::string const& path)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Components.empty()) {
|
2015-12-10 19:38:18 +03:00
|
|
|
return path;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-12-10 19:38:18 +03:00
|
|
|
|
|
|
|
std::string::size_type pos = path.find('/');
|
|
|
|
|
|
|
|
return path.substr(pos + 1);
|
|
|
|
}
|