Merge topic 'CPackNSIS-warnDESTDIRandABSOLUTE'
4986d52
Use CPACK_xxx and CMAKE_xxx in a consistent way.f90223c
Fix KWStyle warning47f0dbd
CPack add necessary check to detect/warns/error on ABSOLUTE DESTINATION6ba055b
CPack add easy possibility to warn about CPACK_SET_DESTDIR
This commit is contained in:
commit
db1857e142
|
@ -77,4 +77,35 @@ void cmCPackDocumentVariables::DefineVariables(cmake* cm)
|
|||
"which is done right before packaging the files."
|
||||
" The script is not called by e.g.: make install.", false,
|
||||
"Variables common to all CPack generators");
|
||||
|
||||
cm->DefineProperty
|
||||
("CPACK_ABSOLUTE_DESTINATION_FILES", cmProperty::VARIABLE,
|
||||
"List of files which have been installed using "
|
||||
" an ABSOLUTE DESTINATION path.",
|
||||
"This variable is a Read-Only variable which is set internally"
|
||||
" by CPack during installation and before packaging using"
|
||||
" CMAKE_ABSOLUTE_DESTINATION_FILES defined in cmake_install.cmake "
|
||||
"scripts. The value can be used within CPack project configuration"
|
||||
" file and/or CPack<GEN>.cmake file of <GEN> generator.", false,
|
||||
"Variables common to all CPack generators");
|
||||
|
||||
cm->DefineProperty
|
||||
("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", cmProperty::VARIABLE,
|
||||
"Ask CPack to warn each time a file with absolute INSTALL"
|
||||
" DESTINATION is encountered.",
|
||||
"This variable triggers the definition of "
|
||||
"CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION when CPack runs"
|
||||
" cmake_install.cmake scripts.", false,
|
||||
"Variables common to all CPack generators");
|
||||
|
||||
cm->DefineProperty
|
||||
("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", cmProperty::VARIABLE,
|
||||
"Ask CPack to error out as soon as a file with absolute INSTALL"
|
||||
" DESTINATION is encountered.",
|
||||
"The fatal error is emitted before the installation of "
|
||||
"the offending file takes place. Some CPack generators, like NSIS,"
|
||||
"enforce this internally. "
|
||||
"This variable triggers the definition of"
|
||||
"CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION when CPack runs"
|
||||
"Variables common to all CPack generators");
|
||||
}
|
||||
|
|
|
@ -62,10 +62,31 @@ void cmCPackGenerator::DisplayVerboseOutput(const char* msg,
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
int cmCPackGenerator::PrepareNames()
|
||||
{
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
||||
"Create temp directory." << std::endl);
|
||||
|
||||
// checks CPACK_SET_DESTDIR support
|
||||
if (IsOn("CPACK_SET_DESTDIR"))
|
||||
{
|
||||
if (SETDESTDIR_UNSUPPORTED==SupportsSetDestdir())
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"CPACK_SET_DESTDIR is set to ON but the '"
|
||||
<< Name << "' generator does NOT support it."
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
else if (SETDESTDIR_SHOULD_NOT_BE_USED==SupportsSetDestdir())
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_WARNING,
|
||||
"CPACK_SET_DESTDIR is set to ON but it is "
|
||||
<< "usually a bad idea to do that with '"
|
||||
<< Name << "' generator. Use at your own risk."
|
||||
<< std::endl);
|
||||
}
|
||||
}
|
||||
|
||||
std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
|
||||
tempDirectory += "/_CPack_Packages/";
|
||||
const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
|
||||
|
@ -831,8 +852,35 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
|
|||
filesBefore = glB.GetFiles();
|
||||
std::sort(filesBefore.begin(),filesBefore.end());
|
||||
}
|
||||
|
||||
// If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION
|
||||
// then forward request to cmake_install.cmake script
|
||||
if (this->GetOption("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION"))
|
||||
{
|
||||
mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION",
|
||||
"1");
|
||||
}
|
||||
// If current CPack generator does support
|
||||
// ABSOLUTE INSTALL DESTINATION or CPack has been asked for
|
||||
// then ask cmake_install.cmake script to error out
|
||||
// as soon as it occurs (before installing file)
|
||||
if (!SupportsAbsoluteDestination() ||
|
||||
this->GetOption("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION"))
|
||||
{
|
||||
mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION",
|
||||
"1");
|
||||
}
|
||||
// do installation
|
||||
int res = mf->ReadListFile(0, installFile.c_str());
|
||||
// forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
|
||||
// to CPack (may be used by generators like CPack RPM or DEB)
|
||||
// in order to transparently handle ABSOLUTE PATH
|
||||
if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"))
|
||||
{
|
||||
mf->AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES",
|
||||
mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES"));
|
||||
}
|
||||
|
||||
// Now rebuild the list of files after installation
|
||||
// of the current component (if we are in component install)
|
||||
if (componentInstall)
|
||||
|
@ -956,6 +1004,8 @@ int cmCPackGenerator::DoPackage()
|
|||
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
||||
"Create package using " << this->Name.c_str() << std::endl);
|
||||
|
||||
// Prepare CPack internal name and check
|
||||
// values for many CPACK_xxx vars
|
||||
if ( !this->PrepareNames() )
|
||||
{
|
||||
return 0;
|
||||
|
@ -1433,6 +1483,19 @@ std::string cmCPackGenerator::GetComponentPackageFileName(
|
|||
return initialPackageFileName + suffix;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
enum cmCPackGenerator::CPackSetDestdirSupport
|
||||
cmCPackGenerator::SupportsSetDestdir() const
|
||||
{
|
||||
return cmCPackGenerator::SETDESTDIR_SUPPORTED;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCPackGenerator::SupportsAbsoluteDestination() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCPackGenerator::SupportsComponentInstallation() const
|
||||
{
|
||||
|
|
|
@ -189,6 +189,38 @@ protected:
|
|||
virtual int InstallProjectViaInstallCMakeProjects(
|
||||
bool setDestDir, const char* tempInstallDirectory);
|
||||
|
||||
/**
|
||||
* The various level of support of
|
||||
* CPACK_SET_DESTDIR used by the generator.
|
||||
*/
|
||||
enum CPackSetDestdirSupport {
|
||||
/* the generator works with or without it */
|
||||
SETDESTDIR_SUPPORTED,
|
||||
/* the generator works best if automatically handled */
|
||||
SETDESTDIR_INTERNALLY_SUPPORTED,
|
||||
/* no official support, use at your own risk */
|
||||
SETDESTDIR_SHOULD_NOT_BE_USED,
|
||||
/* officially NOT supported */
|
||||
SETDESTDIR_UNSUPPORTED
|
||||
};
|
||||
|
||||
/**
|
||||
* Does the CPack generator support CPACK_SET_DESTDIR?
|
||||
* The default legacy value is 'SETDESTDIR_SUPPORTED' generator
|
||||
* have to override it in order change this.
|
||||
* @return CPackSetDestdirSupport
|
||||
*/
|
||||
virtual enum CPackSetDestdirSupport SupportsSetDestdir() const;
|
||||
|
||||
/**
|
||||
* Does the CPack generator support absolute path
|
||||
* in INSTALL DESTINATION?
|
||||
* The default legacy value is 'true' generator
|
||||
* have to override it in order change this.
|
||||
* @return true if supported false otherwise
|
||||
*/
|
||||
virtual bool SupportsAbsoluteDestination() const;
|
||||
|
||||
/**
|
||||
* Does the CPack generator support component installation?.
|
||||
* Some Generators requires the user to set
|
||||
|
|
|
@ -64,6 +64,7 @@ int cmCPackNSISGenerator::PackageFiles()
|
|||
<< std::endl);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
||||
std::string tmpFile = nsisFileName;
|
||||
tmpFile += "/NSISOutput.log";
|
||||
|
@ -630,6 +631,19 @@ bool cmCPackNSISGenerator::GetListOfSubdirectories(const char* topdir,
|
|||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
enum cmCPackGenerator::CPackSetDestdirSupport
|
||||
cmCPackNSISGenerator::SupportsSetDestdir() const
|
||||
{
|
||||
return cmCPackGenerator::SETDESTDIR_SHOULD_NOT_BE_USED;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCPackNSISGenerator::SupportsAbsoluteDestination() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCPackNSISGenerator::SupportsComponentInstallation() const
|
||||
{
|
||||
|
|
|
@ -44,6 +44,8 @@ protected:
|
|||
bool GetListOfSubdirectories(const char* dir,
|
||||
std::vector<std::string>& dirs);
|
||||
|
||||
enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const;
|
||||
virtual bool SupportsAbsoluteDestination() const;
|
||||
virtual bool SupportsComponentInstallation() const;
|
||||
|
||||
/// Produce a string that contains the NSIS code to describe a
|
||||
|
|
|
@ -843,6 +843,36 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
|
|||
"Default is ON.",false,
|
||||
"Variables That Change Behavior");
|
||||
|
||||
cm->DefineProperty
|
||||
("CMAKE_ABSOLUTE_DESTINATION_FILES", cmProperty::VARIABLE,
|
||||
"List of files which have been installed using "
|
||||
" an ABSOLUTE DESTINATION path.",
|
||||
"This variable is defined by CMake-generated cmake_install.cmake "
|
||||
"scripts."
|
||||
" It can be used (read-only) by program or script that source those"
|
||||
" install scripts. This is used by some CPack generators (e.g. RPM).",
|
||||
false,
|
||||
"Variables That Change Behavior");
|
||||
|
||||
cm->DefineProperty
|
||||
("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", cmProperty::VARIABLE,
|
||||
"Ask cmake_install.cmake script to warn each time a file with "
|
||||
"absolute INSTALL DESTINATION is encountered.",
|
||||
"This variable is used by CMake-generated cmake_install.cmake"
|
||||
" scripts. If ones set this variable to ON while running the"
|
||||
" script, it may get warning messages from the script.", false,
|
||||
"Variables That Change Behavior");
|
||||
|
||||
cm->DefineProperty
|
||||
("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", cmProperty::VARIABLE,
|
||||
"Ask cmake_install.cmake script to error out as soon as "
|
||||
"a file with absolute INSTALL DESTINATION is encountered.",
|
||||
"The fatal error is emitted before the installation of "
|
||||
"the offending file takes place."
|
||||
" This variable is used by CMake-generated cmake_install.cmake"
|
||||
" scripts. If ones set this variable to ON while running the"
|
||||
" script, it may get fatal error messages from the script.",false,
|
||||
"Variables That Change Behavior");
|
||||
|
||||
// Variables defined by CMake that describe the system
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ void cmInstallGenerator
|
|||
std::string dest = this->GetInstallDestination();
|
||||
if (cmSystemTools::FileIsFullPath(dest.c_str()))
|
||||
{
|
||||
os << "list(APPEND CPACK_ABSOLUTE_DESTINATION_FILES\n";
|
||||
os << "list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES\n";
|
||||
os << indent << " \"";
|
||||
for(std::vector<std::string>::const_iterator fi = files.begin();
|
||||
fi != files.end(); ++fi)
|
||||
|
@ -80,6 +80,16 @@ void cmInstallGenerator
|
|||
}
|
||||
}
|
||||
os << "\")\n";
|
||||
os << indent << "IF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
||||
os << indent << indent << "message(WARNING \"ABSOLUTE path INSTALL "
|
||||
<< "DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
|
||||
os << indent << "ENDIF (CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
||||
|
||||
os << indent << "IF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
||||
os << indent << indent << "message(FATAL_ERROR \"ABSOLUTE path INSTALL "
|
||||
<< "DESTINATION forbidden (by caller): "
|
||||
<< "${CMAKE_ABSOLUTE_DESTINATION_FILES}\")\n";
|
||||
os << indent << "ENDIF (CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
|
||||
}
|
||||
os << "FILE(INSTALL DESTINATION \"" << dest << "\" TYPE " << stype.c_str();
|
||||
if(optional)
|
||||
|
|
Loading…
Reference in New Issue