ENH: Restored APPEND option to EXPORT() command in new implementation.
This commit is contained in:
parent
611bff2c1b
commit
6388ebceb1
|
@ -35,6 +35,8 @@ public:
|
|||
void SetExports(std::vector<cmTarget*> const* exports)
|
||||
{ this->Exports = exports; }
|
||||
|
||||
/** Set whether to append generated code to the output file. */
|
||||
void SetAppendMode(bool append) { this->AppendMode = append; }
|
||||
protected:
|
||||
// Implement virtual methods from the superclass.
|
||||
virtual bool GenerateMainFile(std::ostream& os);
|
||||
|
|
|
@ -26,6 +26,7 @@ cmExportCommand::cmExportCommand()
|
|||
:cmCommand()
|
||||
,ArgumentGroup()
|
||||
,Targets(&Helper, "TARGETS")
|
||||
,Append(&Helper, "APPEND", &ArgumentGroup)
|
||||
,Namespace(&Helper, "NAMESPACE", &ArgumentGroup)
|
||||
,Filename(&Helper, "FILE", &ArgumentGroup)
|
||||
{
|
||||
|
@ -146,6 +147,7 @@ bool cmExportCommand
|
|||
cmExportBuildFileGenerator ebfg;
|
||||
ebfg.SetExportFile(fname.c_str());
|
||||
ebfg.SetNamespace(this->Namespace.GetCString());
|
||||
ebfg.SetAppendMode(this->Append.IsEnabled());
|
||||
ebfg.SetExports(&targets);
|
||||
|
||||
// Compute the set of configurations exported.
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
{
|
||||
return
|
||||
" export(TARGETS [target1 [target2 [...]]] [NAMESPACE <namespace>]\n"
|
||||
" FILE <filename>)\n"
|
||||
" [APPEND] FILE <filename>)\n"
|
||||
"Create a file <filename> that may be included by outside projects to "
|
||||
"import targets from the current project's build tree. "
|
||||
"This is useful during cross-compiling to build utility executables "
|
||||
|
@ -73,6 +73,8 @@ public:
|
|||
"them into another project being compiled for the target platform. "
|
||||
"If the NAMESPACE option is given the <namespace> string will be "
|
||||
"prepended to all target names written to the file. "
|
||||
"If the APPEND option is given the generated code will be appended "
|
||||
"to the file instead of overwriting it. "
|
||||
"If a library target is included in the export but "
|
||||
"a target to which it links is not included the behavior is "
|
||||
"unspecified."
|
||||
|
@ -88,6 +90,7 @@ public:
|
|||
private:
|
||||
cmCommandArgumentGroup ArgumentGroup;
|
||||
cmCAStringVector Targets;
|
||||
cmCAEnabler Append;
|
||||
cmCAString Namespace;
|
||||
cmCAString Filename;
|
||||
};
|
||||
|
|
|
@ -21,6 +21,14 @@
|
|||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
|
||||
#include <cmsys/auto_ptr.hxx>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmExportFileGenerator::cmExportFileGenerator()
|
||||
{
|
||||
this->AppendMode = false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmExportFileGenerator::AddConfiguration(const char* config)
|
||||
{
|
||||
|
@ -43,8 +51,23 @@ void cmExportFileGenerator::SetExportFile(const char* mainFile)
|
|||
bool cmExportFileGenerator::GenerateImportFile()
|
||||
{
|
||||
// Open the output file to generate it.
|
||||
cmGeneratedFileStream exportFileStream(this->MainImportFile.c_str(), true);
|
||||
if(!exportFileStream)
|
||||
cmsys::auto_ptr<std::ofstream> foutPtr;
|
||||
if(this->AppendMode)
|
||||
{
|
||||
// Open for append.
|
||||
cmsys::auto_ptr<std::ofstream>
|
||||
ap(new std::ofstream(this->MainImportFile.c_str(), std::ios::app));
|
||||
foutPtr = ap;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Generate atomically and with copy-if-different.
|
||||
cmsys::auto_ptr<cmGeneratedFileStream>
|
||||
ap(new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
|
||||
ap->SetCopyIfDifferent(true);
|
||||
foutPtr = ap;
|
||||
}
|
||||
if(!foutPtr.get() || !*foutPtr)
|
||||
{
|
||||
std::string se = cmSystemTools::GetLastSystemError();
|
||||
cmOStringStream e;
|
||||
|
@ -53,7 +76,7 @@ bool cmExportFileGenerator::GenerateImportFile()
|
|||
cmSystemTools::Error(e.str().c_str());
|
||||
return false;
|
||||
}
|
||||
std::ostream& os = exportFileStream;
|
||||
std::ostream& os = *foutPtr;
|
||||
|
||||
// Start with the import file header.
|
||||
this->GenerateImportHeaderCode(os);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
class cmExportFileGenerator
|
||||
{
|
||||
public:
|
||||
cmExportFileGenerator();
|
||||
virtual ~cmExportFileGenerator() {}
|
||||
|
||||
/** Set the full path to the export file to generate. */
|
||||
|
@ -90,6 +91,7 @@ protected:
|
|||
std::string FileDir;
|
||||
std::string FileBase;
|
||||
std::string FileExt;
|
||||
bool AppendMode;
|
||||
|
||||
// The set of targets included in the export.
|
||||
std::set<cmTarget*> ExportedTargets;
|
||||
|
|
|
@ -31,7 +31,11 @@ install(
|
|||
install(EXPORT exp NAMESPACE exp_ DESTINATION lib/exp)
|
||||
|
||||
# Export from build tree.
|
||||
export(TARGETS testExe1 testLib1 testLib2 testExe2 testLib3 testLib4
|
||||
export(TARGETS testExe1 testLib1 testLib2
|
||||
NAMESPACE bld_
|
||||
FILE ExportBuildTree.cmake
|
||||
)
|
||||
export(TARGETS testExe2 testLib3 testLib4
|
||||
NAMESPACE bld_
|
||||
APPEND FILE ExportBuildTree.cmake
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue