diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-02-01 03:13:56 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-02-01 03:34:29 (GMT) |
commit | 837f7c113a9333997304c3b5742c922617da23b5 (patch) | |
tree | 19e0f56c92675f0095786d51abb968d5ac63701d /Source | |
parent | d19648a9286d0943858ea0c5dc5e13d3b735b129 (diff) | |
download | CMake-837f7c113a9333997304c3b5742c922617da23b5.zip CMake-837f7c113a9333997304c3b5742c922617da23b5.tar.gz CMake-837f7c113a9333997304c3b5742c922617da23b5.tar.bz2 |
cmCommonTargetGenerator: classify linked target directories by language
These directories are used to direct collators for Fortran and C++
modules to consume dependent module information to properly collate.
However, the consumption of these files merely checks for existence of
the file, not whether they are actually needed anymore.
The problem arises when a target has Fortran or C++ modules at point A,
a build occurs populating this file, and then the target is updated to
no longer have potential modules. The `DependInfo.make` (for
`Makefiles`) or `<LANG>DependInfo.json` (for `Ninja`) files still exist
as they are never guaranteed to be cleaned up. This can introduce stale
information to the build which may cause a false-positive compilation if
a module file happens to still exist and gets found this way.
Instead, query the `linked-target-dirs` using the language in question
and only add the directory if it contains potential sources for modules
coming from the language in question.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCommonTargetGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmCommonTargetGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 2 |
4 files changed, 9 insertions, 4 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 5fe6756..a065ba9 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -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(), '/', diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index e8c5a19..2d23037 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -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); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 4f80edc..c40d685 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1498,7 +1498,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() "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"; } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 6887376..13782b0 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -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); } |