2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-06-08 19:57:16 +04: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.
|
2007-06-08 19:57:16 +04: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.
|
|
|
|
============================================================================*/
|
2007-06-08 19:57:16 +04:00
|
|
|
#include "cmExportCommand.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2007-06-08 19:57:16 +04:00
|
|
|
#include "cmake.h"
|
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
#include <cmsys/Encoding.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2009-09-01 22:04:53 +04:00
|
|
|
|
2016-07-12 20:26:55 +03:00
|
|
|
#include "cmExportBuildAndroidMKGenerator.h"
|
2008-01-28 16:38:36 +03:00
|
|
|
#include "cmExportBuildFileGenerator.h"
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2009-09-28 17:45:34 +04:00
|
|
|
#if defined(__HAIKU__)
|
2013-10-05 18:31:36 +04:00
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <StorageDefs.h>
|
2009-09-28 17:45:34 +04:00
|
|
|
#endif
|
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
cmExportCommand::cmExportCommand()
|
2016-05-16 17:34:04 +03:00
|
|
|
: cmCommand()
|
|
|
|
, ArgumentGroup()
|
|
|
|
, Targets(&Helper, "TARGETS")
|
|
|
|
, Append(&Helper, "APPEND", &ArgumentGroup)
|
|
|
|
, ExportSetName(&Helper, "EXPORT", &ArgumentGroup)
|
|
|
|
, Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
|
|
|
|
, Filename(&Helper, "FILE", &ArgumentGroup)
|
|
|
|
, ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup)
|
2016-07-12 20:26:55 +03:00
|
|
|
, AndroidMKFile(&Helper, "ANDROID_MK")
|
2007-07-02 23:43:21 +04:00
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
this->ExportSet = CM_NULLPTR;
|
2007-07-02 23:43:21 +04:00
|
|
|
}
|
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
// cmExportCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2007-06-08 19:57:16 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 2) {
|
2007-06-08 19:57:16 +04:00
|
|
|
this->SetError("called with too few arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[0] == "PACKAGE") {
|
2009-09-01 22:04:53 +04:00
|
|
|
return this->HandlePackage(args);
|
2016-09-16 23:45:24 +03:00
|
|
|
}
|
|
|
|
if (args[0] == "EXPORT") {
|
2016-06-27 23:44:16 +03:00
|
|
|
this->ExportSetName.Follows(CM_NULLPTR);
|
2013-12-23 20:07:26 +04:00
|
|
|
this->ArgumentGroup.Follows(&this->ExportSetName);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-06-27 23:44:16 +03:00
|
|
|
this->Targets.Follows(CM_NULLPTR);
|
2013-12-23 20:07:26 +04:00
|
|
|
this->ArgumentGroup.Follows(&this->Targets);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
|
2007-07-02 23:43:21 +04:00
|
|
|
std::vector<std::string> unknownArgs;
|
|
|
|
this->Helper.Parse(&args, &unknownArgs);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!unknownArgs.empty()) {
|
2007-07-02 23:43:21 +04:00
|
|
|
this->SetError("Unknown arguments.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-02 23:43:21 +04:00
|
|
|
|
2013-12-23 20:07:26 +04:00
|
|
|
std::string fname;
|
2016-07-12 20:26:55 +03:00
|
|
|
bool android = false;
|
|
|
|
if (this->AndroidMKFile.WasFound()) {
|
|
|
|
fname = this->AndroidMKFile.GetString();
|
|
|
|
android = true;
|
|
|
|
}
|
|
|
|
if (!this->Filename.WasFound() && fname.empty()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[0] != "EXPORT") {
|
2013-12-23 20:07:26 +04:00
|
|
|
this->SetError("FILE <filename> option missing.");
|
|
|
|
return false;
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fname = this->ExportSetName.GetString() + ".cmake";
|
2016-07-12 20:26:55 +03:00
|
|
|
} else if (fname.empty()) {
|
2013-12-23 20:07:26 +04:00
|
|
|
// Make sure the file has a .cmake extension.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString()) !=
|
|
|
|
".cmake") {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "FILE option given filename \"" << this->Filename.GetString()
|
|
|
|
<< "\" which does not have an extension of \".cmake\".\n";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2013-12-23 20:07:26 +04:00
|
|
|
return false;
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fname = this->Filename.GetString();
|
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Get the file to write.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsFullPath(fname.c_str())) {
|
|
|
|
if (!this->Makefile->CanIWriteThisFile(fname.c_str())) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-01-28 16:38:36 +03:00
|
|
|
e << "FILE option given filename \"" << fname
|
|
|
|
<< "\" which is in the source tree.\n";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2008-01-28 16:38:36 +03:00
|
|
|
return false;
|
2007-06-08 19:57:16 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-28 16:38:36 +03:00
|
|
|
// Interpret relative paths with respect to the current build dir.
|
2015-04-16 22:33:09 +03:00
|
|
|
std::string dir = this->Makefile->GetCurrentBinaryDirectory();
|
2013-12-23 20:07:26 +04:00
|
|
|
fname = dir + "/" + fname;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-08 19:57:16 +04:00
|
|
|
|
2013-12-23 20:07:26 +04:00
|
|
|
std::vector<std::string> targets;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
|
2013-12-23 20:07:26 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[0] == "EXPORT") {
|
|
|
|
if (this->Append.IsEnabled()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "EXPORT signature does not recognise the APPEND option.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2013-12-23 20:07:26 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-12-23 20:07:26 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ExportOld.IsEnabled()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "EXPORT signature does not recognise the "
|
2016-05-16 17:34:04 +03:00
|
|
|
"EXPORT_LINK_INTERFACE_LIBRARIES option.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2013-07-12 11:14:31 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-07-12 11:14:31 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExportSetMap& setMap = gg->GetExportSets();
|
2013-12-23 20:07:26 +04:00
|
|
|
std::string setName = this->ExportSetName.GetString();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (setMap.find(setName) == setMap.end()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "Export set \"" << setName << "\" not found.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2013-12-23 20:07:26 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->ExportSet = setMap[setName];
|
|
|
|
} else if (this->Targets.WasFound()) {
|
|
|
|
for (std::vector<std::string>::const_iterator currentTarget =
|
|
|
|
this->Targets.GetVector().begin();
|
|
|
|
currentTarget != this->Targets.GetVector().end(); ++currentTarget) {
|
|
|
|
if (this->Makefile->IsAlias(*currentTarget)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "given ALIAS target \"" << *currentTarget
|
2012-03-12 18:47:40 +04:00
|
|
|
<< "\" which may not be exported.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2012-03-12 18:47:40 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-12-23 20:07:26 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmTarget* target = gg->FindTarget(*currentTarget)) {
|
|
|
|
if (target->GetType() == cmState::OBJECT_LIBRARY) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "given OBJECT library \"" << *currentTarget
|
|
|
|
<< "\" which may not be exported.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2013-12-23 20:07:26 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (target->GetType() == cmState::UTILITY) {
|
|
|
|
this->SetError("given custom target \"" + *currentTarget +
|
|
|
|
"\" which may not be exported.");
|
2015-07-21 21:37:20 +03:00
|
|
|
return false;
|
2013-12-23 20:07:26 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-12-23 20:07:26 +04:00
|
|
|
e << "given target \"" << *currentTarget
|
|
|
|
<< "\" which is not built by this project.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2013-12-23 20:07:26 +04:00
|
|
|
return false;
|
2008-01-28 16:38:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
targets.push_back(*currentTarget);
|
|
|
|
}
|
|
|
|
if (this->Append.IsEnabled()) {
|
|
|
|
if (cmExportBuildFileGenerator* ebfg =
|
|
|
|
gg->GetExportedTargetsFile(fname)) {
|
2013-12-23 20:07:26 +04:00
|
|
|
ebfg->AppendTargets(targets);
|
|
|
|
return true;
|
2013-12-02 20:18:29 +04:00
|
|
|
}
|
2012-10-06 19:27:40 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-12-23 20:07:26 +04:00
|
|
|
this->SetError("EXPORT or TARGETS specifier missing.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-09 00:19:13 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Setup export file generation.
|
2016-07-12 20:26:55 +03:00
|
|
|
cmExportBuildFileGenerator* ebfg = CM_NULLPTR;
|
|
|
|
if (android) {
|
|
|
|
ebfg = new cmExportBuildAndroidMKGenerator;
|
|
|
|
} else {
|
|
|
|
ebfg = new cmExportBuildFileGenerator;
|
|
|
|
}
|
2012-10-06 19:27:40 +04:00
|
|
|
ebfg->SetExportFile(fname.c_str());
|
|
|
|
ebfg->SetNamespace(this->Namespace.GetCString());
|
|
|
|
ebfg->SetAppendMode(this->Append.IsEnabled());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ExportSet) {
|
2013-12-23 20:07:26 +04:00
|
|
|
ebfg->SetExportSet(this->ExportSet);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-12-23 20:07:26 +04:00
|
|
|
ebfg->SetTargets(targets);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-16 23:08:22 +03:00
|
|
|
this->Makefile->AddExportBuildFileGenerator(ebfg);
|
2012-10-06 19:27:40 +04:00
|
|
|
ebfg->SetExportOld(this->ExportOld.IsEnabled());
|
2013-06-18 18:33:33 +04:00
|
|
|
|
2008-01-28 16:38:36 +03:00
|
|
|
// Compute the set of configurations exported.
|
2010-09-08 22:54:49 +04:00
|
|
|
std::vector<std::string> configurationTypes;
|
|
|
|
this->Makefile->GetConfigurations(configurationTypes);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (configurationTypes.empty()) {
|
2014-03-27 12:46:58 +04:00
|
|
|
configurationTypes.push_back("");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator ci =
|
|
|
|
configurationTypes.begin();
|
|
|
|
ci != configurationTypes.end(); ++ci) {
|
2014-03-27 12:46:58 +04:00
|
|
|
ebfg->AddConfiguration(*ci);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->ExportSet) {
|
2013-12-26 17:34:27 +04:00
|
|
|
gg->AddBuildExportExportSet(ebfg);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-12-26 17:34:27 +04:00
|
|
|
gg->AddBuildExportSet(ebfg);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-31 01:25:52 +03:00
|
|
|
|
2007-06-08 19:57:16 +04:00
|
|
|
return true;
|
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
|
|
|
|
bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
// Parse PACKAGE mode arguments.
|
2016-05-16 17:34:04 +03:00
|
|
|
enum Doing
|
|
|
|
{
|
|
|
|
DoingNone,
|
|
|
|
DoingPackage
|
|
|
|
};
|
2009-09-01 22:04:53 +04:00
|
|
|
Doing doing = DoingPackage;
|
|
|
|
std::string package;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 1; i < args.size(); ++i) {
|
|
|
|
if (doing == DoingPackage) {
|
2009-09-01 22:04:53 +04:00
|
|
|
package = args[i];
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2013-05-01 13:36:14 +04:00
|
|
|
e << "PACKAGE given unknown argument: " << args[i];
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-09-01 22:04:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
|
|
|
|
// Verify the package name.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (package.empty()) {
|
2009-09-01 22:04:53 +04:00
|
|
|
this->SetError("PACKAGE must be given a package name.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
const char* packageExpr = "^[A-Za-z0-9_.-]+$";
|
|
|
|
cmsys::RegularExpression packageRegex(packageExpr);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!packageRegex.find(package.c_str())) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-09-01 22:04:53 +04:00
|
|
|
e << "PACKAGE given invalid package name \"" << package << "\". "
|
|
|
|
<< "Package names must match \"" << packageExpr << "\".";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-09-01 22:04:53 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
|
2014-04-02 18:32:54 +04:00
|
|
|
// If the CMAKE_EXPORT_NO_PACKAGE_REGISTRY variable is set the command
|
|
|
|
// export(PACKAGE) does nothing.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY")) {
|
2014-04-02 18:32:54 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-04-02 18:32:54 +04:00
|
|
|
|
2009-09-01 22:04:53 +04:00
|
|
|
// We store the current build directory in the registry as a value
|
|
|
|
// named by a hash of its own content. This is deterministic and is
|
|
|
|
// unique with high probability.
|
2015-04-16 22:33:09 +03:00
|
|
|
const char* outDir = this->Makefile->GetCurrentBinaryDirectory();
|
2009-09-01 22:04:53 +04:00
|
|
|
std::string hash = cmSystemTools::ComputeStringMD5(outDir);
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
this->StorePackageRegistryWin(package, outDir, hash.c_str());
|
|
|
|
#else
|
|
|
|
this->StorePackageRegistryDir(package, outDir, hash.c_str());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2016-05-16 17:34:04 +03:00
|
|
|
#include <windows.h>
|
|
|
|
#undef GetCurrentDirectory
|
2009-09-01 22:04:53 +04:00
|
|
|
void cmExportCommand::ReportRegistryError(std::string const& msg,
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& key, long err)
|
2009-09-01 22:04:53 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-09-01 22:04:53 +04:00
|
|
|
e << msg << "\n"
|
|
|
|
<< " HKEY_CURRENT_USER\\" << key << "\n";
|
2013-12-05 09:17:24 +04:00
|
|
|
wchar_t winmsg[1024];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (FormatMessageW(
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, err,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), winmsg, 1024, 0) > 0) {
|
2009-09-01 22:04:53 +04:00
|
|
|
e << "Windows reported:\n"
|
2013-12-05 09:17:24 +04:00
|
|
|
<< " " << cmsys::Encoding::ToNarrow(winmsg);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
this->Makefile->IssueMessage(cmake::WARNING, e.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportCommand::StorePackageRegistryWin(std::string const& package,
|
|
|
|
const char* content,
|
|
|
|
const char* hash)
|
|
|
|
{
|
|
|
|
std::string key = "Software\\Kitware\\CMake\\Packages\\";
|
|
|
|
key += package;
|
|
|
|
HKEY hKey;
|
2016-05-16 17:34:04 +03:00
|
|
|
LONG err =
|
|
|
|
RegCreateKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(key).c_str(), 0,
|
|
|
|
0, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, 0, &hKey, 0);
|
|
|
|
if (err != ERROR_SUCCESS) {
|
|
|
|
this->ReportRegistryError("Cannot create/open registry key", key, err);
|
2009-09-01 22:04:53 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-12-05 09:17:24 +04:00
|
|
|
|
|
|
|
std::wstring wcontent = cmsys::Encoding::ToWide(content);
|
2016-05-16 17:34:04 +03:00
|
|
|
err =
|
|
|
|
RegSetValueExW(hKey, cmsys::Encoding::ToWide(hash).c_str(), 0, REG_SZ,
|
|
|
|
(BYTE const*)wcontent.c_str(),
|
|
|
|
static_cast<DWORD>(wcontent.size() + 1) * sizeof(wchar_t));
|
2009-09-01 22:04:53 +04:00
|
|
|
RegCloseKey(hKey);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (err != ERROR_SUCCESS) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2009-09-01 22:04:53 +04:00
|
|
|
msg << "Cannot set registry value \"" << hash << "\" under key";
|
|
|
|
this->ReportRegistryError(msg.str(), key, err);
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void cmExportCommand::StorePackageRegistryDir(std::string const& package,
|
|
|
|
const char* content,
|
|
|
|
const char* hash)
|
|
|
|
{
|
2009-09-28 17:45:34 +04:00
|
|
|
#if defined(__HAIKU__)
|
2013-10-05 18:31:36 +04:00
|
|
|
char dir[B_PATH_NAME_LENGTH];
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) !=
|
2016-05-16 17:34:04 +03:00
|
|
|
B_OK) {
|
2009-09-28 17:45:34 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-05 18:31:36 +04:00
|
|
|
std::string fname = dir;
|
|
|
|
fname += "/cmake/packages/";
|
|
|
|
fname += package;
|
2009-09-28 17:45:34 +04:00
|
|
|
#else
|
2016-07-08 00:54:05 +03:00
|
|
|
std::string fname;
|
|
|
|
if (!cmSystemTools::GetEnv("HOME", fname)) {
|
2009-09-01 22:04:53 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(fname);
|
|
|
|
fname += "/.cmake/packages/";
|
|
|
|
fname += package;
|
2009-09-28 17:45:34 +04:00
|
|
|
#endif
|
2009-09-01 22:04:53 +04:00
|
|
|
cmSystemTools::MakeDirectory(fname.c_str());
|
|
|
|
fname += "/";
|
|
|
|
fname += hash;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(fname.c_str())) {
|
2009-09-01 22:04:53 +04:00
|
|
|
cmGeneratedFileStream entry(fname.c_str(), true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (entry) {
|
2009-09-01 22:04:53 +04:00
|
|
|
entry << content << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2009-09-01 22:04:53 +04:00
|
|
|
e << "Cannot create package registry file:\n"
|
|
|
|
<< " " << fname << "\n"
|
|
|
|
<< cmSystemTools::GetLastSystemError() << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2009-09-01 22:04:53 +04:00
|
|
|
this->Makefile->IssueMessage(cmake::WARNING, e.str());
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-01 22:04:53 +04:00
|
|
|
}
|
|
|
|
#endif
|