summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-01-28 13:21:42 -0500
committerBrad King <brad.king@kitware.com>2008-01-28 13:21:42 -0500
commit6388ebceb12e8eca3ce0e30528f0edaa990c8f7a (patch)
tree93706ecc2ed10615acdbf78216e3d4bd49389b53
parent611bff2c1b8a0ce533d92662504a391c9e3d494b (diff)
downloadcmake-6388ebceb12e8eca3ce0e30528f0edaa990c8f7a.tar.gz
ENH: Restored APPEND option to EXPORT() command in new implementation.
-rw-r--r--Source/cmExportBuildFileGenerator.h2
-rw-r--r--Source/cmExportCommand.cxx2
-rw-r--r--Source/cmExportCommand.h5
-rw-r--r--Source/cmExportFileGenerator.cxx29
-rw-r--r--Source/cmExportFileGenerator.h2
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt6
6 files changed, 41 insertions, 5 deletions
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index 0bb79cc2a4..53423f382e 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -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);
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index 70c024e5c7..cfc339c33b 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -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.
diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h
index f42450118a..d0e88c47a4 100644
--- a/Source/cmExportCommand.h
+++ b/Source/cmExportCommand.h
@@ -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;
};
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 2c916e54e6..dd0c33a6e6 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -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);
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index 92b6896f56..8edf82e301 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -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;
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
index 53fe70574e..62fe811590 100644
--- a/Tests/ExportImport/Export/CMakeLists.txt
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -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
+ )