summaryrefslogtreecommitdiffstats
path: root/Source/cmInstallExportGenerator.cxx
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-06-19 17:10:21 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-06-19 17:10:21 (GMT)
commitc0d000d234525c709b8f6226d1c78c3cc0b632b3 (patch)
treefce16d3de49d612d0c545e2b385eed04b736a945 /Source/cmInstallExportGenerator.cxx
parent617602e9e9e0ff57a3ef35e62e17d4a764edf920 (diff)
downloadCMake-c0d000d234525c709b8f6226d1c78c3cc0b632b3.zip
CMake-c0d000d234525c709b8f6226d1c78c3cc0b632b3.tar.gz
CMake-c0d000d234525c709b8f6226d1c78c3cc0b632b3.tar.bz2
ENH: add INSTALL(EXPORT ...) mode and INSTALL( TARGETS ... EXPORT <set> ) ,
tests still have to be added Alex
Diffstat (limited to 'Source/cmInstallExportGenerator.cxx')
-rw-r--r--Source/cmInstallExportGenerator.cxx231
1 files changed, 231 insertions, 0 deletions
diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx
new file mode 100644
index 0000000..171cf32
--- /dev/null
+++ b/Source/cmInstallExportGenerator.cxx
@@ -0,0 +1,231 @@
+/*=========================================================================
+
+ 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 <stdio.h>
+
+#include "cmInstallTargetGenerator.h"
+#include "cmGeneratedFileStream.h"
+#include "cmTarget.h"
+
+#include "cmInstallExportGenerator.h"
+
+cmInstallExportGenerator::cmInstallExportGenerator(const char* destination,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations,
+ const char* filename, const char* prefix, const char* tempOutputDir)
+ :cmInstallGenerator(destination)
+ ,FilePermissions(file_permissions)
+ ,Configurations(configurations)
+ ,Filename(filename)
+ ,Prefix(prefix)
+ ,TempOutputDir(tempOutputDir)
+{
+}
+
+/* Helper function which adds the install locations from the generator
+to the properties for this target.
+*/
+bool cmInstallExportGenerator::AddInstallLocations(cmTargetWithProperties* twp,
+ cmInstallTargetGenerator* generator,
+ const char* prefix)
+{
+ if (generator == 0) // nothing to do
+ {
+ return true;
+ }
+
+ if (prefix == 0)
+ {
+ prefix = "";
+ }
+
+ const std::vector<std::string>& configs = generator->GetConfigurations();
+ if (configs.empty())
+ {
+ std::string propertyName = prefix;
+ propertyName += "LOCATION";
+ // check that this property doesn't exist yet and add it then
+ if (twp->Properties.find(propertyName.c_str())== twp->Properties.end())
+ {
+ std::string destinationFilename = generator->GetDestination();
+ destinationFilename += "/";
+ destinationFilename += generator->GetInstallFilename(0);
+ twp->Properties[propertyName.c_str()] = destinationFilename;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ for(std::vector<std::string>::const_iterator configIt = configs.begin();
+ configIt != configs.end();
+ ++configIt)
+ {
+ std::string propertyName = configIt->c_str();
+ propertyName += "_";
+ propertyName += prefix;
+ propertyName += "LOCATION";
+ // check that this property doesn't exist yet and add it then
+ if (twp->Properties.find(propertyName.c_str())== twp->Properties.end())
+ {
+ std::string destinationFilename = generator->GetDestination();
+ destinationFilename += "/";
+ destinationFilename +=generator->GetInstallFilename(configIt->c_str());
+ twp->Properties[propertyName.c_str()] = destinationFilename;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+
+bool cmInstallExportGenerator::SetExportSet(const char* name,
+ const std::vector<cmTargetExport*>* set)
+{
+ if ((name == 0) || (*name == 0) || (set==0))
+ {
+ return false;
+ }
+
+ this->Name = name;
+
+ /* iterate over all targets in the set.
+ If a cmTargetWithProperties with the same name already exists in this
+ generator, add the new properties to it. If the property already exists,
+ fail with an error.
+ If no cmTargetWithProperties exists, create a new one.
+ */
+ for(std::vector<cmTargetExport*>::const_iterator it=set->begin();
+ it != set->end();
+ ++it)
+ {
+ std::string targetName = (*it)->Target->GetName();
+
+ cmTargetWithProperties* targetWithProps = 0;
+ for(unsigned int i=0; i<this->Targets.size(); i++)
+ {
+ if (targetName == this->Targets[i]->Target->GetName())
+ {
+ targetWithProps = this->Targets[i];
+ }
+ }
+
+ if (targetWithProps == 0)
+ {
+ targetWithProps = new cmTargetWithProperties((*it)->Target);
+ this->Targets.push_back(targetWithProps);
+ }
+
+ if (this->AddInstallLocations(targetWithProps, (*it)->ArchiveGenerator,
+ "ARCHIVE_") == false)
+ {
+ return false;
+ }
+ if (this->AddInstallLocations(targetWithProps, (*it)->RuntimeGenerator,
+ "") == false)
+ {
+ return false;
+ }
+ if (this->AddInstallLocations(targetWithProps, (*it)->LibraryGenerator,
+ "LIBRARY_") == false)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void cmInstallExportGenerator::GenerateScript(std::ostream& os)
+{
+ // for the case that somebody exports the same set with the same file name
+ // to different locations make the temp filename unique
+ char buf[64];
+ snprintf(buf, 64, "%p", this);
+ this->ExportFilename = this->TempOutputDir;
+ this->ExportFilename += "/";
+ this->ExportFilename += this->Filename;
+ this->ExportFilename += ".";
+ this->ExportFilename += buf;
+
+ cmGeneratedFileStream exportFileStream(this->ExportFilename.c_str());
+ if(!exportFileStream)
+ {
+ return;
+ }
+
+ /* for every target add the IMPORT statements and set the properties
+ of the target. */
+ for(std::vector<cmTargetWithProperties*>::const_iterator
+ targetIt = this->Targets.begin();
+ targetIt != this->Targets.end();
+ ++targetIt)
+ {
+ switch ((*targetIt)->Target->GetType())
+ {
+ case cmTarget::EXECUTABLE:
+ exportFileStream << "ADD_EXECUTABLE(" << this->Prefix.c_str()
+ << (*targetIt)->Target->GetName()
+ << " IMPORT )\n";
+ break;
+ case cmTarget::STATIC_LIBRARY:
+ exportFileStream << "ADD_LIBRARY(" << this->Prefix.c_str()
+ << (*targetIt)->Target->GetName()
+ << " STATIC IMPORT )\n";
+ break;
+ case cmTarget::SHARED_LIBRARY:
+ exportFileStream << "ADD_LIBRARY(" << this->Prefix.c_str()
+ << (*targetIt)->Target->GetName()
+ << " SHARED IMPORT )\n";
+ break;
+ case cmTarget::MODULE_LIBRARY:
+ exportFileStream << "ADD_LIBRARY(" << this->Prefix.c_str()
+ << (*targetIt)->Target->GetName()
+ << " MODULE IMPORT )\n";
+ break;
+ default: // should never happen
+ break;
+ }
+
+ exportFileStream << "SET_TARGET_PROPERTIES ( " << this->Prefix.c_str()
+ << (*targetIt)->Target->GetName() << " PROPERTIES \n";
+
+ for (std::map<std::string, std::string>::const_iterator
+ propIt = (*targetIt)->Properties.begin();
+ propIt != (*targetIt)->Properties.end();
+ ++propIt)
+ {
+ exportFileStream << " " << propIt->first
+ << " \"" << propIt->second << "\"\n";
+ }
+ exportFileStream << " )\n\n";
+ }
+
+ // install rule for the file created above
+ this->AddInstallRule(os, this->Destination.c_str(), cmTarget::INSTALL_FILES,
+ this->ExportFilename.c_str(), false, 0,
+ this->FilePermissions.c_str(), 0, this->Configurations,
+ 0, this->Filename.c_str(), 0);
+
+}
+