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"
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorExpression.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratorExpressionDAGChecker.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorTarget.h"
|
2015-07-25 21:44:35 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2015-10-17 15:27:59 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
|
|
|
#include "cm_auto_ptr.hxx"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2015-07-25 21:44:35 +03:00
|
|
|
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
|
2016-05-16 17:34:04 +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;
|
2016-05-16 17:34:04 +03: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();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emitted.insert(te).second) {
|
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;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define FIND_TARGETS(PROPERTY) \
|
|
|
|
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
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-07 20:36:29 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
std::string cmExportTryCompileFileGenerator::FindTargets(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& propName, cmGeneratorTarget const* tgt,
|
|
|
|
std::set<cmGeneratorTarget const*>& emitted)
|
2013-02-07 20:36:29 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* prop = tgt->GetProperty(propName);
|
|
|
|
if (!prop) {
|
2013-02-07 20:36:29 +04:00
|
|
|
return std::string();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2014-05-23 22:59:11 +04:00
|
|
|
cmGeneratorExpression ge;
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName,
|
|
|
|
CM_NULLPTR, CM_NULLPTR);
|
2013-02-07 20:36:29 +04:00
|
|
|
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
|
2013-02-07 20:36:29 +04:00
|
|
|
|
|
|
|
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,
|
2016-05-16 17:34:04 +03:00
|
|
|
false, &gDummyHead, tgt, &dagChecker);
|
|
|
|
|
|
|
|
const std::set<cmGeneratorTarget const*>& allTargets =
|
|
|
|
cge->GetAllTargetsSeen();
|
|
|
|
for (std::set<cmGeneratorTarget const*>::const_iterator li =
|
|
|
|
allTargets.begin();
|
|
|
|
li != allTargets.end(); ++li) {
|
|
|
|
if (emitted.insert(*li).second) {
|
2015-10-17 15:33:51 +03:00
|
|
|
this->Exports.push_back(*li);
|
2013-02-07 20:36:29 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-07 20:36:29 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void 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();
|
2016-05-16 17:34:04 +03:00
|
|
|
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);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i->find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
|
|
|
|
i->find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0 ||
|
|
|
|
i->find("INTERFACE_LINK_LIBRARIES") == 0) {
|
|
|
|
std::string evalResult = this->FindTargets(*i, target, emitted);
|
2013-02-07 20:36:29 +04:00
|
|
|
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
cmSystemTools::ExpandListArgument(evalResult, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator li = depends.begin();
|
|
|
|
li != depends.end(); ++li) {
|
|
|
|
cmGeneratorTarget* tgt =
|
|
|
|
target->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
|
|
|
|
if (tgt && emitted.insert(tgt).second) {
|
2013-02-07 20:36:29 +04:00
|
|
|
this->Exports.push_back(tgt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-02-07 20:36:29 +04:00
|
|
|
}
|
2015-06-06 23:54:50 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmExportTryCompileFileGenerator::InstallNameDir(
|
|
|
|
cmGeneratorTarget* target, const std::string& config)
|
2013-05-21 02:57:58 +04:00
|
|
|
{
|
|
|
|
std::string install_name_dir;
|
|
|
|
|
2015-08-04 20:19:47 +03:00
|
|
|
cmMakefile* mf = target->Target->GetMakefile();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
|
|
|
|
install_name_dir = target->GetInstallNameDirForBuildTree(config);
|
|
|
|
}
|
2013-05-21 02:57:58 +04:00
|
|
|
|
|
|
|
return install_name_dir;
|
|
|
|
}
|