summaryrefslogtreecommitdiffstats
path: root/Source/cmDependsFortran.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmDependsFortran.cxx')
-rw-r--r--Source/cmDependsFortran.cxx507
1 files changed, 208 insertions, 299 deletions
diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx
index 2e4a276..b8af178 100644
--- a/Source/cmDependsFortran.cxx
+++ b/Source/cmDependsFortran.cxx
@@ -38,31 +38,28 @@ public:
typedef std::map<std::string, cmFortranSourceInfo> ObjectInfoMap;
ObjectInfoMap ObjectInfo;
- cmFortranSourceInfo& CreateObjectInfo(const char* obj,
- const char* src)
- {
+ cmFortranSourceInfo& CreateObjectInfo(const char* obj, const char* src)
+ {
std::map<std::string, cmFortranSourceInfo>::iterator i =
this->ObjectInfo.find(obj);
- if(i == this->ObjectInfo.end())
- {
- std::map<std::string, cmFortranSourceInfo>::value_type
- entry(obj, cmFortranSourceInfo());
+ if (i == this->ObjectInfo.end()) {
+ std::map<std::string, cmFortranSourceInfo>::value_type entry(
+ obj, cmFortranSourceInfo());
i = this->ObjectInfo.insert(entry).first;
i->second.Source = src;
- }
- return i->second;
}
+ return i->second;
+ }
};
-cmDependsFortran::cmDependsFortran():
- Internal(0)
+cmDependsFortran::cmDependsFortran()
+ : Internal(0)
{
}
-cmDependsFortran
-::cmDependsFortran(cmLocalGenerator* lg):
- cmDepends(lg),
- Internal(new cmDependsFortranInternals)
+cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg)
+ : cmDepends(lg)
+ , Internal(new cmDependsFortranInternals)
{
// Configure the include file search path.
this->SetIncludePathFromLanguage("Fortran");
@@ -70,25 +67,22 @@ cmDependsFortran
// Get the list of definitions.
std::vector<std::string> definitions;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
- if(const char* c_defines =
- mf->GetDefinition("CMAKE_TARGET_DEFINITIONS_Fortran"))
- {
+ if (const char* c_defines =
+ mf->GetDefinition("CMAKE_TARGET_DEFINITIONS_Fortran")) {
cmSystemTools::ExpandListArgument(c_defines, definitions);
- }
+ }
// translate i.e. FOO=BAR to FOO and add it to the list of defined
// preprocessor symbols
- for(std::vector<std::string>::const_iterator
- it = definitions.begin(); it != definitions.end(); ++it)
- {
+ for (std::vector<std::string>::const_iterator it = definitions.begin();
+ it != definitions.end(); ++it) {
std::string def = *it;
std::string::size_type assignment = def.find("=");
- if(assignment != std::string::npos)
- {
+ if (assignment != std::string::npos) {
def = it->substr(0, assignment);
- }
- this->PPDefinitions.insert(def);
}
+ this->PPDefinitions.insert(def);
+ }
}
cmDependsFortran::~cmDependsFortran()
@@ -96,26 +90,23 @@ cmDependsFortran::~cmDependsFortran()
delete this->Internal;
}
-bool cmDependsFortran::WriteDependencies(
- const std::set<std::string>& sources, const std::string& obj,
- std::ostream&, std::ostream&)
+bool cmDependsFortran::WriteDependencies(const std::set<std::string>& sources,
+ const std::string& obj, std::ostream&,
+ std::ostream&)
{
// Make sure this is a scanning instance.
- if(sources.empty() || sources.begin()->empty())
- {
+ if (sources.empty() || sources.begin()->empty()) {
cmSystemTools::Error("Cannot scan dependencies without a source file.");
return false;
- }
- if(obj.empty())
- {
+ }
+ if (obj.empty()) {
cmSystemTools::Error("Cannot scan dependencies without an object file.");
return false;
- }
+ }
bool okay = true;
- for(std::set<std::string>::const_iterator it = sources.begin();
- it != sources.end(); ++it)
- {
+ for (std::set<std::string>::const_iterator it = sources.begin();
+ it != sources.end(); ++it) {
const std::string& src = *it;
// Get the information object for this source.
cmFortranSourceInfo& info =
@@ -129,12 +120,11 @@ bool cmDependsFortran::WriteDependencies(
cmFortranParser_FilePush(&parser, src.c_str());
// Parse the translation unit.
- if(cmFortran_yyparse(parser.Scanner) != 0)
- {
+ if (cmFortran_yyparse(parser.Scanner) != 0) {
// Failed to parse the file. Report failure to write dependencies.
okay = false;
- }
}
+ }
return okay;
}
@@ -151,25 +141,21 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
cmMakefile* mf = this->LocalGenerator->GetMakefile();
std::string mod_dir =
mf->GetSafeDefinition("CMAKE_Fortran_TARGET_MODULE_DIR");
- if (mod_dir.empty())
- {
- mod_dir =
- this->LocalGenerator->GetCurrentBinaryDirectory();
- }
+ if (mod_dir.empty()) {
+ mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
+ }
// Actually write dependencies to the streams.
typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
- for(ObjectInfoMap::const_iterator i = objInfo.begin();
- i != objInfo.end(); ++i)
- {
- if(!this->WriteDependenciesReal(i->first.c_str(), i->second,
- mod_dir, stamp_dir,
- makeDepends, internalDepends))
- {
+ for (ObjectInfoMap::const_iterator i = objInfo.begin(); i != objInfo.end();
+ ++i) {
+ if (!this->WriteDependenciesReal(i->first.c_str(), i->second, mod_dir,
+ stamp_dir, makeDepends,
+ internalDepends)) {
return false;
- }
}
+ }
// Store the list of modules provided by this target.
std::string fiName = this->TargetDirectory;
@@ -178,23 +164,20 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
fiStream << "# The fortran modules provided by this target.\n";
fiStream << "provides\n";
std::set<std::string> const& provides = this->Internal->TargetProvides;
- for(std::set<std::string>::const_iterator i = provides.begin();
- i != provides.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = provides.begin();
+ i != provides.end(); ++i) {
fiStream << " " << *i << "\n";
- }
+ }
// Create a script to clean the modules.
- if(!provides.empty())
- {
+ if (!provides.empty()) {
std::string fcName = this->TargetDirectory;
fcName += "/cmake_clean_Fortran.cmake";
cmGeneratedFileStream fcStream(fcName.c_str());
fcStream << "# Remove fortran modules provided by this target.\n";
fcStream << "FILE(REMOVE";
- for(std::set<std::string>::const_iterator i = provides.begin();
- i != provides.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = provides.begin();
+ i != provides.end(); ++i) {
std::string mod_upper = mod_dir;
mod_upper += "/";
mod_upper += cmSystemTools::UpperCase(*i);
@@ -208,21 +191,21 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
stamp += *i;
stamp += ".mod.stamp";
fcStream << "\n";
- fcStream << " \"" <<
- this->LocalGenerator->Convert(mod_lower,
- cmLocalGenerator::START_OUTPUT)
+ fcStream << " \""
+ << this->LocalGenerator->Convert(mod_lower,
+ cmLocalGenerator::START_OUTPUT)
<< "\"\n";
- fcStream << " \"" <<
- this->LocalGenerator->Convert(mod_upper,
- cmLocalGenerator::START_OUTPUT)
+ fcStream << " \""
+ << this->LocalGenerator->Convert(mod_upper,
+ cmLocalGenerator::START_OUTPUT)
<< "\"\n";
- fcStream << " \"" <<
- this->LocalGenerator->Convert(stamp,
- cmLocalGenerator::START_OUTPUT)
+ fcStream << " \""
+ << this->LocalGenerator->Convert(stamp,
+ cmLocalGenerator::START_OUTPUT)
<< "\"\n";
- }
- fcStream << " )\n";
}
+ fcStream << " )\n";
+ }
return true;
}
@@ -231,26 +214,23 @@ void cmDependsFortran::LocateModules()
// Collect the set of modules provided and required by all sources.
typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
- for(ObjectInfoMap::const_iterator infoI = objInfo.begin();
- infoI != objInfo.end(); ++infoI)
- {
+ for (ObjectInfoMap::const_iterator infoI = objInfo.begin();
+ infoI != objInfo.end(); ++infoI) {
cmFortranSourceInfo const& info = infoI->second;
// Include this module in the set provided by this target.
this->Internal->TargetProvides.insert(info.Provides.begin(),
info.Provides.end());
- for(std::set<std::string>::const_iterator i = info.Requires.begin();
- i != info.Requires.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = info.Requires.begin();
+ i != info.Requires.end(); ++i) {
this->Internal->TargetRequires[*i] = "";
- }
}
+ }
// Short-circuit for simple targets.
- if(this->Internal->TargetRequires.empty())
- {
+ if (this->Internal->TargetRequires.empty()) {
return;
- }
+ }
// Match modules provided by this target to those it requires.
this->MatchLocalModules();
@@ -258,33 +238,29 @@ void cmDependsFortran::LocateModules()
// Load information about other targets.
cmMakefile* mf = this->LocalGenerator->GetMakefile();
std::vector<std::string> infoFiles;
- if(const char* infoFilesValue =
- mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES"))
- {
+ if (const char* infoFilesValue =
+ mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES")) {
cmSystemTools::ExpandListArgument(infoFilesValue, infoFiles);
- }
- for(std::vector<std::string>::const_iterator i = infoFiles.begin();
- i != infoFiles.end(); ++i)
- {
+ }
+ for (std::vector<std::string>::const_iterator i = infoFiles.begin();
+ i != infoFiles.end(); ++i) {
std::string targetDir = cmSystemTools::GetFilenamePath(*i);
std::string fname = targetDir + "/fortran.internal";
cmsys::ifstream fin(fname.c_str());
- if(fin)
- {
+ if (fin) {
this->MatchRemoteModules(fin, targetDir.c_str());
- }
}
+ }
}
void cmDependsFortran::MatchLocalModules()
{
const char* stampDir = this->TargetDirectory.c_str();
std::set<std::string> const& provides = this->Internal->TargetProvides;
- for(std::set<std::string>::const_iterator i = provides.begin();
- i != provides.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = provides.begin();
+ i != provides.end(); ++i) {
this->ConsiderModule(i->c_str(), stampDir);
- }
+ }
}
void cmDependsFortran::MatchRemoteModules(std::istream& fin,
@@ -292,59 +268,47 @@ void cmDependsFortran::MatchRemoteModules(std::istream& fin,
{
std::string line;
bool doing_provides = false;
- while(cmSystemTools::GetLineFromStream(fin, line))
- {
+ while (cmSystemTools::GetLineFromStream(fin, line)) {
// Ignore comments and empty lines.
- if(line.empty() || line[0] == '#' || line[0] == '\r')
- {
+ if (line.empty() || line[0] == '#' || line[0] == '\r') {
continue;
- }
+ }
- if(line[0] == ' ')
- {
- if(doing_provides)
- {
- this->ConsiderModule(line.c_str()+1, stampDir);
- }
+ if (line[0] == ' ') {
+ if (doing_provides) {
+ this->ConsiderModule(line.c_str() + 1, stampDir);
}
- else if(line == "provides")
- {
+ } else if (line == "provides") {
doing_provides = true;
- }
- else
- {
+ } else {
doing_provides = false;
- }
}
+ }
}
-void cmDependsFortran::ConsiderModule(const char* name,
- const char* stampDir)
+void cmDependsFortran::ConsiderModule(const char* name, const char* stampDir)
{
// Locate each required module.
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
TargetRequiresMap::iterator required =
this->Internal->TargetRequires.find(name);
- if(required != this->Internal->TargetRequires.end() &&
- required->second.empty())
- {
+ if (required != this->Internal->TargetRequires.end() &&
+ required->second.empty()) {
// The module is provided by a CMake target. It will have a stamp file.
std::string stampFile = stampDir;
stampFile += "/";
stampFile += name;
stampFile += ".mod.stamp";
required->second = stampFile;
- }
+ }
}
-bool
-cmDependsFortran
-::WriteDependenciesReal(const char *obj,
- cmFortranSourceInfo const& info,
- std::string const& mod_dir,
- const char* stamp_dir,
- std::ostream& makeDepends,
- std::ostream& internalDepends)
+bool cmDependsFortran::WriteDependenciesReal(const char* obj,
+ cmFortranSourceInfo const& info,
+ std::string const& mod_dir,
+ const char* stamp_dir,
+ std::ostream& makeDepends,
+ std::ostream& internalDepends)
{
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
@@ -354,39 +318,34 @@ cmDependsFortran
// Write the include dependencies to the output stream.
std::string obj_i =
this->LocalGenerator->Convert(obj, cmLocalGenerator::HOME_OUTPUT);
- std::string obj_m =
- this->LocalGenerator->ConvertToOutputFormat(obj_i,
- cmLocalGenerator::MAKERULE);
+ std::string obj_m = this->LocalGenerator->ConvertToOutputFormat(
+ obj_i, cmLocalGenerator::MAKERULE);
internalDepends << obj_i << std::endl;
internalDepends << " " << src << std::endl;
- for(std::set<std::string>::const_iterator i = info.Includes.begin();
- i != info.Includes.end(); ++i)
- {
- makeDepends << obj_m << ": " <<
- this->LocalGenerator->Convert(*i,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::MAKERULE)
+ for (std::set<std::string>::const_iterator i = info.Includes.begin();
+ i != info.Includes.end(); ++i) {
+ makeDepends << obj_m << ": "
+ << this->LocalGenerator->Convert(*i,
+ cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE)
<< std::endl;
internalDepends << " " << *i << std::endl;
- }
+ }
makeDepends << std::endl;
// Write module requirements to the output stream.
- for(std::set<std::string>::const_iterator i = info.Requires.begin();
- i != info.Requires.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = info.Requires.begin();
+ i != info.Requires.end(); ++i) {
// Require only modules not provided in the same source.
- if(std::set<std::string>::const_iterator(info.Provides.find(*i)) !=
- info.Provides.end())
- {
+ if (std::set<std::string>::const_iterator(info.Provides.find(*i)) !=
+ info.Provides.end()) {
continue;
- }
+ }
// If the module is provided in this target special handling is
// needed.
- if(this->Internal->TargetProvides.find(*i) !=
- this->Internal->TargetProvides.end())
- {
+ 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.
@@ -394,67 +353,57 @@ cmDependsFortran
proxy += "/";
proxy += *i;
proxy += ".mod.proxy";
- proxy = this->LocalGenerator->Convert(proxy,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::MAKERULE);
+ proxy = this->LocalGenerator->Convert(
+ proxy, cmLocalGenerator::HOME_OUTPUT, cmLocalGenerator::MAKERULE);
// 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 =
this->Internal->TargetRequires.find(*i);
- if(required == this->Internal->TargetRequires.end()) { abort(); }
- if(!required->second.empty())
- {
+ if (required == this->Internal->TargetRequires.end()) {
+ abort();
+ }
+ if (!required->second.empty()) {
// This module is known. Depend on its timestamp file.
- std::string stampFile =
- this->LocalGenerator->Convert(required->second,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::MAKERULE);
+ std::string stampFile = this->LocalGenerator->Convert(
+ required->second, cmLocalGenerator::HOME_OUTPUT,
+ cmLocalGenerator::MAKERULE);
makeDepends << obj_m << ": " << stampFile << "\n";
- }
- else
- {
+ } else {
// This module is not known to CMake. Try to locate it where
// the compiler will and depend on that.
std::string module;
- if(this->FindModule(*i, module))
- {
- module =
- this->LocalGenerator->Convert(module,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::MAKERULE);
+ if (this->FindModule(*i, module)) {
+ module = this->LocalGenerator->Convert(
+ module, cmLocalGenerator::HOME_OUTPUT, cmLocalGenerator::MAKERULE);
makeDepends << obj_m << ": " << module << "\n";
- }
}
}
+ }
// Write provided modules to the output stream.
- for(std::set<std::string>::const_iterator i = info.Provides.begin();
- i != info.Provides.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = info.Provides.begin();
+ i != info.Provides.end(); ++i) {
std::string proxy = stamp_dir;
proxy += "/";
proxy += *i;
proxy += ".mod.proxy";
- proxy = this->LocalGenerator->Convert(proxy,
- cmLocalGenerator::HOME_OUTPUT,
+ proxy = this->LocalGenerator->Convert(proxy, cmLocalGenerator::HOME_OUTPUT,
cmLocalGenerator::MAKERULE);
makeDepends << proxy << ": " << obj_m << ".provides" << std::endl;
- }
+ }
// If any modules are provided then they must be converted to stamp files.
- if(!info.Provides.empty())
- {
+ if (!info.Provides.empty()) {
// Create a target to copy the module after the object file
// changes.
makeDepends << obj_m << ".provides.build:\n";
- for(std::set<std::string>::const_iterator i = info.Provides.begin();
- i != info.Provides.end(); ++i)
- {
+ for (std::set<std::string>::const_iterator i = info.Provides.begin();
+ i != info.Provides.end(); ++i) {
// Include this module in the set provided by this target.
this->Internal->TargetProvides.insert(*i);
@@ -465,28 +414,23 @@ cmDependsFortran
std::string modFile = mod_dir;
modFile += "/";
modFile += *i;
- modFile =
- this->LocalGenerator->Convert(modFile,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::SHELL);
+ modFile = this->LocalGenerator->Convert(
+ modFile, cmLocalGenerator::HOME_OUTPUT, cmLocalGenerator::SHELL);
std::string stampFile = stamp_dir;
stampFile += "/";
stampFile += m;
stampFile += ".mod.stamp";
- stampFile =
- this->LocalGenerator->Convert(stampFile,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::SHELL);
- makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod "
- << modFile << " " << stampFile;
+ stampFile = this->LocalGenerator->Convert(
+ stampFile, cmLocalGenerator::HOME_OUTPUT, cmLocalGenerator::SHELL);
+ makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod " << modFile
+ << " " << stampFile;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
- if(cid && *cid)
- {
+ if (cid && *cid) {
makeDepends << " " << cid;
- }
- makeDepends << "\n";
}
+ makeDepends << "\n";
+ }
// After copying the modules update the timestamp file so that
// copying will not be done again until the source rebuilds.
makeDepends << "\t$(CMAKE_COMMAND) -E touch " << obj_m
@@ -496,17 +440,15 @@ cmDependsFortran
// the target finishes building.
std::string driver = this->TargetDirectory;
driver += "/build";
- driver = this->LocalGenerator->Convert(driver,
- cmLocalGenerator::HOME_OUTPUT,
- cmLocalGenerator::MAKERULE);
+ driver = this->LocalGenerator->Convert(
+ driver, cmLocalGenerator::HOME_OUTPUT, cmLocalGenerator::MAKERULE);
makeDepends << driver << ": " << obj_m << ".provides.build\n";
- }
+ }
return true;
}
-bool cmDependsFortran::FindModule(std::string const& name,
- std::string& module)
+bool cmDependsFortran::FindModule(std::string const& name, std::string& module)
{
// Construct possible names for the module file.
std::string mod_upper = cmSystemTools::UpperCase(name);
@@ -516,29 +458,26 @@ bool cmDependsFortran::FindModule(std::string const& name,
// Search the include path for the module.
std::string fullName;
- for(std::vector<std::string>::const_iterator i =
- this->IncludePath.begin(); i != this->IncludePath.end(); ++i)
- {
+ for (std::vector<std::string>::const_iterator i = this->IncludePath.begin();
+ i != this->IncludePath.end(); ++i) {
// Try the lower-case name.
fullName = *i;
fullName += "/";
fullName += mod_lower;
- if(cmSystemTools::FileExists(fullName.c_str(), true))
- {
+ if (cmSystemTools::FileExists(fullName.c_str(), true)) {
module = fullName;
return true;
- }
+ }
// Try the upper-case name.
fullName = *i;
fullName += "/";
fullName += mod_upper;
- if(cmSystemTools::FileExists(fullName.c_str(), true))
- {
+ if (cmSystemTools::FileExists(fullName.c_str(), true)) {
module = fullName;
return true;
- }
}
+ }
return false;
}
@@ -557,12 +496,13 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
std::string mod = args[2];
std::string stamp = args[3];
std::string compilerId;
- if(args.size() >= 5)
- {
+ if (args.size() >= 5) {
compilerId = args[4];
- }
+ }
std::string mod_dir = cmSystemTools::GetFilenamePath(mod);
- if(!mod_dir.empty()) { mod_dir += "/"; }
+ if (!mod_dir.empty()) {
+ mod_dir += "/";
+ }
std::string mod_upper = mod_dir;
mod_upper += cmSystemTools::UpperCase(cmSystemTools::GetFilenameName(mod));
std::string mod_lower = mod_dir;
@@ -570,101 +510,81 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
mod += ".mod";
mod_upper += ".mod";
mod_lower += ".mod";
- if(cmSystemTools::FileExists(mod_upper.c_str(), true))
- {
- if(cmDependsFortran::ModulesDiffer(mod_upper.c_str(), stamp.c_str(),
- compilerId.c_str()))
- {
- if(!cmSystemTools::CopyFileAlways(mod_upper, stamp))
- {
- std::cerr << "Error copying Fortran module from \""
- << mod_upper << "\" to \"" << stamp
- << "\".\n";
+ if (cmSystemTools::FileExists(mod_upper.c_str(), true)) {
+ if (cmDependsFortran::ModulesDiffer(mod_upper.c_str(), stamp.c_str(),
+ compilerId.c_str())) {
+ if (!cmSystemTools::CopyFileAlways(mod_upper, stamp)) {
+ std::cerr << "Error copying Fortran module from \"" << mod_upper
+ << "\" to \"" << stamp << "\".\n";
return false;
- }
}
- return true;
}
- else if(cmSystemTools::FileExists(mod_lower.c_str(), true))
- {
- if(cmDependsFortran::ModulesDiffer(mod_lower.c_str(), stamp.c_str(),
- compilerId.c_str()))
- {
- if(!cmSystemTools::CopyFileAlways(mod_lower, stamp))
- {
- std::cerr << "Error copying Fortran module from \""
- << mod_lower << "\" to \"" << stamp
- << "\".\n";
+ return true;
+ } else if (cmSystemTools::FileExists(mod_lower.c_str(), true)) {
+ if (cmDependsFortran::ModulesDiffer(mod_lower.c_str(), stamp.c_str(),
+ compilerId.c_str())) {
+ if (!cmSystemTools::CopyFileAlways(mod_lower, stamp)) {
+ std::cerr << "Error copying Fortran module from \"" << mod_lower
+ << "\" to \"" << stamp << "\".\n";
return false;
- }
}
- return true;
}
+ return true;
+ }
- std::cerr << "Error copying Fortran module \"" << args[2]
- << "\". Tried \"" << mod_upper
- << "\" and \"" << mod_lower << "\".\n";
+ std::cerr << "Error copying Fortran module \"" << args[2] << "\". Tried \""
+ << mod_upper << "\" and \"" << mod_lower << "\".\n";
return false;
}
// Helper function to look for a short sequence in a stream. If this
// is later used for longer sequences it should be re-written using an
// efficient string search algorithm such as Boyer-Moore.
-static
-bool cmFortranStreamContainsSequence(std::istream& ifs,
- const char* seq, int len)
+static bool cmFortranStreamContainsSequence(std::istream& ifs, const char* seq,
+ int len)
{
assert(len > 0);
int cur = 0;
- while(cur < len)
- {
+ while (cur < len) {
// Get the next character.
int token = ifs.get();
- if(!ifs)
- {
+ if (!ifs) {
return false;
- }
+ }
// Check the character.
- if(token == static_cast<int>(seq[cur]))
- {
+ if (token == static_cast<int>(seq[cur])) {
++cur;
- }
- else
- {
+ } else {
// Assume the sequence has no repeating subsequence.
cur = 0;
- }
}
+ }
// The entire sequence was matched.
return true;
}
// Helper function to compare the remaining content in two streams.
-static bool cmFortranStreamsDiffer(std::istream& ifs1,
- std::istream& ifs2)
+static bool cmFortranStreamsDiffer(std::istream& ifs1, std::istream& ifs2)
{
// Compare the remaining content.
- for(;;)
- {
+ for (;;) {
int ifs1_c = ifs1.get();
int ifs2_c = ifs2.get();
- if(!ifs1 && !ifs2)
- {
+ if (!ifs1 && !ifs2) {
// We have reached the end of both streams simultaneously.
// The streams are identical.
return false;
- }
+ }
- if(!ifs1 || !ifs2 || ifs1_c != ifs2_c)
- {
+ if (!ifs1 || !ifs2 || ifs1_c != ifs2_c) {
// We have reached the end of one stream before the other or
// found differing content. The streams are different.
break;
- }
}
+ }
return true;
}
@@ -701,15 +621,13 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
TODO ...
*/
-
/* Compilers which do _not_ produce different mod content when the same
* source is compiled twice
* -SunPro
*/
- if(strcmp(compilerId, "SunPro") == 0)
- {
+ if (strcmp(compilerId, "SunPro") == 0) {
return cmSystemTools::FilesDiffer(modFile, stampFile);
- }
+ }
#if defined(_WIN32) || defined(__CYGWIN__)
cmsys::ifstream finModFile(modFile, std::ios::in | std::ios::binary);
@@ -718,11 +636,10 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
cmsys::ifstream finModFile(modFile, std::ios::in);
cmsys::ifstream finStampFile(stampFile, std::ios::in);
#endif
- if(!finModFile || !finStampFile)
- {
+ if (!finModFile || !finStampFile) {
// At least one of the files does not exist. The modules differ.
return true;
- }
+ }
/* Compilers which _do_ produce different mod content when the same
* source is compiled twice
@@ -732,62 +649,54 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
* Eat the stream content until all recompile only related changes
* are left behind.
*/
- if (strcmp(compilerId, "GNU") == 0 )
- {
+ if (strcmp(compilerId, "GNU") == 0) {
// GNU Fortran 4.9 and later compress .mod files with gzip
// but also do not include a date so we can fall through to
// compare them without skipping any prefix.
unsigned char hdr[2];
- bool okay = finModFile.read(reinterpret_cast<char*>(hdr), 2)? true:false;
+ bool okay =
+ finModFile.read(reinterpret_cast<char*>(hdr), 2) ? true : false;
finModFile.seekg(0);
- if(!(okay && hdr[0] == 0x1f && hdr[1] == 0x8b))
- {
- const char seq[1] = {'\n'};
+ if (!(okay && hdr[0] == 0x1f && hdr[1] == 0x8b)) {
+ const char seq[1] = { '\n' };
const int seqlen = 1;
- if(!cmFortranStreamContainsSequence(finModFile, seq, seqlen))
- {
+ if (!cmFortranStreamContainsSequence(finModFile, seq, seqlen)) {
// The module is of unexpected format. Assume it is different.
std::cerr << compilerId << " fortran module " << modFile
<< " has unexpected format." << std::endl;
return true;
- }
+ }
- if(!cmFortranStreamContainsSequence(finStampFile, seq, seqlen))
- {
+ if (!cmFortranStreamContainsSequence(finStampFile, seq, seqlen)) {
// The stamp must differ if the sequence is not contained.
return true;
- }
}
}
- else if(strcmp(compilerId, "Intel") == 0)
- {
- const char seq[2] = {'\n', '\0'};
+ } else if (strcmp(compilerId, "Intel") == 0) {
+ const char seq[2] = { '\n', '\0' };
const int seqlen = 2;
- if(!cmFortranStreamContainsSequence(finModFile, seq, seqlen))
- {
+ if (!cmFortranStreamContainsSequence(finModFile, seq, seqlen)) {
// The module is of unexpected format. Assume it is different.
std::cerr << compilerId << " fortran module " << modFile
<< " has unexpected format." << std::endl;
return true;
- }
+ }
- if(!cmFortranStreamContainsSequence(finStampFile, seq, seqlen))
- {
+ if (!cmFortranStreamContainsSequence(finStampFile, seq, seqlen)) {
// The stamp must differ if the sequence is not contained.
return true;
- }
}
+ }
// Compare the remaining content. If no compiler id matched above,
// including the case none was given, this will compare the whole
// content.
- if(!cmFortranStreamsDiffer(finModFile, finStampFile))
- {
+ if (!cmFortranStreamsDiffer(finModFile, finStampFile)) {
return false;
- }
+ }
- // The modules are different.
- return true;
+ // The modules are different.
+ return true;
}