1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2013 Stephen Kelly <steveire@gmail.com>
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
13 #include "cmExportTryCompileFileGenerator.h"
15 #include "cmGeneratedFileStream.h"
16 #include "cmGeneratorExpressionDAGChecker.h"
18 //----------------------------------------------------------------------------
19 bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
21 std::set<cmTarget*> emitted;
22 std::set<cmTarget*> emittedDeps;
23 while(!this->Exports.empty())
25 cmTarget* te = this->Exports.back();
26 this->Exports.pop_back();
27 if (emitted.insert(te).second)
29 emittedDeps.insert(te);
30 this->GenerateImportTargetCode(os, te);
32 ImportPropertyMap properties;
34 #define FIND_TARGETS(PROPERTY) \
35 this->FindTargets(#PROPERTY, te, emittedDeps);
37 CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
39 this->PopulateProperties(te, properties, emittedDeps);
41 this->GenerateInterfaceProperties(te, os, properties);
47 std::string cmExportTryCompileFileGenerator::FindTargets(const char *propName,
49 std::set<cmTarget*> &emitted)
51 const char *prop = tgt->GetProperty(propName);
57 cmListFileBacktrace lfbt;
58 cmGeneratorExpression ge(lfbt);
60 cmGeneratorExpressionDAGChecker dagChecker(lfbt,
64 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
67 dummyHead.SetType(cmTarget::EXECUTABLE, "try_compile_dummy_exe");
68 dummyHead.SetMakefile(tgt->GetMakefile());
70 std::string result = cge->Evaluate(tgt->GetMakefile(), this->Config,
71 false, &dummyHead, tgt, &dagChecker);
73 const std::set<cmTarget*> &allTargets = cge->GetAllTargetsSeen();
74 for(std::set<cmTarget*>::const_iterator li = allTargets.begin();
75 li != allTargets.end(); ++li)
77 if(emitted.insert(*li).second)
79 this->Exports.push_back(*li);
85 //----------------------------------------------------------------------------
87 cmExportTryCompileFileGenerator::PopulateProperties(cmTarget* target,
88 ImportPropertyMap& properties,
89 std::set<cmTarget*> &emitted)
91 cmPropertyMap props = target->GetProperties();
92 for(cmPropertyMap::const_iterator i = props.begin(); i != props.end(); ++i)
94 properties[i->first] = i->second.GetValue();
96 if(i->first.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
97 || i->first.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
98 || i->first.find("INTERFACE_LINK_LIBRARIES") == 0)
100 const std::string libs = i->second.GetValue();
102 std::string evalResult = this->FindTargets(i->first.c_str(),
105 std::vector<std::string> depends;
106 cmSystemTools::ExpandListArgument(evalResult, depends);
107 for(std::vector<std::string>::const_iterator li = depends.begin();
108 li != depends.end(); ++li)
110 cmTarget *tgt = target->GetMakefile()->FindTargetToUse(li->c_str());
111 if(tgt && emitted.insert(tgt).second)
113 this->Exports.push_back(tgt);
120 cmExportTryCompileFileGenerator::InstallNameDir(cmTarget* target,
121 const std::string& config)
123 std::string install_name_dir;
125 cmMakefile* mf = target->GetMakefile();
126 if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
129 target->GetInstallNameDirForBuildTree(config.c_str());
132 return install_name_dir;