2006-01-02 07:21:05 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
|
|
|
|
#include "cmCPackNSISGenerator.h"
|
|
|
|
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2006-01-03 00:14:21 +03:00
|
|
|
#include "cmCPackLog.h"
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
#include <cmsys/SystemTools.hxx>
|
|
|
|
#include <cmsys/Glob.hxx>
|
2006-02-16 23:20:23 +03:00
|
|
|
#include <cmsys/Directory.hxx>
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackNSISGenerator::cmCPackNSISGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackNSISGenerator::~cmCPackNSISGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCPackNSISGenerator::CompressFiles(const char* outFileName, const char* toplevel,
|
|
|
|
const std::vector<std::string>& files)
|
|
|
|
{
|
|
|
|
(void)outFileName; // TODO: Fix nsis to force out file name
|
|
|
|
(void)toplevel;
|
|
|
|
std::string nsisInFileName = this->FindTemplate("NSIS.template.in");
|
|
|
|
if ( nsisInFileName.size() == 0 )
|
|
|
|
{
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack error: Could not find NSIS installer template file." << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
std::string tmpFile = nsisFileName;
|
|
|
|
tmpFile += "/NSISOutput.log";
|
|
|
|
nsisFileName += "/project.nsi";
|
2006-02-16 23:20:23 +03:00
|
|
|
cmOStringStream str;
|
|
|
|
std::vector<std::string>::const_iterator it;
|
|
|
|
for ( it = files.begin(); it != files.end(); ++ it )
|
|
|
|
{
|
|
|
|
std::string fileN = cmSystemTools::RelativePath(toplevel,
|
|
|
|
it->c_str());
|
|
|
|
cmSystemTools::ReplaceString(fileN, "/", "\\");
|
|
|
|
str << " Delete \"$INSTDIR\\" << fileN.c_str() << "\"" << std::endl;
|
|
|
|
}
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " << str.str().c_str() << std::endl);
|
|
|
|
this->SetOption("CPACK_NSIS_DELETE_FILES", str.str().c_str());
|
|
|
|
std::vector<std::string> dirs;
|
|
|
|
this->GetListOfSubdirectories(toplevel, dirs);
|
|
|
|
std::vector<std::string>::const_iterator sit;
|
|
|
|
cmOStringStream dstr;
|
|
|
|
for ( sit = dirs.begin(); sit != dirs.end(); ++ sit )
|
|
|
|
{
|
|
|
|
std::string fileN = cmSystemTools::RelativePath(toplevel,
|
|
|
|
sit->c_str());
|
|
|
|
if ( fileN.empty() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cmSystemTools::ReplaceString(fileN, "/", "\\");
|
|
|
|
dstr << " RMDir \"$INSTDIR\\" << fileN.c_str() << "\"" << std::endl;
|
|
|
|
}
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: " << dstr.str().c_str() << std::endl);
|
|
|
|
this->SetOption("CPACK_NSIS_DELETE_DIRECTORIES", dstr.str().c_str());
|
|
|
|
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << nsisInFileName << " to " << nsisFileName << std::endl);
|
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 + "\"";
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << nsisCmd.c_str() << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
|
|
|
bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
|
|
|
|
if ( !res || retVal )
|
|
|
|
{
|
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
|
|
|
ofs << "# Run command: " << nsisCmd.c_str() << std::endl
|
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output.c_str() << std::endl;
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running NSIS command: " << nsisCmd.c_str() << std::endl
|
|
|
|
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-01-03 01:28:20 +03:00
|
|
|
int cmCPackNSISGenerator::Initialize(const char* name, cmMakefile* mf)
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2006-01-03 01:28:20 +03:00
|
|
|
int res = this->Superclass::Initialize(name, mf);
|
|
|
|
if ( !res )
|
|
|
|
{
|
|
|
|
return res;
|
|
|
|
}
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()" << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
std::vector<std::string> path;
|
|
|
|
std::string nsisPath;
|
|
|
|
if ( !cmsys::SystemTools::ReadRegistryValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS",
|
|
|
|
nsisPath) )
|
|
|
|
{
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find NSIS registry value" << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
path.push_back(nsisPath);
|
|
|
|
nsisPath = cmSystemTools::FindProgram("makensis", path, false);
|
|
|
|
if ( nsisPath.empty() )
|
|
|
|
{
|
2006-01-03 00:14:21 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find NSIS compiler" << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
this->SetOption("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
|
2006-02-14 22:29:15 +03:00
|
|
|
|
|
|
|
const char* cpackPackageExecutables = this->GetOption("CPACK_PACKAGE_EXECUTABLES");
|
|
|
|
if ( cpackPackageExecutables )
|
|
|
|
{
|
2006-02-16 23:55:16 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: " << cpackPackageExecutables << "." << std::endl);
|
2006-02-14 22:29:15 +03:00
|
|
|
cmOStringStream str;
|
|
|
|
cmOStringStream deleteStr;
|
|
|
|
std::vector<std::string> cpackPackageExecutablesVector;
|
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageExecutables,cpackPackageExecutablesVector);
|
|
|
|
if ( cpackPackageExecutablesVector.size() % 2 != 0 )
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and <icon name>." << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
std::vector<std::string>::iterator it;
|
|
|
|
for ( it = cpackPackageExecutablesVector.begin(); it != cpackPackageExecutablesVector.end();
|
|
|
|
++it )
|
|
|
|
{
|
|
|
|
std::string execName = *it;
|
|
|
|
++ it;
|
|
|
|
std::string linkName = *it;
|
2006-02-16 23:55:16 +03:00
|
|
|
str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName << ".lnk\" \"$INSTDIR\\bin\\" << execName << ".exe\"" << std::endl;
|
2006-02-14 22:29:15 +03:00
|
|
|
deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName << ".lnk\"" << std::endl;
|
|
|
|
}
|
|
|
|
this->SetOption("CPACK_NSIS_CREATE_ICONS", str.str().c_str());
|
|
|
|
this->SetOption("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str());
|
|
|
|
}
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-02-16 23:20:23 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool cmCPackNSISGenerator::GetListOfSubdirectories(const char* topdir, std::vector<std::string>& dirs)
|
|
|
|
{
|
|
|
|
cmsys::Directory dir;
|
|
|
|
dir.Load(topdir);
|
|
|
|
size_t fileNum;
|
|
|
|
for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum)
|
|
|
|
{
|
|
|
|
if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
|
|
|
|
strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
|
|
|
|
{
|
|
|
|
kwsys_stl::string fullPath = topdir;
|
|
|
|
fullPath += "/";
|
|
|
|
fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
|
|
|
|
if(cmsys::SystemTools::FileIsDirectory(fullPath.c_str()) &&
|
|
|
|
!cmsys::SystemTools::FileIsSymlink(fullPath.c_str()))
|
|
|
|
{
|
|
|
|
if (!this->GetListOfSubdirectories(fullPath.c_str(), dirs))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dirs.push_back(topdir);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|