2013-02-07 20:36:29 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2013 Stephen Kelly <steveire@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmExportTryCompileFileGenerator.h"
|
|
|
|
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2015-07-25 21:44:35 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2015-10-17 15:27:59 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2013-02-07 20:36:29 +04:00
|
|
|
#include "cmGeneratorExpressionDAGChecker.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2015-07-25 21:44:35 +03:00
|
|
|
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
|
2015-10-17 15:27:59 +03:00
|
|
|
cmGlobalGenerator* gg,
|
|
|
|
const std::vector<std::string>& targets,
|
|
|
|
cmMakefile* mf)
|
2015-07-25 21:44:35 +03:00
|
|
|
{
|
2015-10-17 15:27:59 +03:00
|
|
|
gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
|
2015-07-25 21:44:35 +03:00
|
|
|
}
|
|
|
|
|
2013-02-07 20:36:29 +04:00
|
|
|
bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
|
|
|
|
{
|
2015-10-17 15:33:51 +03:00
|
|
|
std::set<cmGeneratorTarget const*> emitted;
|
|
|
|
std::set<cmGeneratorTarget const*> emittedDeps;
|
2013-02-07 20:36:29 +04:00
|
|
|
while(!this->Exports.empty())
|
|
|
|
{
|
2015-10-17 15:27:59 +03:00
|
|
|
cmGeneratorTarget const* te = this->Exports.back();
|
2013-02-07 20:36:29 +04:00
|
|
|
this->Exports.pop_back();
|
2015-10-17 15:33:51 +03:00
|
|
|
if (emitted.insert(te).second)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
2015-10-17 15:33:51 +03:00
|
|
|
emittedDeps.insert(te);
|
|
|
|
this->GenerateImportTargetCode(os, te);
|
2013-02-07 20:36:29 +04:00
|
|
|
|
|
|
|
ImportPropertyMap properties;
|
|
|
|
|
2013-06-10 18:01:59 +04:00
|
|
|
#define FIND_TARGETS(PROPERTY) \
|
2015-10-17 15:33:51 +03:00
|
|
|
this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
|
2013-06-10 18:01:59 +04:00
|
|
|
|
|
|
|
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2013-12-31 17:34:16 +04:00
|
|
|
#undef FIND_TARGETS
|
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
this->PopulateProperties(te, properties, emittedDeps);
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
this->GenerateInterfaceProperties(te, os, properties);
|
2013-02-07 20:36:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
std::string cmExportTryCompileFileGenerator::FindTargets(
|
2015-10-17 15:33:51 +03:00
|
|
|
const std::string& propName,
|
|
|
|
cmGeneratorTarget const* tgt,
|
|
|
|
std::set<cmGeneratorTarget const*> &emitted)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
|
|
|
const char *prop = tgt->GetProperty(propName);
|
|
|
|
if(!prop)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2014-05-23 22:59:11 +04:00
|
|
|
cmGeneratorExpression ge;
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2014-05-23 22:59:11 +04:00
|
|
|
cmGeneratorExpressionDAGChecker dagChecker(
|
2013-02-07 20:36:29 +04:00
|
|
|
tgt->GetName(),
|
|
|
|
propName, 0, 0);
|
|
|
|
|
|
|
|
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
|
|
|
|
|
|
|
|
cmTarget dummyHead;
|
2015-10-08 01:21:51 +03:00
|
|
|
dummyHead.SetType(cmState::EXECUTABLE, "try_compile_dummy_exe");
|
2015-10-17 15:33:51 +03:00
|
|
|
dummyHead.SetMakefile(tgt->Target->GetMakefile());
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
|
2015-09-16 02:08:49 +03:00
|
|
|
|
2015-10-17 15:33:51 +03:00
|
|
|
std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
|
2015-09-16 05:38:52 +03:00
|
|
|
false, &gDummyHead,
|
2015-10-17 15:33:51 +03:00
|
|
|
tgt, &dagChecker);
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2015-10-10 19:41:51 +03:00
|
|
|
const std::set<cmGeneratorTarget const*> &allTargets =
|
|
|
|
cge->GetAllTargetsSeen();
|
|
|
|
for(std::set<cmGeneratorTarget const*>::const_iterator li =
|
|
|
|
allTargets.begin(); li != allTargets.end(); ++li)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
2015-10-17 15:33:51 +03:00
|
|
|
if(emitted.insert(*li).second)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
2015-10-17 15:33:51 +03:00
|
|
|
this->Exports.push_back(*li);
|
2013-02-07 20:36:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
2015-10-17 15:33:51 +03:00
|
|
|
cmExportTryCompileFileGenerator::PopulateProperties(
|
|
|
|
const cmGeneratorTarget* target,
|
|
|
|
ImportPropertyMap& properties,
|
|
|
|
std::set<cmGeneratorTarget const*> &emitted)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
2015-10-25 12:35:36 +03:00
|
|
|
std::vector<std::string> props = target->GetPropertyKeys();
|
|
|
|
for(std::vector<std::string>::const_iterator i = props.begin();
|
|
|
|
i != props.end(); ++i)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
|
|
|
|
2015-10-25 12:35:36 +03:00
|
|
|
properties[*i] = target->GetProperty(*i);
|
|
|
|
|
|
|
|
if(i->find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
|
|
|
|
|| i->find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0
|
|
|
|
|| i->find("INTERFACE_LINK_LIBRARIES") == 0)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
2015-10-25 12:35:36 +03:00
|
|
|
std::string evalResult = this->FindTargets(*i,
|
2013-02-07 20:36:29 +04:00
|
|
|
target, emitted);
|
|
|
|
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
cmSystemTools::ExpandListArgument(evalResult, depends);
|
|
|
|
for(std::vector<std::string>::const_iterator li = depends.begin();
|
|
|
|
li != depends.end(); ++li)
|
|
|
|
{
|
2015-10-17 15:27:59 +03:00
|
|
|
cmGeneratorTarget *tgt =
|
2015-10-17 15:33:51 +03:00
|
|
|
target->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
|
|
|
|
if(tgt && emitted.insert(tgt).second)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
|
|
|
this->Exports.push_back(tgt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 23:54:50 +03:00
|
|
|
|
2013-05-21 02:57:58 +04:00
|
|
|
std::string
|
2015-08-04 20:19:47 +03:00
|
|
|
cmExportTryCompileFileGenerator::InstallNameDir(cmGeneratorTarget* target,
|
2013-05-21 02:57:58 +04:00
|
|
|
const std::string& config)
|
|
|
|
{
|
|
|
|
std::string install_name_dir;
|
|
|
|
|
2015-08-04 20:19:47 +03:00
|
|
|
cmMakefile* mf = target->Target->GetMakefile();
|
2013-05-21 02:57:58 +04:00
|
|
|
if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
|
|
|
|
{
|
|
|
|
install_name_dir =
|
2014-03-11 03:04:11 +04:00
|
|
|
target->GetInstallNameDirForBuildTree(config);
|
2013-05-21 02:57:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return install_name_dir;
|
|
|
|
}
|