2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2013-02-07 16:36:29 +00:00
|
|
|
#include "cmExportTryCompileFileGenerator.h"
|
|
|
|
|
2016-09-01 18:59:28 +00:00
|
|
|
#include "cmGeneratorExpression.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmGeneratorExpressionDAGChecker.h"
|
2016-09-01 18:59:28 +00:00
|
|
|
#include "cmGeneratorTarget.h"
|
2015-07-25 18:44:35 +00:00
|
|
|
#include "cmGlobalGenerator.h"
|
2015-10-17 12:27:59 +00:00
|
|
|
#include "cmLocalGenerator.h"
|
2016-09-01 18:59:28 +00:00
|
|
|
#include "cmMakefile.h"
|
2016-10-18 19:28:48 +00:00
|
|
|
#include "cmStateTypes.h"
|
2016-09-01 18:59:28 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
|
|
|
|
|
|
|
#include <map>
|
2017-09-21 21:06:05 +00:00
|
|
|
#include <memory> // IWYU pragma: keep
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <utility>
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2015-07-25 18:44:35 +00:00
|
|
|
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGlobalGenerator* gg, const std::vector<std::string>& targets,
|
|
|
|
cmMakefile* mf)
|
2015-07-25 18:44:35 +00:00
|
|
|
{
|
2015-10-17 12:27:59 +00:00
|
|
|
gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
|
2015-07-25 18:44:35 +00:00
|
|
|
}
|
|
|
|
|
2013-02-07 16:36:29 +00:00
|
|
|
bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
|
|
|
|
{
|
2015-10-17 12:33:51 +00:00
|
|
|
std::set<cmGeneratorTarget const*> emitted;
|
|
|
|
std::set<cmGeneratorTarget const*> emittedDeps;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (!this->Exports.empty()) {
|
2015-10-17 12:27:59 +00:00
|
|
|
cmGeneratorTarget const* te = this->Exports.back();
|
2013-02-07 16:36:29 +00:00
|
|
|
this->Exports.pop_back();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (emitted.insert(te).second) {
|
2015-10-17 12:33:51 +00:00
|
|
|
emittedDeps.insert(te);
|
|
|
|
this->GenerateImportTargetCode(os, te);
|
2013-02-07 16:36:29 +00:00
|
|
|
|
|
|
|
ImportPropertyMap properties;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
#define FIND_TARGETS(PROPERTY) \
|
|
|
|
this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
|
2013-06-10 14:01:59 +00:00
|
|
|
|
|
|
|
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2013-12-31 13:34:16 +00:00
|
|
|
#undef FIND_TARGETS
|
|
|
|
|
2015-10-17 12:33:51 +00:00
|
|
|
this->PopulateProperties(te, properties, emittedDeps);
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2015-10-17 12:33:51 +00:00
|
|
|
this->GenerateInterfaceProperties(te, os, properties);
|
2013-02-07 16:36:29 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-02-07 16:36:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-02 20:27:32 +00:00
|
|
|
std::string cmExportTryCompileFileGenerator::FindTargets(
|
2016-05-16 14:34:04 +00:00
|
|
|
const std::string& propName, cmGeneratorTarget const* tgt,
|
|
|
|
std::set<cmGeneratorTarget const*>& emitted)
|
2013-02-07 16:36:29 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* prop = tgt->GetProperty(propName);
|
|
|
|
if (!prop) {
|
2013-02-07 16:36:29 +00:00
|
|
|
return std::string();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2014-05-23 18:59:11 +00:00
|
|
|
cmGeneratorExpression ge;
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2017-08-22 21:42:36 +00:00
|
|
|
cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName, nullptr,
|
|
|
|
nullptr);
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2017-09-21 21:06:05 +00:00
|
|
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2016-10-18 19:28:46 +00:00
|
|
|
cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE,
|
2016-09-14 18:28:07 +00:00
|
|
|
cmTarget::VisibilityNormal, tgt->Target->GetMakefile());
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2015-10-17 12:33:51 +00:00
|
|
|
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
|
2015-09-15 23:08:49 +00:00
|
|
|
|
2015-10-17 12:33:51 +00:00
|
|
|
std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
|
2016-05-16 14:34:04 +00:00
|
|
|
false, &gDummyHead, tgt, &dagChecker);
|
|
|
|
|
|
|
|
const std::set<cmGeneratorTarget const*>& allTargets =
|
|
|
|
cge->GetAllTargetsSeen();
|
2017-09-11 10:40:26 +00:00
|
|
|
for (cmGeneratorTarget const* target : allTargets) {
|
|
|
|
if (emitted.insert(target).second) {
|
|
|
|
this->Exports.push_back(target);
|
2013-02-07 16:36:29 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-02-07 16:36:29 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmExportTryCompileFileGenerator::PopulateProperties(
|
|
|
|
const cmGeneratorTarget* target, ImportPropertyMap& properties,
|
|
|
|
std::set<cmGeneratorTarget const*>& emitted)
|
2013-02-07 16:36:29 +00:00
|
|
|
{
|
2015-10-25 09:35:36 +00:00
|
|
|
std::vector<std::string> props = target->GetPropertyKeys();
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& p : props) {
|
2013-02-07 16:36:29 +00:00
|
|
|
|
2017-09-11 10:40:26 +00:00
|
|
|
properties[p] = target->GetProperty(p);
|
2015-10-25 09:35:36 +00:00
|
|
|
|
2017-09-11 10:40:26 +00:00
|
|
|
if (p.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
|
|
|
|
p.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0 ||
|
|
|
|
p.find("INTERFACE_LINK_LIBRARIES") == 0) {
|
|
|
|
std::string evalResult = this->FindTargets(p, target, emitted);
|
2013-02-07 16:36:29 +00:00
|
|
|
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
cmSystemTools::ExpandListArgument(evalResult, depends);
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& li : depends) {
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorTarget* tgt =
|
2017-09-11 10:40:26 +00:00
|
|
|
target->GetLocalGenerator()->FindGeneratorTargetToUse(li);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (tgt && emitted.insert(tgt).second) {
|
2013-02-07 16:36:29 +00:00
|
|
|
this->Exports.push_back(tgt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-02-07 16:36:29 +00:00
|
|
|
}
|
2015-06-06 20:54:50 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cmExportTryCompileFileGenerator::InstallNameDir(
|
|
|
|
cmGeneratorTarget* target, const std::string& config)
|
2013-05-20 22:57:58 +00:00
|
|
|
{
|
|
|
|
std::string install_name_dir;
|
|
|
|
|
2015-08-04 17:19:47 +00:00
|
|
|
cmMakefile* mf = target->Target->GetMakefile();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
|
|
|
|
install_name_dir = target->GetInstallNameDirForBuildTree(config);
|
|
|
|
}
|
2013-05-20 22:57:58 +00:00
|
|
|
|
|
|
|
return install_name_dir;
|
|
|
|
}
|