mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Merge topic 'modules-lang-specific-target-linked-dirs'
13810dee17cmDependsFortran: require that dependency info files workeed295fd8acmGlobalNinjaGenerator: require that dependency info files work837f7c113acmCommonTargetGenerator: classify linked target directories by languaged19648a928cmGeneratorTarget: add a method to query if Fortran sources exist245a89d8b6cmMakefileTargetGenerator: make "target linked info" variable Fortran-specificaeb1b2ae3dcmMakefileTargetGenerator: simplify string streaming Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !8146
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include <cm/string_view>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cmComputeLinkInformation.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalCommonGenerator.h"
|
||||
@@ -157,7 +160,7 @@ std::string cmCommonTargetGenerator::GetIncludes(std::string const& l,
|
||||
}
|
||||
|
||||
std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories(
|
||||
const std::string& config) const
|
||||
const std::string& lang, const std::string& config) const
|
||||
{
|
||||
std::vector<std::string> dirs;
|
||||
std::set<cmGeneratorTarget const*> emitted;
|
||||
@@ -172,6 +175,8 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories(
|
||||
// Target->GetLinkInformation already processed their
|
||||
// link interface and they don't have any output themselves.
|
||||
&& linkee->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
|
||||
((lang == "CXX"_s && linkee->HaveCxx20ModuleSources()) ||
|
||||
(lang == "Fortran"_s && linkee->HaveFortranSources(config))) &&
|
||||
emitted.insert(linkee).second) {
|
||||
cmLocalGenerator* lg = linkee->GetLocalGenerator();
|
||||
std::string di = cmStrCat(lg->GetCurrentBinaryDirectory(), '/',
|
||||
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
std::string GetAIXExports(std::string const& config);
|
||||
|
||||
std::vector<std::string> GetLinkedTargetDirectories(
|
||||
const std::string& config) const;
|
||||
const std::string& lang, const std::string& config) const;
|
||||
std::string ComputeTargetCompilePDB(const std::string& config) const;
|
||||
|
||||
std::string GetLinkerLauncher(const std::string& config);
|
||||
|
||||
@@ -150,7 +150,9 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
|
||||
std::ostream& internalDepends)
|
||||
{
|
||||
// Prepare the module search process.
|
||||
this->LocateModules();
|
||||
if (!this->LocateModules()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the directory in which stamp files will be stored.
|
||||
const std::string& stamp_dir = this->TargetDirectory;
|
||||
@@ -216,7 +218,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmDependsFortran::LocateModules()
|
||||
bool cmDependsFortran::LocateModules()
|
||||
{
|
||||
// Collect the set of modules provided and required by all sources.
|
||||
using ObjectInfoMap = cmDependsFortranInternals::ObjectInfoMap;
|
||||
@@ -234,7 +236,7 @@ void cmDependsFortran::LocateModules()
|
||||
|
||||
// Short-circuit for simple targets.
|
||||
if (this->Internal->TargetRequires.empty()) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Match modules provided by this target to those it requires.
|
||||
@@ -243,15 +245,19 @@ void cmDependsFortran::LocateModules()
|
||||
// Load information about other targets.
|
||||
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
||||
std::vector<std::string> infoFiles;
|
||||
mf->GetDefExpandList("CMAKE_TARGET_LINKED_INFO_FILES", infoFiles);
|
||||
mf->GetDefExpandList("CMAKE_Fortran_TARGET_LINKED_INFO_FILES", infoFiles);
|
||||
for (std::string const& i : infoFiles) {
|
||||
std::string targetDir = cmSystemTools::GetFilenamePath(i);
|
||||
std::string fname = targetDir + "/fortran.internal";
|
||||
cmsys::ifstream fin(fname.c_str());
|
||||
if (fin) {
|
||||
this->MatchRemoteModules(fin, targetDir);
|
||||
if (!fin) {
|
||||
cmSystemTools::Error(cmStrCat("-E cmake_depends failed to open ", fname,
|
||||
" for module information"));
|
||||
return false;
|
||||
}
|
||||
this->MatchRemoteModules(fin, targetDir);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmDependsFortran::MatchLocalModules()
|
||||
|
||||
@@ -55,7 +55,7 @@ protected:
|
||||
std::ostream& internalDepends) override;
|
||||
|
||||
// Find all the modules required by the target.
|
||||
void LocateModules();
|
||||
bool LocateModules();
|
||||
void MatchLocalModules();
|
||||
void MatchRemoteModules(std::istream& fin, const std::string& stampDir);
|
||||
void ConsiderModule(const std::string& name, const std::string& stampDir);
|
||||
|
||||
@@ -8860,6 +8860,15 @@ std::string cmGeneratorTarget::GenerateHeaderSetVerificationFile(
|
||||
return filename;
|
||||
}
|
||||
|
||||
bool cmGeneratorTarget::HaveFortranSources(std::string const& config) const
|
||||
{
|
||||
auto sources = cmGeneratorTarget::GetSourceFiles(config);
|
||||
return std::any_of(sources.begin(), sources.end(),
|
||||
[](BT<cmSourceFile*> const& sf) -> bool {
|
||||
return sf.Value->GetLanguage() == "Fortran"_s;
|
||||
});
|
||||
}
|
||||
|
||||
bool cmGeneratorTarget::HaveCxx20ModuleSources() const
|
||||
{
|
||||
auto const& fs_names = this->Target->GetAllFileSetNames();
|
||||
|
||||
@@ -1225,6 +1225,8 @@ public:
|
||||
cmGeneratorTarget const* t2) const;
|
||||
};
|
||||
|
||||
bool HaveFortranSources(std::string const& config) const;
|
||||
|
||||
// C++20 module support queries.
|
||||
|
||||
/**
|
||||
|
||||
@@ -2537,8 +2537,13 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
|
||||
cmStrCat(linked_target_dir, '/', arg_lang, "Modules.json");
|
||||
Json::Value ltm;
|
||||
cmsys::ifstream ltmf(ltmn.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!ltmf) {
|
||||
cmSystemTools::Error(cmStrCat("-E cmake_ninja_dyndep failed to open ",
|
||||
ltmn, " for module information"));
|
||||
return false;
|
||||
}
|
||||
Json::Reader reader;
|
||||
if (ltmf && !reader.parse(ltmf, ltm, false)) {
|
||||
if (!reader.parse(ltmf, ltm, false)) {
|
||||
cmSystemTools::Error(cmStrCat("-E cmake_ninja_dyndep failed to parse ",
|
||||
linked_target_dir,
|
||||
reader.getFormattedErrorMessages()));
|
||||
|
||||
@@ -1494,11 +1494,11 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
|
||||
/* clang-format off */
|
||||
*this->InfoFileStream
|
||||
<< "\n"
|
||||
<< "# Targets to which this target links.\n"
|
||||
<< "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
|
||||
"# Targets to which this target links which contain Fortran sources.\n"
|
||||
"set(CMAKE_Fortran_TARGET_LINKED_INFO_FILES\n";
|
||||
/* clang-format on */
|
||||
std::vector<std::string> dirs =
|
||||
this->GetLinkedTargetDirectories(this->GetConfigName());
|
||||
this->GetLinkedTargetDirectories("Fortran", this->GetConfigName());
|
||||
for (std::string const& d : dirs) {
|
||||
*this->InfoFileStream << " \"" << d << "/DependInfo.cmake\"\n";
|
||||
}
|
||||
|
||||
@@ -1675,7 +1675,7 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang,
|
||||
|
||||
Json::Value& tdi_linked_target_dirs = tdi["linked-target-dirs"] =
|
||||
Json::arrayValue;
|
||||
for (std::string const& l : this->GetLinkedTargetDirectories(config)) {
|
||||
for (std::string const& l : this->GetLinkedTargetDirectories(lang, config)) {
|
||||
tdi_linked_target_dirs.append(l);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user