Merge topic 'makefile-simplify-fortran'

7ab9a625 Makefiles: Drop 'requires' step and its supporting infrastructure
5f2e2c38 Makefiles: Avoid nested make calls for Fortran module dependencies

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1523
This commit is contained in:
Brad King
2017-12-15 15:42:01 +00:00
committed by Kitware Robot
9 changed files with 22 additions and 140 deletions

View File

@@ -67,11 +67,6 @@ if(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
set(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran "${_override}")
endif()
# Fortran needs cmake to do a requires step during its build process to
# catch any modules
set(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
endif()

View File

@@ -331,24 +331,6 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
continue;
}
// If the module is provided in this target special handling is
// needed.
if (this->Internal->TargetProvides.find(i) !=
this->Internal->TargetProvides.end()) {
// The module is provided by a different source in the same
// target. Add the proxy dependency to make sure the other
// source builds first.
std::string proxy = stamp_dir;
proxy += "/";
proxy += i;
proxy += ".mod.proxy";
proxy = cmSystemTools::ConvertToOutputPath(
this->MaybeConvertToRelativePath(binDir, proxy).c_str());
// since we require some things add them to our list of requirements
makeDepends << obj_m << ".requires: " << proxy << std::endl;
}
// The object file should depend on timestamped files for the
// modules it uses.
TargetRequiresMap::const_iterator required =
@@ -373,22 +355,10 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
}
}
// Write provided modules to the output stream.
for (std::string const& i : info.Provides) {
std::string proxy = stamp_dir;
proxy += "/";
proxy += i;
proxy += ".mod.proxy";
proxy = cmSystemTools::ConvertToOutputPath(
this->MaybeConvertToRelativePath(binDir, proxy).c_str());
makeDepends << proxy << ": " << obj_m << ".provides" << std::endl;
}
// If any modules are provided then they must be converted to stamp files.
if (!info.Provides.empty()) {
// Create a target to copy the module after the object file
// changes.
makeDepends << obj_m << ".provides.build:\n";
for (std::string const& i : info.Provides) {
// Include this module in the set provided by this target.
this->Internal->TargetProvides.insert(i);
@@ -407,11 +377,25 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
stampFile += "/";
stampFile += m;
stampFile += ".mod.stamp";
stampFile = this->LocalGenerator->ConvertToOutputFormat(
this->MaybeConvertToRelativePath(binDir, stampFile),
cmOutputConverter::SHELL);
stampFile = this->MaybeConvertToRelativePath(binDir, stampFile);
std::string const stampFileForShell =
this->LocalGenerator->ConvertToOutputFormat(stampFile,
cmOutputConverter::SHELL);
std::string const stampFileForMake =
cmSystemTools::ConvertToOutputPath(stampFile.c_str());
makeDepends << obj_m << ".provides.build"
<< ": " << stampFileForMake << "\n";
// Note that when cmake_copy_f90_mod finds that a module file
// and the corresponding stamp file have no differences, the stamp
// file is not updated. In such case the stamp file will be always
// older than its prerequisite and trigger cmake_copy_f90_mod
// on each new build. This is expected behavior for incremental
// builds and can not be changed without preforming recursive make
// calls that would considerably slow down the building process.
makeDepends << stampFileForMake << ": " << obj_m << "\n";
makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod " << modFile
<< " " << stampFile;
<< " " << stampFileForShell;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
if (cid && *cid) {
@@ -419,8 +403,8 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
}
makeDepends << "\n";
}
// After copying the modules update the timestamp file so that
// copying will not be done again until the source rebuilds.
makeDepends << obj_m << ".provides.build:\n";
// After copying the modules update the timestamp file.
makeDepends << "\t$(CMAKE_COMMAND) -E touch " << obj_m
<< ".provides.build\n";

View File

@@ -21,7 +21,6 @@
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cmake.h"
@@ -630,8 +629,6 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
makefileName = localName;
makefileName += "/build.make";
bool needRequiresStep = this->NeedRequiresStep(gtarget);
lg->WriteDivider(ruleFileStream);
ruleFileStream << "# Target rules for target " << localName << "\n\n";
@@ -641,13 +638,6 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
commands.push_back(
lg->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
// add requires if we need it for this generator
if (needRequiresStep) {
makeTargetName = localName;
makeTargetName += "/requires";
commands.push_back(
lg->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
}
makeTargetName = localName;
makeTargetName += "/build";
commands.push_back(
@@ -952,21 +942,3 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
commands, true);
ruleFileStream << "\n\n";
}
bool cmGlobalUnixMakefileGenerator3::NeedRequiresStep(
const cmGeneratorTarget* target)
{
std::set<std::string> languages;
target->GetLanguages(
languages,
target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (std::string const& l : languages) {
std::string var = "CMAKE_NEEDS_REQUIRES_STEP_";
var += l;
var += "_FLAG";
if (target->Target->GetMakefile()->GetDefinition(var)) {
return true;
}
}
return false;
}

View File

@@ -174,9 +174,6 @@ protected:
void AppendGlobalTargetDepends(std::vector<std::string>& depends,
cmGeneratorTarget* target);
// does this generator need a requires step for any of its targets
bool NeedRequiresStep(cmGeneratorTarget const*);
// Target name hooks for superclass.
const char* GetAllTargetName() const override { return "all"; }
const char* GetInstallTargetName() const override { return "install"; }

View File

@@ -1444,6 +1444,8 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
}
#ifdef CMAKE_BUILD_WITH_CMAKE
else if (lang == "Fortran") {
ruleFileStream << "# Note that incremental build could trigger "
<< "a call to cmake_copy_f90_mod on each re-build\n";
scanner = new cmDependsFortran(this);
} else if (lang == "Java") {
scanner = new cmDependsJava();

View File

@@ -69,9 +69,6 @@ void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
this->WriteExecutableRule(true);
}
// Write the requires target.
this->WriteTargetRequiresRules();
// Write clean target
this->WriteTargetCleanRules();

View File

@@ -89,9 +89,6 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
break;
}
// Write the requires target.
this->WriteTargetRequiresRules();
// Write clean target
this->WriteTargetCleanRules();

View File

@@ -824,65 +824,6 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
commands, false);
}
}
// If the language needs provides-requires mode, create the
// corresponding targets.
std::string objectRequires = relativeObj;
objectRequires += ".requires";
std::vector<std::string> p_depends;
// always provide an empty requires target
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
objectRequires, p_depends, no_commands,
true);
// write a build rule to recursively build what this obj provides
std::string objectProvides = relativeObj;
objectProvides += ".provides";
std::string temp = relativeObj;
temp += ".provides.build";
std::vector<std::string> r_commands;
std::string tgtMakefileName =
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
tgtMakefileName += "/build.make";
r_commands.push_back(
this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(), temp));
p_depends.clear();
p_depends.push_back(objectRequires);
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
objectProvides, p_depends, r_commands,
true);
// write the provides.build rule dependency on the obj file
p_depends.clear();
p_depends.push_back(relativeObj);
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, temp,
p_depends, no_commands, false);
}
void cmMakefileTargetGenerator::WriteTargetRequiresRules()
{
std::vector<std::string> depends;
std::vector<std::string> no_commands;
// Construct the name of the dependency generation target.
std::string depTarget =
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
depTarget += "/requires";
// This target drives dependency generation for all object files.
std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
std::string objTarget;
for (std::string const& obj : this->Objects) {
objTarget = relPath;
objTarget += obj;
objTarget += ".requires";
depends.push_back(objTarget);
}
// Write the rule.
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
depTarget, depends, no_commands, true);
}
void cmMakefileTargetGenerator::WriteTargetCleanRules()

View File

@@ -63,9 +63,6 @@ protected:
void WriteCommonCodeRules();
void WriteTargetLanguageFlags();
// write the provide require rules for this target
void WriteTargetRequiresRules();
// write the clean rules for this target
void WriteTargetCleanRules();