2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2005-01-26 23:33:38 +03:00
|
|
|
#include "cmDependsFortran.h"
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmFortranParser.h" /* Interface to parser object. */
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2007-10-12 17:51:28 +04:00
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmSystemTools.h"
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2005-01-27 00:09:48 +03:00
|
|
|
#include <assert.h>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <utility>
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2005-03-02 17:02:36 +03:00
|
|
|
// TODO: Test compiler for the case of the mod file. Some always
|
|
|
|
// use lower case and some always use upper case. I do not know if any
|
|
|
|
// use the case from the source code.
|
|
|
|
|
2007-12-28 19:49:59 +03:00
|
|
|
class cmDependsFortranInternals
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The set of modules provided by this target.
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> TargetProvides;
|
2007-12-28 19:49:59 +03:00
|
|
|
|
|
|
|
// Map modules required by this target to locations.
|
2014-02-10 09:21:34 +04:00
|
|
|
typedef std::map<std::string, std::string> TargetRequiresMap;
|
2007-12-28 19:49:59 +03:00
|
|
|
TargetRequiresMap TargetRequires;
|
|
|
|
|
|
|
|
// Information about each object file.
|
2015-07-22 20:21:45 +03:00
|
|
|
typedef std::map<std::string, cmFortranSourceInfo> ObjectInfoMap;
|
2007-12-28 19:49:59 +03:00
|
|
|
ObjectInfoMap ObjectInfo;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmFortranSourceInfo& CreateObjectInfo(const char* obj, const char* src)
|
|
|
|
{
|
2015-07-22 20:21:45 +03:00
|
|
|
std::map<std::string, cmFortranSourceInfo>::iterator i =
|
2007-12-28 19:49:59 +03:00
|
|
|
this->ObjectInfo.find(obj);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i == this->ObjectInfo.end()) {
|
|
|
|
std::map<std::string, cmFortranSourceInfo>::value_type entry(
|
|
|
|
obj, cmFortranSourceInfo());
|
2007-12-28 19:49:59 +03:00
|
|
|
i = this->ObjectInfo.insert(entry).first;
|
|
|
|
i->second.Source = src;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return i->second;
|
|
|
|
}
|
2005-01-26 23:33:38 +03:00
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmDependsFortran::cmDependsFortran()
|
2016-06-27 23:44:16 +03:00
|
|
|
: Internal(CM_NULLPTR)
|
2005-01-26 23:33:38 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg)
|
|
|
|
: cmDepends(lg)
|
|
|
|
, Internal(new cmDependsFortranInternals)
|
2005-01-26 23:33:38 +03:00
|
|
|
{
|
2009-02-24 22:32:25 +03:00
|
|
|
// Configure the include file search path.
|
|
|
|
this->SetIncludePathFromLanguage("Fortran");
|
|
|
|
|
2008-05-08 18:09:14 +04:00
|
|
|
// Get the list of definitions.
|
|
|
|
std::vector<std::string> definitions;
|
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* c_defines =
|
|
|
|
mf->GetDefinition("CMAKE_TARGET_DEFINITIONS_Fortran")) {
|
2008-05-08 18:09:14 +04:00
|
|
|
cmSystemTools::ExpandListArgument(c_defines, definitions);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-08 18:09:14 +04:00
|
|
|
|
2008-01-18 03:58:01 +03:00
|
|
|
// translate i.e. FOO=BAR to FOO and add it to the list of defined
|
2008-01-09 18:30:11 +03:00
|
|
|
// preprocessor symbols
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator it = definitions.begin();
|
|
|
|
it != definitions.end(); ++it) {
|
2008-01-18 03:58:01 +03:00
|
|
|
std::string def = *it;
|
2016-05-24 22:24:10 +03:00
|
|
|
std::string::size_type assignment = def.find('=');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (assignment != std::string::npos) {
|
2008-01-18 03:58:01 +03:00
|
|
|
def = it->substr(0, assignment);
|
2008-01-09 18:30:11 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->PPDefinitions.insert(def);
|
|
|
|
}
|
2005-01-26 23:33:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmDependsFortran::~cmDependsFortran()
|
|
|
|
{
|
2007-12-28 19:49:59 +03:00
|
|
|
delete this->Internal;
|
2005-01-26 23:33:38 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmDependsFortran::WriteDependencies(const std::set<std::string>& sources,
|
2016-08-17 02:49:57 +03:00
|
|
|
const std::string& obj,
|
|
|
|
std::ostream& /*makeDepends*/,
|
|
|
|
std::ostream& /*internalDepends*/)
|
2005-01-26 23:33:38 +03:00
|
|
|
{
|
|
|
|
// Make sure this is a scanning instance.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (sources.empty() || sources.begin()->empty()) {
|
2012-09-30 19:53:01 +04:00
|
|
|
cmSystemTools::Error("Cannot scan dependencies without a source file.");
|
2005-01-26 23:33:38 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (obj.empty()) {
|
2005-07-27 17:49:37 +04:00
|
|
|
cmSystemTools::Error("Cannot scan dependencies without an object file.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2012-09-30 19:53:01 +04:00
|
|
|
bool okay = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator it = sources.begin();
|
|
|
|
it != sources.end(); ++it) {
|
2012-09-30 19:53:01 +04:00
|
|
|
const std::string& src = *it;
|
|
|
|
// Get the information object for this source.
|
2015-07-22 20:21:45 +03:00
|
|
|
cmFortranSourceInfo& info =
|
2012-09-30 19:53:01 +04:00
|
|
|
this->Internal->CreateObjectInfo(obj.c_str(), src.c_str());
|
2007-10-12 17:51:28 +04:00
|
|
|
|
2015-07-22 20:45:28 +03:00
|
|
|
// Create the parser object. The constructor takes info by reference,
|
|
|
|
// so we may look into the resulting objects later.
|
|
|
|
cmFortranParser parser(this->IncludePath, this->PPDefinitions, info);
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2012-09-30 19:53:01 +04:00
|
|
|
// Push on the starting file.
|
2015-07-22 20:21:45 +03:00
|
|
|
cmFortranParser_FilePush(&parser, src.c_str());
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2012-09-30 19:53:01 +04:00
|
|
|
// Parse the translation unit.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmFortran_yyparse(parser.Scanner) != 0) {
|
2012-09-30 19:53:01 +04:00
|
|
|
// Failed to parse the file. Report failure to write dependencies.
|
|
|
|
okay = false;
|
2016-09-05 21:50:31 +03:00
|
|
|
/* clang-format off */
|
|
|
|
std::cerr <<
|
|
|
|
"warning: failed to parse dependencies from Fortran source "
|
|
|
|
"'" << src << "': " << parser.Error << std::endl
|
|
|
|
;
|
|
|
|
/* clang-format on */
|
2005-01-26 23:33:38 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-30 19:53:01 +04:00
|
|
|
return okay;
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmDependsFortran::Finalize(std::ostream& makeDepends,
|
|
|
|
std::ostream& internalDepends)
|
|
|
|
{
|
|
|
|
// Prepare the module search process.
|
|
|
|
this->LocateModules();
|
|
|
|
|
2007-12-31 00:11:38 +03:00
|
|
|
// Get the directory in which stamp files will be stored.
|
2008-01-03 02:30:48 +03:00
|
|
|
const char* stamp_dir = this->TargetDirectory.c_str();
|
2007-12-31 00:11:38 +03:00
|
|
|
|
|
|
|
// Get the directory in which module files will be created.
|
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
2015-07-29 18:44:25 +03:00
|
|
|
std::string mod_dir =
|
|
|
|
mf->GetSafeDefinition("CMAKE_Fortran_TARGET_MODULE_DIR");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (mod_dir.empty()) {
|
|
|
|
mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
|
|
|
|
}
|
2007-12-31 00:11:38 +03:00
|
|
|
|
2007-12-28 19:49:59 +03:00
|
|
|
// Actually write dependencies to the streams.
|
|
|
|
typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
|
|
|
|
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
|
2016-05-16 17:34:04 +03:00
|
|
|
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)) {
|
2007-12-28 19:49:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
|
|
|
// Store the list of modules provided by this target.
|
|
|
|
std::string fiName = this->TargetDirectory;
|
|
|
|
fiName += "/fortran.internal";
|
|
|
|
cmGeneratedFileStream fiStream(fiName.c_str());
|
|
|
|
fiStream << "# The fortran modules provided by this target.\n";
|
|
|
|
fiStream << "provides\n";
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> const& provides = this->Internal->TargetProvides;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = provides.begin();
|
|
|
|
i != provides.end(); ++i) {
|
2007-12-28 19:49:59 +03:00
|
|
|
fiStream << " " << *i << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:50:14 +03:00
|
|
|
|
|
|
|
// Create a script to clean the modules.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!provides.empty()) {
|
2007-12-28 19:50:14 +03:00
|
|
|
std::string fcName = this->TargetDirectory;
|
|
|
|
fcName += "/cmake_clean_Fortran.cmake";
|
|
|
|
cmGeneratedFileStream fcStream(fcName.c_str());
|
|
|
|
fcStream << "# Remove fortran modules provided by this target.\n";
|
2007-12-31 00:11:38 +03:00
|
|
|
fcStream << "FILE(REMOVE";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = provides.begin();
|
|
|
|
i != provides.end(); ++i) {
|
2007-12-31 00:11:38 +03:00
|
|
|
std::string mod_upper = mod_dir;
|
|
|
|
mod_upper += "/";
|
|
|
|
mod_upper += cmSystemTools::UpperCase(*i);
|
|
|
|
mod_upper += ".mod";
|
|
|
|
std::string mod_lower = mod_dir;
|
|
|
|
mod_lower += "/";
|
|
|
|
mod_lower += *i;
|
|
|
|
mod_lower += ".mod";
|
|
|
|
std::string stamp = stamp_dir;
|
|
|
|
stamp += "/";
|
|
|
|
stamp += *i;
|
|
|
|
stamp += ".mod.stamp";
|
|
|
|
fcStream << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
fcStream << " \""
|
2016-08-27 14:44:56 +03:00
|
|
|
<< this->LocalGenerator->ConvertToRelativePath(
|
2016-05-20 00:11:40 +03:00
|
|
|
mod_lower, cmOutputConverter::START_OUTPUT)
|
2007-12-31 00:11:38 +03:00
|
|
|
<< "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
fcStream << " \""
|
2016-08-27 14:44:56 +03:00
|
|
|
<< this->LocalGenerator->ConvertToRelativePath(
|
2016-05-20 00:11:40 +03:00
|
|
|
mod_upper, cmOutputConverter::START_OUTPUT)
|
2007-12-31 00:11:38 +03:00
|
|
|
<< "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
fcStream << " \""
|
2016-08-27 14:44:56 +03:00
|
|
|
<< this->LocalGenerator->ConvertToRelativePath(
|
2016-05-20 00:11:40 +03:00
|
|
|
stamp, cmOutputConverter::START_OUTPUT)
|
2007-12-31 00:11:38 +03:00
|
|
|
<< "\"\n";
|
2007-12-28 19:50:14 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fcStream << " )\n";
|
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsFortran::LocateModules()
|
|
|
|
{
|
|
|
|
// Collect the set of modules provided and required by all sources.
|
|
|
|
typedef cmDependsFortranInternals::ObjectInfoMap ObjectInfoMap;
|
|
|
|
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (ObjectInfoMap::const_iterator infoI = objInfo.begin();
|
|
|
|
infoI != objInfo.end(); ++infoI) {
|
2015-07-22 20:21:45 +03:00
|
|
|
cmFortranSourceInfo const& info = infoI->second;
|
2014-11-25 18:33:00 +03:00
|
|
|
// Include this module in the set provided by this target.
|
|
|
|
this->Internal->TargetProvides.insert(info.Provides.begin(),
|
|
|
|
info.Provides.end());
|
2007-12-28 19:49:59 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = info.Requires.begin();
|
|
|
|
i != info.Requires.end(); ++i) {
|
2007-12-28 19:49:59 +03:00
|
|
|
this->Internal->TargetRequires[*i] = "";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
|
|
|
// Short-circuit for simple targets.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Internal->TargetRequires.empty()) {
|
2007-12-28 19:49:59 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
|
|
|
// Match modules provided by this target to those it requires.
|
|
|
|
this->MatchLocalModules();
|
|
|
|
|
|
|
|
// Load information about other targets.
|
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
|
|
|
std::vector<std::string> infoFiles;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* infoFilesValue =
|
|
|
|
mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES")) {
|
2007-12-28 19:49:59 +03:00
|
|
|
cmSystemTools::ExpandListArgument(infoFilesValue, infoFiles);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator i = infoFiles.begin();
|
|
|
|
i != infoFiles.end(); ++i) {
|
2007-12-28 19:49:59 +03:00
|
|
|
std::string targetDir = cmSystemTools::GetFilenamePath(*i);
|
|
|
|
std::string fname = targetDir + "/fortran.internal";
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(fname.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (fin) {
|
2008-01-03 02:30:48 +03:00
|
|
|
this->MatchRemoteModules(fin, targetDir.c_str());
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsFortran::MatchLocalModules()
|
|
|
|
{
|
2008-01-03 02:30:48 +03:00
|
|
|
const char* stampDir = this->TargetDirectory.c_str();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> const& provides = this->Internal->TargetProvides;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = provides.begin();
|
|
|
|
i != provides.end(); ++i) {
|
2007-12-31 00:11:38 +03:00
|
|
|
this->ConsiderModule(i->c_str(), stampDir);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsFortran::MatchRemoteModules(std::istream& fin,
|
2007-12-31 00:11:38 +03:00
|
|
|
const char* stampDir)
|
2007-12-28 19:49:59 +03:00
|
|
|
{
|
|
|
|
std::string line;
|
2007-12-29 06:29:19 +03:00
|
|
|
bool doing_provides = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
2007-12-28 19:49:59 +03:00
|
|
|
// Ignore comments and empty lines.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (line.empty() || line[0] == '#' || line[0] == '\r') {
|
2007-12-28 19:49:59 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (line[0] == ' ') {
|
|
|
|
if (doing_provides) {
|
|
|
|
this->ConsiderModule(line.c_str() + 1, stampDir);
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (line == "provides") {
|
2007-12-28 19:49:59 +03:00
|
|
|
doing_provides = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-12-28 19:49:59 +03:00
|
|
|
doing_provides = false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmDependsFortran::ConsiderModule(const char* name, const char* stampDir)
|
2007-12-28 19:49:59 +03:00
|
|
|
{
|
|
|
|
// Locate each required module.
|
|
|
|
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
|
|
|
|
TargetRequiresMap::iterator required =
|
|
|
|
this->Internal->TargetRequires.find(name);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (required != this->Internal->TargetRequires.end() &&
|
|
|
|
required->second.empty()) {
|
2007-12-28 19:49:59 +03:00
|
|
|
// The module is provided by a CMake target. It will have a stamp file.
|
2007-12-31 00:11:38 +03:00
|
|
|
std::string stampFile = stampDir;
|
2007-12-28 19:49:59 +03:00
|
|
|
stampFile += "/";
|
|
|
|
stampFile += name;
|
|
|
|
stampFile += ".mod.stamp";
|
|
|
|
required->second = stampFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmDependsFortran::WriteDependenciesReal(const char* obj,
|
|
|
|
cmFortranSourceInfo const& info,
|
|
|
|
std::string const& mod_dir,
|
|
|
|
const char* stamp_dir,
|
|
|
|
std::ostream& makeDepends,
|
|
|
|
std::ostream& internalDepends)
|
2007-12-28 19:49:59 +03:00
|
|
|
{
|
|
|
|
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
|
|
|
|
|
|
|
|
// Get the source file for this object.
|
|
|
|
const char* src = info.Source.c_str();
|
|
|
|
|
2005-01-28 18:45:00 +03:00
|
|
|
// Write the include dependencies to the output stream.
|
2016-08-27 14:44:56 +03:00
|
|
|
std::string obj_i = this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
obj, cmOutputConverter::HOME_OUTPUT);
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string obj_m = this->LocalGenerator->ConvertToOutputFormat(
|
2016-05-20 00:11:40 +03:00
|
|
|
obj_i, cmOutputConverter::MAKERULE);
|
2014-07-22 20:50:37 +04:00
|
|
|
internalDepends << obj_i << std::endl;
|
2007-12-20 00:35:09 +03:00
|
|
|
internalDepends << " " << src << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = info.Includes.begin();
|
|
|
|
i != info.Includes.end(); ++i) {
|
|
|
|
makeDepends << obj_m << ": "
|
2016-05-20 00:11:40 +03:00
|
|
|
<< this->LocalGenerator->Convert(
|
|
|
|
*i, cmOutputConverter::HOME_OUTPUT,
|
|
|
|
cmOutputConverter::MAKERULE)
|
2010-01-04 18:18:44 +03:00
|
|
|
<< std::endl;
|
2014-03-11 16:35:32 +04:00
|
|
|
internalDepends << " " << *i << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-10-12 21:52:29 +04:00
|
|
|
makeDepends << std::endl;
|
2005-01-26 23:33:38 +03:00
|
|
|
|
2005-01-28 18:45:00 +03:00
|
|
|
// Write module requirements to the output stream.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = info.Requires.begin();
|
|
|
|
i != info.Requires.end(); ++i) {
|
2005-01-28 18:45:00 +03:00
|
|
|
// Require only modules not provided in the same source.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (std::set<std::string>::const_iterator(info.Provides.find(*i)) !=
|
|
|
|
info.Provides.end()) {
|
2007-12-28 19:49:59 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
|
|
|
// If the module is provided in this target special handling is
|
|
|
|
// needed.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Internal->TargetProvides.find(*i) !=
|
|
|
|
this->Internal->TargetProvides.end()) {
|
2007-12-28 19:49:59 +03:00
|
|
|
// The module is provided by a different source in the same
|
|
|
|
// target. Add the proxy dependency to make sure the other
|
|
|
|
// source builds first.
|
2007-12-31 00:11:38 +03:00
|
|
|
std::string proxy = stamp_dir;
|
2007-12-15 23:35:00 +03:00
|
|
|
proxy += "/";
|
|
|
|
proxy += *i;
|
|
|
|
proxy += ".mod.proxy";
|
2016-05-16 17:34:04 +03:00
|
|
|
proxy = this->LocalGenerator->Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
proxy, cmOutputConverter::HOME_OUTPUT, cmOutputConverter::MAKERULE);
|
2007-12-15 23:35:00 +03:00
|
|
|
|
2005-05-25 19:19:16 +04:00
|
|
|
// since we require some things add them to our list of requirements
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << obj_m << ".requires: " << proxy << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-10-12 17:51:28 +04:00
|
|
|
|
2007-12-28 19:49:59 +03:00
|
|
|
// The object file should depend on timestamped files for the
|
|
|
|
// modules it uses.
|
|
|
|
TargetRequiresMap::const_iterator required =
|
|
|
|
this->Internal->TargetRequires.find(*i);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (required == this->Internal->TargetRequires.end()) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (!required->second.empty()) {
|
2007-12-28 19:49:59 +03:00
|
|
|
// This module is known. Depend on its timestamp file.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string stampFile = this->LocalGenerator->Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
required->second, cmOutputConverter::HOME_OUTPUT,
|
|
|
|
cmOutputConverter::MAKERULE);
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << obj_m << ": " << stampFile << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-12-28 19:49:59 +03:00
|
|
|
// This module is not known to CMake. Try to locate it where
|
|
|
|
// the compiler will and depend on that.
|
|
|
|
std::string module;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->FindModule(*i, module)) {
|
|
|
|
module = this->LocalGenerator->Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
module, cmOutputConverter::HOME_OUTPUT, cmOutputConverter::MAKERULE);
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << obj_m << ": " << module << "\n";
|
2005-01-28 18:45:00 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-28 18:45:00 +03:00
|
|
|
|
|
|
|
// Write provided modules to the output stream.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = info.Provides.begin();
|
|
|
|
i != info.Provides.end(); ++i) {
|
2007-12-31 00:11:38 +03:00
|
|
|
std::string proxy = stamp_dir;
|
2007-12-15 23:35:00 +03:00
|
|
|
proxy += "/";
|
|
|
|
proxy += *i;
|
|
|
|
proxy += ".mod.proxy";
|
2016-05-20 00:11:40 +03:00
|
|
|
proxy = this->LocalGenerator->Convert(
|
|
|
|
proxy, cmOutputConverter::HOME_OUTPUT, cmOutputConverter::MAKERULE);
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << proxy << ": " << obj_m << ".provides" << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
2005-01-28 18:45:00 +03:00
|
|
|
// If any modules are provided then they must be converted to stamp files.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!info.Provides.empty()) {
|
2007-12-15 23:35:00 +03:00
|
|
|
// Create a target to copy the module after the object file
|
|
|
|
// changes.
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << obj_m << ".provides.build:\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator i = info.Provides.begin();
|
|
|
|
i != info.Provides.end(); ++i) {
|
2007-12-28 19:49:59 +03:00
|
|
|
// Include this module in the set provided by this target.
|
|
|
|
this->Internal->TargetProvides.insert(*i);
|
|
|
|
|
2005-03-04 00:53:33 +03:00
|
|
|
// Always use lower case for the mod stamp file name. The
|
|
|
|
// cmake_copy_f90_mod will call back to this class, which will
|
|
|
|
// try various cases for the real mod file name.
|
2005-03-01 21:36:07 +03:00
|
|
|
std::string m = cmSystemTools::LowerCase(*i);
|
2007-12-15 23:35:00 +03:00
|
|
|
std::string modFile = mod_dir;
|
|
|
|
modFile += "/";
|
|
|
|
modFile += *i;
|
2016-05-16 17:34:04 +03:00
|
|
|
modFile = this->LocalGenerator->Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
modFile, cmOutputConverter::HOME_OUTPUT, cmOutputConverter::SHELL);
|
2007-12-31 00:11:38 +03:00
|
|
|
std::string stampFile = stamp_dir;
|
2007-12-15 23:35:00 +03:00
|
|
|
stampFile += "/";
|
|
|
|
stampFile += m;
|
|
|
|
stampFile += ".mod.stamp";
|
2016-05-16 17:34:04 +03:00
|
|
|
stampFile = this->LocalGenerator->Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
stampFile, cmOutputConverter::HOME_OUTPUT, cmOutputConverter::SHELL);
|
2016-05-16 17:34:04 +03:00
|
|
|
makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod " << modFile
|
|
|
|
<< " " << stampFile;
|
2008-01-02 19:04:52 +03:00
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
|
|
|
const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cid && *cid) {
|
2008-01-02 19:04:52 +03:00
|
|
|
makeDepends << " " << cid;
|
2005-01-28 18:45:00 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
makeDepends << "\n";
|
|
|
|
}
|
2007-12-15 23:35:00 +03:00
|
|
|
// After copying the modules update the timestamp file so that
|
|
|
|
// copying will not be done again until the source rebuilds.
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << "\t$(CMAKE_COMMAND) -E touch " << obj_m
|
2007-12-05 17:17:07 +03:00
|
|
|
<< ".provides.build\n";
|
2007-12-15 23:35:00 +03:00
|
|
|
|
|
|
|
// Make sure the module timestamp rule is evaluated by the time
|
|
|
|
// the target finishes building.
|
2007-12-19 22:28:46 +03:00
|
|
|
std::string driver = this->TargetDirectory;
|
|
|
|
driver += "/build";
|
2016-05-16 17:34:04 +03:00
|
|
|
driver = this->LocalGenerator->Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
driver, cmOutputConverter::HOME_OUTPUT, cmOutputConverter::MAKERULE);
|
2014-07-22 20:50:37 +04:00
|
|
|
makeDepends << driver << ": " << obj_m << ".provides.build\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-28 18:45:00 +03:00
|
|
|
|
2005-01-26 23:33:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmDependsFortran::FindModule(std::string const& name, std::string& module)
|
2007-12-28 19:49:59 +03:00
|
|
|
{
|
|
|
|
// Construct possible names for the module file.
|
|
|
|
std::string mod_upper = cmSystemTools::UpperCase(name);
|
|
|
|
std::string mod_lower = name;
|
|
|
|
mod_upper += ".mod";
|
|
|
|
mod_lower += ".mod";
|
|
|
|
|
|
|
|
// Search the include path for the module.
|
|
|
|
std::string fullName;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i = this->IncludePath.begin();
|
|
|
|
i != this->IncludePath.end(); ++i) {
|
2007-12-28 19:49:59 +03:00
|
|
|
// Try the lower-case name.
|
|
|
|
fullName = *i;
|
|
|
|
fullName += "/";
|
|
|
|
fullName += mod_lower;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(fullName.c_str(), true)) {
|
2007-12-28 19:49:59 +03:00
|
|
|
module = fullName;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
|
|
|
|
// Try the upper-case name.
|
|
|
|
fullName = *i;
|
|
|
|
fullName += "/";
|
|
|
|
fullName += mod_upper;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(fullName.c_str(), true)) {
|
2007-12-28 19:49:59 +03:00
|
|
|
module = fullName;
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 19:49:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-03-04 00:53:33 +03:00
|
|
|
bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
// Implements
|
|
|
|
//
|
|
|
|
// $(CMAKE_COMMAND) -E cmake_copy_f90_mod input.mod output.mod.stamp
|
2008-01-02 19:04:52 +03:00
|
|
|
// [compiler-id]
|
2005-03-04 00:53:33 +03:00
|
|
|
//
|
|
|
|
// Note that the case of the .mod file depends on the compiler. In
|
|
|
|
// the future this copy could also account for the fact that some
|
|
|
|
// compilers include a timestamp in the .mod file so it changes even
|
|
|
|
// when the interface described in the module does not.
|
|
|
|
|
|
|
|
std::string mod = args[2];
|
|
|
|
std::string stamp = args[3];
|
2008-01-02 19:04:52 +03:00
|
|
|
std::string compilerId;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() >= 5) {
|
2008-01-02 19:04:52 +03:00
|
|
|
compilerId = args[4];
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-15 23:35:00 +03:00
|
|
|
std::string mod_dir = cmSystemTools::GetFilenamePath(mod);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!mod_dir.empty()) {
|
|
|
|
mod_dir += "/";
|
|
|
|
}
|
2007-12-15 23:35:00 +03:00
|
|
|
std::string mod_upper = mod_dir;
|
|
|
|
mod_upper += cmSystemTools::UpperCase(cmSystemTools::GetFilenameName(mod));
|
|
|
|
std::string mod_lower = mod_dir;
|
|
|
|
mod_lower += cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(mod));
|
2005-03-07 23:19:18 +03:00
|
|
|
mod += ".mod";
|
|
|
|
mod_upper += ".mod";
|
|
|
|
mod_lower += ".mod";
|
2016-05-16 17:34:04 +03:00
|
|
|
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";
|
2007-12-31 19:25:17 +03:00
|
|
|
return false;
|
2005-03-04 00:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
2016-08-18 21:36:29 +03:00
|
|
|
}
|
|
|
|
if (cmSystemTools::FileExists(mod_lower.c_str(), true)) {
|
2016-05-16 17:34:04 +03:00
|
|
|
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";
|
2007-12-31 19:25:17 +03:00
|
|
|
return false;
|
2005-03-04 00:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2005-03-04 00:53:33 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::cerr << "Error copying Fortran module \"" << args[2] << "\". Tried \""
|
|
|
|
<< mod_upper << "\" and \"" << mod_lower << "\".\n";
|
2005-03-04 00:53:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-07 19:36:17 +03:00
|
|
|
// 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.
|
2016-05-16 17:34:04 +03:00
|
|
|
static bool cmFortranStreamContainsSequence(std::istream& ifs, const char* seq,
|
|
|
|
int len)
|
2008-01-07 19:36:17 +03:00
|
|
|
{
|
|
|
|
assert(len > 0);
|
|
|
|
|
|
|
|
int cur = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cur < len) {
|
2008-01-07 19:36:17 +03:00
|
|
|
// Get the next character.
|
|
|
|
int token = ifs.get();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ifs) {
|
2008-01-07 19:36:17 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
|
|
|
// Check the character.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (token == static_cast<int>(seq[cur])) {
|
2008-01-07 19:36:17 +03:00
|
|
|
++cur;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-07 19:36:17 +03:00
|
|
|
// Assume the sequence has no repeating subsequence.
|
|
|
|
cur = 0;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
|
|
|
// The entire sequence was matched.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function to compare the remaining content in two streams.
|
2016-05-16 17:34:04 +03:00
|
|
|
static bool cmFortranStreamsDiffer(std::istream& ifs1, std::istream& ifs2)
|
2008-01-07 19:36:17 +03:00
|
|
|
{
|
|
|
|
// Compare the remaining content.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (;;) {
|
2008-01-07 19:36:17 +03:00
|
|
|
int ifs1_c = ifs1.get();
|
|
|
|
int ifs2_c = ifs2.get();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ifs1 && !ifs2) {
|
2008-01-07 19:36:17 +03:00
|
|
|
// We have reached the end of both streams simultaneously.
|
|
|
|
// The streams are identical.
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ifs1 || !ifs2 || ifs1_c != ifs2_c) {
|
2008-01-07 19:36:17 +03:00
|
|
|
// We have reached the end of one stream before the other or
|
|
|
|
// found differing content. The streams are different.
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-12-31 19:25:17 +03:00
|
|
|
bool cmDependsFortran::ModulesDiffer(const char* modFile,
|
2008-01-02 19:04:52 +03:00
|
|
|
const char* stampFile,
|
|
|
|
const char* compilerId)
|
2007-12-31 19:25:17 +03:00
|
|
|
{
|
|
|
|
/*
|
2014-06-19 17:11:29 +04:00
|
|
|
gnu >= 4.9:
|
|
|
|
A mod file is an ascii file compressed with gzip.
|
|
|
|
Compiling twice produces identical modules.
|
|
|
|
|
|
|
|
gnu < 4.9:
|
2007-12-31 19:25:17 +03:00
|
|
|
A mod file is an ascii file.
|
|
|
|
<bar.mod>
|
|
|
|
FORTRAN module created from /path/to/foo.f90 on Sun Dec 30 22:47:58 2007
|
|
|
|
If you edit this, you'll get what you deserve.
|
|
|
|
...
|
|
|
|
</bar.mod>
|
|
|
|
As you can see the first line contains the date.
|
|
|
|
|
|
|
|
intel:
|
|
|
|
A mod file is a binary file.
|
|
|
|
However, looking into both generated bar.mod files with a hex editor
|
2008-01-07 19:36:17 +03:00
|
|
|
shows that they differ only before a sequence linefeed-zero (0x0A 0x00)
|
|
|
|
which is located some bytes in front of the absoulte path to the source
|
|
|
|
file.
|
2007-12-31 19:25:17 +03:00
|
|
|
|
|
|
|
sun:
|
2008-01-07 19:36:17 +03:00
|
|
|
A mod file is a binary file. Compiling twice produces identical modules.
|
2007-12-31 19:25:17 +03:00
|
|
|
|
|
|
|
others:
|
2008-01-07 19:36:17 +03:00
|
|
|
TODO ...
|
2007-12-31 19:25:17 +03:00
|
|
|
*/
|
2008-01-07 19:36:17 +03:00
|
|
|
|
|
|
|
/* Compilers which do _not_ produce different mod content when the same
|
|
|
|
* source is compiled twice
|
|
|
|
* -SunPro
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strcmp(compilerId, "SunPro") == 0) {
|
2008-01-07 19:36:17 +03:00
|
|
|
return cmSystemTools::FilesDiffer(modFile, stampFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
2007-12-31 19:25:17 +03:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream finModFile(modFile, std::ios::in | std::ios::binary);
|
|
|
|
cmsys::ifstream finStampFile(stampFile, std::ios::in | std::ios::binary);
|
2007-12-31 19:25:17 +03:00
|
|
|
#else
|
2016-06-13 23:56:48 +03:00
|
|
|
cmsys::ifstream finModFile(modFile);
|
|
|
|
cmsys::ifstream finStampFile(stampFile);
|
2007-12-31 19:25:17 +03:00
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!finModFile || !finStampFile) {
|
2007-12-31 19:25:17 +03:00
|
|
|
// At least one of the files does not exist. The modules differ.
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-31 19:25:17 +03:00
|
|
|
|
2008-01-07 19:36:17 +03:00
|
|
|
/* Compilers which _do_ produce different mod content when the same
|
|
|
|
* source is compiled twice
|
|
|
|
* -GNU
|
|
|
|
* -Intel
|
|
|
|
*
|
2012-02-26 22:44:20 +04:00
|
|
|
* Eat the stream content until all recompile only related changes
|
|
|
|
* are left behind.
|
2008-01-07 19:36:17 +03:00
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strcmp(compilerId, "GNU") == 0) {
|
2014-06-19 17:11:29 +04:00
|
|
|
// 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];
|
2016-06-02 00:29:53 +03:00
|
|
|
bool okay = !finModFile.read(reinterpret_cast<char*>(hdr), 2).fail();
|
2014-06-19 17:11:29 +04:00
|
|
|
finModFile.seekg(0);
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!okay || hdr[0] != 0x1f || hdr[1] != 0x8b) {
|
2016-05-16 17:34:04 +03:00
|
|
|
const char seq[1] = { '\n' };
|
2014-06-19 17:11:29 +04:00
|
|
|
const int seqlen = 1;
|
2008-01-07 19:36:17 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmFortranStreamContainsSequence(finModFile, seq, seqlen)) {
|
2014-06-19 17:11:29 +04:00
|
|
|
// The module is of unexpected format. Assume it is different.
|
|
|
|
std::cerr << compilerId << " fortran module " << modFile
|
|
|
|
<< " has unexpected format." << std::endl;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-06-19 17:11:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmFortranStreamContainsSequence(finStampFile, seq, seqlen)) {
|
2014-06-19 17:11:29 +04:00
|
|
|
// The stamp must differ if the sequence is not contained.
|
|
|
|
return true;
|
2008-01-07 19:36:17 +03:00
|
|
|
}
|
2007-12-31 19:25:17 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(compilerId, "Intel") == 0) {
|
|
|
|
const char seq[2] = { '\n', '\0' };
|
2008-01-07 19:36:17 +03:00
|
|
|
const int seqlen = 2;
|
2007-12-31 19:25:17 +03:00
|
|
|
|
2016-08-24 18:51:59 +03:00
|
|
|
// Skip the leading byte which appears to be a version number.
|
|
|
|
// We do not need to check for an error because the sequence search
|
|
|
|
// below will fail in that case.
|
|
|
|
finModFile.get();
|
|
|
|
finStampFile.get();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmFortranStreamContainsSequence(finModFile, seq, seqlen)) {
|
2008-01-07 19:36:17 +03:00
|
|
|
// The module is of unexpected format. Assume it is different.
|
|
|
|
std::cerr << compilerId << " fortran module " << modFile
|
|
|
|
<< " has unexpected format." << std::endl;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmFortranStreamContainsSequence(finStampFile, seq, seqlen)) {
|
2008-01-07 19:36:17 +03:00
|
|
|
// The stamp must differ if the sequence is not contained.
|
|
|
|
return true;
|
2007-12-31 19:25:17 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-31 19:25:17 +03:00
|
|
|
|
2012-02-26 22:44:20 +04:00
|
|
|
// Compare the remaining content. If no compiler id matched above,
|
2008-01-07 19:36:17 +03:00
|
|
|
// including the case none was given, this will compare the whole
|
|
|
|
// content.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmFortranStreamsDiffer(finModFile, finStampFile)) {
|
2008-01-07 19:36:17 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-07 19:36:17 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// The modules are different.
|
|
|
|
return true;
|
2007-12-31 19:25:17 +03:00
|
|
|
}
|