2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2005-01-26 20:33:38 +00:00
|
|
|
#include "cmDependsFortran.h"
|
|
|
|
|
2019-09-06 20:58:06 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
2005-01-26 20:33:38 +00:00
|
|
|
|
2019-09-30 14:46:28 +00:00
|
|
|
#include "cmsys/FStream.hxx"
|
|
|
|
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmFortranParser.h" /* Interface to parser object. */
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmOutputConverter.h"
|
|
|
|
#include "cmStateDirectory.h"
|
|
|
|
#include "cmStateSnapshot.h"
|
2019-07-29 10:16:40 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2005-03-02 14:02:36 +00: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.
|
|
|
|
|
2018-04-18 17:56:01 +00:00
|
|
|
static void cmFortranModuleAppendUpperLower(std::string const& mod,
|
|
|
|
std::string& mod_upper,
|
|
|
|
std::string& mod_lower)
|
|
|
|
{
|
|
|
|
std::string::size_type ext_len = 0;
|
|
|
|
if (cmHasLiteralSuffix(mod, ".mod")) {
|
|
|
|
ext_len = 4;
|
2018-04-19 13:21:58 +00:00
|
|
|
} else if (cmHasLiteralSuffix(mod, ".smod")) {
|
|
|
|
ext_len = 5;
|
2020-01-15 19:04:32 +00:00
|
|
|
} else if (cmHasLiteralSuffix(mod, ".sub")) {
|
|
|
|
ext_len = 4;
|
2018-04-18 17:56:01 +00:00
|
|
|
}
|
|
|
|
std::string const& name = mod.substr(0, mod.size() - ext_len);
|
|
|
|
std::string const& ext = mod.substr(mod.size() - ext_len);
|
|
|
|
mod_upper += cmSystemTools::UpperCase(name) + ext;
|
|
|
|
mod_lower += mod;
|
|
|
|
}
|
|
|
|
|
2007-12-28 16:49:59 +00:00
|
|
|
class cmDependsFortranInternals
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The set of modules provided by this target.
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> TargetProvides;
|
2007-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
// Map modules required by this target to locations.
|
2019-09-04 16:03:01 +00:00
|
|
|
using TargetRequiresMap = std::map<std::string, std::string>;
|
2007-12-28 16:49:59 +00:00
|
|
|
TargetRequiresMap TargetRequires;
|
|
|
|
|
|
|
|
// Information about each object file.
|
2019-09-04 16:03:01 +00:00
|
|
|
using ObjectInfoMap = std::map<std::string, cmFortranSourceInfo>;
|
2007-12-28 16:49:59 +00:00
|
|
|
ObjectInfoMap ObjectInfo;
|
|
|
|
|
2019-01-19 01:20:00 +00:00
|
|
|
cmFortranSourceInfo& CreateObjectInfo(const std::string& obj,
|
|
|
|
const std::string& src)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
2019-09-04 20:17:22 +00:00
|
|
|
auto i = this->ObjectInfo.find(obj);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (i == this->ObjectInfo.end()) {
|
|
|
|
std::map<std::string, cmFortranSourceInfo>::value_type entry(
|
|
|
|
obj, cmFortranSourceInfo());
|
2007-12-28 16:49:59 +00:00
|
|
|
i = this->ObjectInfo.insert(entry).first;
|
|
|
|
i->second.Source = src;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return i->second;
|
|
|
|
}
|
2005-01-26 20:33:38 +00:00
|
|
|
};
|
|
|
|
|
2019-01-22 22:44:50 +00:00
|
|
|
cmDependsFortran::cmDependsFortran() = default;
|
2005-01-26 20:33:38 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg)
|
|
|
|
: cmDepends(lg)
|
|
|
|
, Internal(new cmDependsFortranInternals)
|
2005-01-26 20:33:38 +00:00
|
|
|
{
|
2009-02-24 19:32:25 +00:00
|
|
|
// Configure the include file search path.
|
|
|
|
this->SetIncludePathFromLanguage("Fortran");
|
|
|
|
|
2008-05-08 14:09:14 +00:00
|
|
|
// Get the list of definitions.
|
|
|
|
std::vector<std::string> definitions;
|
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (const char* c_defines =
|
|
|
|
mf->GetDefinition("CMAKE_TARGET_DEFINITIONS_Fortran")) {
|
2019-08-11 09:56:59 +00:00
|
|
|
cmExpandList(c_defines, definitions);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-05-08 14:09:14 +00:00
|
|
|
|
2008-01-18 00:58:01 +00:00
|
|
|
// translate i.e. FOO=BAR to FOO and add it to the list of defined
|
2008-01-09 15:30:11 +00:00
|
|
|
// preprocessor symbols
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string def : definitions) {
|
2016-05-24 19:24:10 +00:00
|
|
|
std::string::size_type assignment = def.find('=');
|
2016-05-16 14:34:04 +00:00
|
|
|
if (assignment != std::string::npos) {
|
2017-09-11 10:40:26 +00:00
|
|
|
def = def.substr(0, assignment);
|
2008-01-09 15:30:11 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
this->PPDefinitions.insert(def);
|
|
|
|
}
|
2019-02-13 18:34:56 +00:00
|
|
|
|
|
|
|
this->CompilerId = mf->GetSafeDefinition("CMAKE_Fortran_COMPILER_ID");
|
2019-02-13 19:08:34 +00:00
|
|
|
this->SModSep = mf->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_SEP");
|
|
|
|
this->SModExt = mf->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
|
2005-01-26 20:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmDependsFortran::~cmDependsFortran()
|
|
|
|
{
|
2007-12-28 16:49:59 +00:00
|
|
|
delete this->Internal;
|
2005-01-26 20:33:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmDependsFortran::WriteDependencies(const std::set<std::string>& sources,
|
2016-08-16 23:49:57 +00:00
|
|
|
const std::string& obj,
|
|
|
|
std::ostream& /*makeDepends*/,
|
|
|
|
std::ostream& /*internalDepends*/)
|
2005-01-26 20:33:38 +00:00
|
|
|
{
|
|
|
|
// Make sure this is a scanning instance.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (sources.empty() || sources.begin()->empty()) {
|
2012-09-30 15:53:01 +00:00
|
|
|
cmSystemTools::Error("Cannot scan dependencies without a source file.");
|
2005-01-26 20:33:38 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (obj.empty()) {
|
2005-07-27 13:49:37 +00:00
|
|
|
cmSystemTools::Error("Cannot scan dependencies without an object file.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-01-26 20:33:38 +00:00
|
|
|
|
2019-02-13 18:34:56 +00:00
|
|
|
cmFortranCompiler fc;
|
|
|
|
fc.Id = this->CompilerId;
|
2019-02-13 19:08:34 +00:00
|
|
|
fc.SModSep = this->SModSep;
|
|
|
|
fc.SModExt = this->SModExt;
|
2019-02-13 18:34:56 +00:00
|
|
|
|
2012-09-30 15:53:01 +00:00
|
|
|
bool okay = true;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& src : sources) {
|
2012-09-30 15:53:01 +00:00
|
|
|
// Get the information object for this source.
|
2019-01-19 01:20:00 +00:00
|
|
|
cmFortranSourceInfo& info = this->Internal->CreateObjectInfo(obj, src);
|
2007-10-12 13:51:28 +00:00
|
|
|
|
2015-07-22 17:45:28 +00:00
|
|
|
// Create the parser object. The constructor takes info by reference,
|
|
|
|
// so we may look into the resulting objects later.
|
2019-02-13 18:34:56 +00:00
|
|
|
cmFortranParser parser(fc, this->IncludePath, this->PPDefinitions, info);
|
2005-01-26 20:33:38 +00:00
|
|
|
|
2012-09-30 15:53:01 +00:00
|
|
|
// Push on the starting file.
|
2015-07-22 17:21:45 +00:00
|
|
|
cmFortranParser_FilePush(&parser, src.c_str());
|
2005-01-26 20:33:38 +00:00
|
|
|
|
2012-09-30 15:53:01 +00:00
|
|
|
// Parse the translation unit.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmFortran_yyparse(parser.Scanner) != 0) {
|
2012-09-30 15:53:01 +00:00
|
|
|
// Failed to parse the file. Report failure to write dependencies.
|
|
|
|
okay = false;
|
2016-09-05 18:50:31 +00: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 20:33:38 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-09-30 15:53:01 +00:00
|
|
|
return okay;
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmDependsFortran::Finalize(std::ostream& makeDepends,
|
|
|
|
std::ostream& internalDepends)
|
|
|
|
{
|
|
|
|
// Prepare the module search process.
|
|
|
|
this->LocateModules();
|
|
|
|
|
2007-12-30 21:11:38 +00:00
|
|
|
// Get the directory in which stamp files will be stored.
|
2019-01-19 01:20:00 +00:00
|
|
|
const std::string& stamp_dir = this->TargetDirectory;
|
2007-12-30 21:11:38 +00:00
|
|
|
|
|
|
|
// Get the directory in which module files will be created.
|
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
2015-07-29 15:44:25 +00:00
|
|
|
std::string mod_dir =
|
|
|
|
mf->GetSafeDefinition("CMAKE_Fortran_TARGET_MODULE_DIR");
|
2016-05-16 14:34:04 +00:00
|
|
|
if (mod_dir.empty()) {
|
|
|
|
mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
|
|
|
|
}
|
2007-12-30 21:11:38 +00:00
|
|
|
|
2007-12-28 16:49:59 +00:00
|
|
|
// Actually write dependencies to the streams.
|
2019-08-23 21:25:56 +00:00
|
|
|
using ObjectInfoMap = cmDependsFortranInternals::ObjectInfoMap;
|
2007-12-28 16:49:59 +00:00
|
|
|
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (auto const& i : objInfo) {
|
2019-01-19 01:20:00 +00:00
|
|
|
if (!this->WriteDependenciesReal(i.first, i.second, mod_dir, stamp_dir,
|
|
|
|
makeDepends, internalDepends)) {
|
2007-12-28 16:49:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
// Store the list of modules provided by this target.
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string fiName = cmStrCat(this->TargetDirectory, "/fortran.internal");
|
2018-08-07 13:01:25 +00:00
|
|
|
cmGeneratedFileStream fiStream(fiName);
|
2007-12-28 16:49:59 +00:00
|
|
|
fiStream << "# The fortran modules provided by this target.\n";
|
|
|
|
fiStream << "provides\n";
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> const& provides = this->Internal->TargetProvides;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : provides) {
|
|
|
|
fiStream << " " << i << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:50:14 +00:00
|
|
|
|
|
|
|
// Create a script to clean the modules.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!provides.empty()) {
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string fcName =
|
|
|
|
cmStrCat(this->TargetDirectory, "/cmake_clean_Fortran.cmake");
|
2018-08-07 13:01:25 +00:00
|
|
|
cmGeneratedFileStream fcStream(fcName);
|
2007-12-28 16:50:14 +00:00
|
|
|
fcStream << "# Remove fortran modules provided by this target.\n";
|
2007-12-30 21:11:38 +00:00
|
|
|
fcStream << "FILE(REMOVE";
|
2016-09-06 21:52:42 +00:00
|
|
|
std::string currentBinDir =
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory();
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : provides) {
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string mod_upper = cmStrCat(mod_dir, '/');
|
|
|
|
std::string mod_lower = cmStrCat(mod_dir, '/');
|
2018-04-18 17:56:01 +00:00
|
|
|
cmFortranModuleAppendUpperLower(i, mod_upper, mod_lower);
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string stamp = cmStrCat(stamp_dir, '/', i, ".stamp");
|
2007-12-30 21:11:38 +00:00
|
|
|
fcStream << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
fcStream << " \""
|
2016-10-04 20:56:31 +00:00
|
|
|
<< this->MaybeConvertToRelativePath(currentBinDir, mod_lower)
|
2007-12-30 21:11:38 +00:00
|
|
|
<< "\"\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
fcStream << " \""
|
2016-10-04 20:56:31 +00:00
|
|
|
<< this->MaybeConvertToRelativePath(currentBinDir, mod_upper)
|
2007-12-30 21:11:38 +00:00
|
|
|
<< "\"\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
fcStream << " \""
|
2016-10-04 20:56:31 +00:00
|
|
|
<< this->MaybeConvertToRelativePath(currentBinDir, stamp)
|
2007-12-30 21:11:38 +00:00
|
|
|
<< "\"\n";
|
2007-12-28 16:50:14 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
fcStream << " )\n";
|
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsFortran::LocateModules()
|
|
|
|
{
|
|
|
|
// Collect the set of modules provided and required by all sources.
|
2019-08-23 21:25:56 +00:00
|
|
|
using ObjectInfoMap = cmDependsFortranInternals::ObjectInfoMap;
|
2007-12-28 16:49:59 +00:00
|
|
|
ObjectInfoMap const& objInfo = this->Internal->ObjectInfo;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (auto const& infoI : objInfo) {
|
|
|
|
cmFortranSourceInfo const& info = infoI.second;
|
2014-11-25 15:33:00 +00:00
|
|
|
// Include this module in the set provided by this target.
|
|
|
|
this->Internal->TargetProvides.insert(info.Provides.begin(),
|
|
|
|
info.Provides.end());
|
2007-12-28 16:49:59 +00:00
|
|
|
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& r : info.Requires) {
|
2017-09-15 23:26:49 +00:00
|
|
|
this->Internal->TargetRequires[r].clear();
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
// Short-circuit for simple targets.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Internal->TargetRequires.empty()) {
|
2007-12-28 16:49:59 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00: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 14:34:04 +00:00
|
|
|
if (const char* infoFilesValue =
|
|
|
|
mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES")) {
|
2019-08-11 09:56:59 +00:00
|
|
|
cmExpandList(infoFilesValue, infoFiles);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : infoFiles) {
|
|
|
|
std::string targetDir = cmSystemTools::GetFilenamePath(i);
|
2007-12-28 16:49:59 +00:00
|
|
|
std::string fname = targetDir + "/fortran.internal";
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin(fname.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (fin) {
|
2019-01-19 01:20:00 +00:00
|
|
|
this->MatchRemoteModules(fin, targetDir);
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsFortran::MatchLocalModules()
|
|
|
|
{
|
2019-01-19 01:20:00 +00:00
|
|
|
std::string const& stampDir = this->TargetDirectory;
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> const& provides = this->Internal->TargetProvides;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : provides) {
|
2019-01-19 01:20:00 +00:00
|
|
|
this->ConsiderModule(i, stampDir);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmDependsFortran::MatchRemoteModules(std::istream& fin,
|
2019-01-19 01:20:00 +00:00
|
|
|
const std::string& stampDir)
|
2007-12-28 16:49:59 +00:00
|
|
|
{
|
|
|
|
std::string line;
|
2007-12-29 03:29:19 +00:00
|
|
|
bool doing_provides = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
2007-12-28 16:49:59 +00:00
|
|
|
// Ignore comments and empty lines.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (line.empty() || line[0] == '#' || line[0] == '\r') {
|
2007-12-28 16:49:59 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (line[0] == ' ') {
|
|
|
|
if (doing_provides) {
|
2018-04-18 17:56:01 +00:00
|
|
|
std::string mod = line;
|
2018-04-19 13:21:58 +00:00
|
|
|
if (!cmHasLiteralSuffix(mod, ".mod") &&
|
2020-01-15 19:04:32 +00:00
|
|
|
!cmHasLiteralSuffix(mod, ".smod") &&
|
|
|
|
!cmHasLiteralSuffix(mod, ".sub")) {
|
2018-04-18 17:56:01 +00:00
|
|
|
// Support fortran.internal files left by older versions of CMake.
|
|
|
|
// They do not include the ".mod" extension.
|
|
|
|
mod += ".mod";
|
|
|
|
}
|
2019-03-30 15:11:21 +00:00
|
|
|
this->ConsiderModule(mod.substr(1), stampDir);
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (line == "provides") {
|
2007-12-28 16:49:59 +00:00
|
|
|
doing_provides = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-12-28 16:49:59 +00:00
|
|
|
doing_provides = false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-19 01:20:00 +00:00
|
|
|
void cmDependsFortran::ConsiderModule(const std::string& name,
|
|
|
|
const std::string& stampDir)
|
2007-12-28 16:49:59 +00:00
|
|
|
{
|
|
|
|
// Locate each required module.
|
2019-09-04 20:17:22 +00:00
|
|
|
auto required = this->Internal->TargetRequires.find(name);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (required != this->Internal->TargetRequires.end() &&
|
|
|
|
required->second.empty()) {
|
2007-12-28 16:49:59 +00:00
|
|
|
// The module is provided by a CMake target. It will have a stamp file.
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string stampFile = cmStrCat(stampDir, '/', name, ".stamp");
|
2007-12-28 16:49:59 +00:00
|
|
|
required->second = stampFile;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-19 01:20:00 +00:00
|
|
|
bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
|
2016-05-16 14:34:04 +00:00
|
|
|
cmFortranSourceInfo const& info,
|
|
|
|
std::string const& mod_dir,
|
2019-01-19 01:20:00 +00:00
|
|
|
std::string const& stamp_dir,
|
2016-05-16 14:34:04 +00:00
|
|
|
std::ostream& makeDepends,
|
|
|
|
std::ostream& internalDepends)
|
2007-12-28 16:49:59 +00:00
|
|
|
{
|
|
|
|
// Get the source file for this object.
|
2019-01-19 01:20:00 +00:00
|
|
|
std::string const& src = info.Source;
|
2007-12-28 16:49:59 +00:00
|
|
|
|
2005-01-28 15:45:00 +00:00
|
|
|
// Write the include dependencies to the output stream.
|
2016-09-07 21:14:30 +00:00
|
|
|
std::string binDir = this->LocalGenerator->GetBinaryDirectory();
|
2016-10-04 20:56:31 +00:00
|
|
|
std::string obj_i = this->MaybeConvertToRelativePath(binDir, obj);
|
2018-01-31 15:20:02 +00:00
|
|
|
std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i);
|
2014-07-22 16:50:37 +00:00
|
|
|
internalDepends << obj_i << std::endl;
|
2007-12-19 21:35:09 +00:00
|
|
|
internalDepends << " " << src << std::endl;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : info.Includes) {
|
2016-10-04 20:56:31 +00:00
|
|
|
makeDepends << obj_m << ": "
|
|
|
|
<< cmSystemTools::ConvertToOutputPath(
|
2018-01-31 15:20:02 +00:00
|
|
|
this->MaybeConvertToRelativePath(binDir, i))
|
2016-10-04 20:56:31 +00:00
|
|
|
<< std::endl;
|
2017-09-11 10:40:26 +00:00
|
|
|
internalDepends << " " << i << std::endl;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-10-12 17:52:29 +00:00
|
|
|
makeDepends << std::endl;
|
2005-01-26 20:33:38 +00:00
|
|
|
|
2005-01-28 15:45:00 +00:00
|
|
|
// Write module requirements to the output stream.
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : info.Requires) {
|
2005-01-28 15:45:00 +00:00
|
|
|
// Require only modules not provided in the same source.
|
2017-09-11 10:40:26 +00:00
|
|
|
if (info.Provides.find(i) != info.Provides.cend()) {
|
2007-12-28 16:49:59 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
// The object file should depend on timestamped files for the
|
|
|
|
// modules it uses.
|
2019-09-04 20:17:22 +00:00
|
|
|
auto required = this->Internal->TargetRequires.find(i);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (required == this->Internal->TargetRequires.end()) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (!required->second.empty()) {
|
2007-12-28 16:49:59 +00:00
|
|
|
// This module is known. Depend on its timestamp file.
|
2016-08-27 16:09:04 +00:00
|
|
|
std::string stampFile = cmSystemTools::ConvertToOutputPath(
|
2018-01-31 15:20:02 +00:00
|
|
|
this->MaybeConvertToRelativePath(binDir, required->second));
|
2014-07-22 16:50:37 +00:00
|
|
|
makeDepends << obj_m << ": " << stampFile << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-12-28 16:49:59 +00:00
|
|
|
// This module is not known to CMake. Try to locate it where
|
|
|
|
// the compiler will and depend on that.
|
|
|
|
std::string module;
|
2017-09-11 10:40:26 +00:00
|
|
|
if (this->FindModule(i, module)) {
|
2016-08-27 16:09:04 +00:00
|
|
|
module = cmSystemTools::ConvertToOutputPath(
|
2018-01-31 15:20:02 +00:00
|
|
|
this->MaybeConvertToRelativePath(binDir, module));
|
2014-07-22 16:50:37 +00:00
|
|
|
makeDepends << obj_m << ": " << module << "\n";
|
2005-01-28 15:45:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-01-28 15:45:00 +00:00
|
|
|
|
|
|
|
// If any modules are provided then they must be converted to stamp files.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!info.Provides.empty()) {
|
2007-12-15 20:35:00 +00:00
|
|
|
// Create a target to copy the module after the object file
|
|
|
|
// changes.
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : info.Provides) {
|
2007-12-28 16:49:59 +00:00
|
|
|
// Include this module in the set provided by this target.
|
2017-09-11 10:40:26 +00:00
|
|
|
this->Internal->TargetProvides.insert(i);
|
2007-12-28 16:49:59 +00:00
|
|
|
|
2005-03-03 21:53:33 +00: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.
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string modFile = cmStrCat(mod_dir, '/', i);
|
2016-08-27 16:20:37 +00:00
|
|
|
modFile = this->LocalGenerator->ConvertToOutputFormat(
|
2016-10-04 20:56:31 +00:00
|
|
|
this->MaybeConvertToRelativePath(binDir, modFile),
|
2016-08-27 16:20:37 +00:00
|
|
|
cmOutputConverter::SHELL);
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string stampFile = cmStrCat(stamp_dir, '/', i, ".stamp");
|
2017-11-24 12:01:18 +00:00
|
|
|
stampFile = this->MaybeConvertToRelativePath(binDir, stampFile);
|
|
|
|
std::string const stampFileForShell =
|
|
|
|
this->LocalGenerator->ConvertToOutputFormat(stampFile,
|
|
|
|
cmOutputConverter::SHELL);
|
|
|
|
std::string const stampFileForMake =
|
2018-01-31 15:20:02 +00:00
|
|
|
cmSystemTools::ConvertToOutputPath(stampFile);
|
2017-11-24 12:01:18 +00:00
|
|
|
|
|
|
|
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";
|
2016-05-16 14:34:04 +00:00
|
|
|
makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod " << modFile
|
2017-11-24 12:01:18 +00:00
|
|
|
<< " " << stampFileForShell;
|
2008-01-02 16:04:52 +00:00
|
|
|
cmMakefile* mf = this->LocalGenerator->GetMakefile();
|
|
|
|
const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cid && *cid) {
|
2008-01-02 16:04:52 +00:00
|
|
|
makeDepends << " " << cid;
|
2005-01-28 15:45:00 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
makeDepends << "\n";
|
|
|
|
}
|
2017-11-24 12:01:18 +00:00
|
|
|
makeDepends << obj_m << ".provides.build:\n";
|
2017-12-05 12:41:59 +00:00
|
|
|
// After copying the modules update the timestamp file.
|
2014-07-22 16:50:37 +00:00
|
|
|
makeDepends << "\t$(CMAKE_COMMAND) -E touch " << obj_m
|
2007-12-05 14:17:07 +00:00
|
|
|
<< ".provides.build\n";
|
2007-12-15 20:35:00 +00:00
|
|
|
|
|
|
|
// Make sure the module timestamp rule is evaluated by the time
|
|
|
|
// the target finishes building.
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string driver = cmStrCat(this->TargetDirectory, "/build");
|
2016-08-27 16:09:04 +00:00
|
|
|
driver = cmSystemTools::ConvertToOutputPath(
|
2018-01-31 15:20:02 +00:00
|
|
|
this->MaybeConvertToRelativePath(binDir, driver));
|
2014-07-22 16:50:37 +00:00
|
|
|
makeDepends << driver << ": " << obj_m << ".provides.build\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-01-28 15:45:00 +00:00
|
|
|
|
2005-01-26 20:33:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmDependsFortran::FindModule(std::string const& name, std::string& module)
|
2007-12-28 16:49:59 +00:00
|
|
|
{
|
|
|
|
// Construct possible names for the module file.
|
2018-04-18 17:56:01 +00:00
|
|
|
std::string mod_upper;
|
|
|
|
std::string mod_lower;
|
|
|
|
cmFortranModuleAppendUpperLower(name, mod_upper, mod_lower);
|
2007-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
// Search the include path for the module.
|
|
|
|
std::string fullName;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& ip : this->IncludePath) {
|
2007-12-28 16:49:59 +00:00
|
|
|
// Try the lower-case name.
|
2019-08-22 14:34:40 +00:00
|
|
|
fullName = cmStrCat(ip, '/', mod_lower);
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(fullName, true)) {
|
2007-12-28 16:49:59 +00:00
|
|
|
module = fullName;
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
// Try the upper-case name.
|
2019-08-22 14:34:40 +00:00
|
|
|
fullName = cmStrCat(ip, '/', mod_upper);
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(fullName, true)) {
|
2007-12-28 16:49:59 +00:00
|
|
|
module = fullName;
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-28 16:49:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-03-03 21:53:33 +00: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 16:04:52 +00:00
|
|
|
// [compiler-id]
|
2005-03-03 21:53:33 +00: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 16:04:52 +00:00
|
|
|
std::string compilerId;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() >= 5) {
|
2008-01-02 16:04:52 +00:00
|
|
|
compilerId = args[4];
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2020-01-15 19:04:32 +00:00
|
|
|
if (!cmHasLiteralSuffix(mod, ".mod") && !cmHasLiteralSuffix(mod, ".smod") &&
|
|
|
|
!cmHasLiteralSuffix(mod, ".sub")) {
|
2018-04-18 17:56:01 +00:00
|
|
|
// Support depend.make files left by older versions of CMake.
|
|
|
|
// They do not include the ".mod" extension.
|
|
|
|
mod += ".mod";
|
|
|
|
}
|
2007-12-15 20:35:00 +00:00
|
|
|
std::string mod_dir = cmSystemTools::GetFilenamePath(mod);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!mod_dir.empty()) {
|
|
|
|
mod_dir += "/";
|
|
|
|
}
|
2007-12-15 20:35:00 +00:00
|
|
|
std::string mod_upper = mod_dir;
|
|
|
|
std::string mod_lower = mod_dir;
|
2018-04-18 17:56:01 +00:00
|
|
|
cmFortranModuleAppendUpperLower(cmSystemTools::GetFilenameName(mod),
|
|
|
|
mod_upper, mod_lower);
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(mod_upper, true)) {
|
2019-01-19 01:20:00 +00:00
|
|
|
if (cmDependsFortran::ModulesDiffer(mod_upper, stamp, compilerId)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::CopyFileAlways(mod_upper, stamp)) {
|
|
|
|
std::cerr << "Error copying Fortran module from \"" << mod_upper
|
|
|
|
<< "\" to \"" << stamp << "\".\n";
|
2007-12-31 16:25:17 +00:00
|
|
|
return false;
|
2005-03-03 21:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return true;
|
2016-08-18 18:36:29 +00:00
|
|
|
}
|
2018-01-31 15:20:02 +00:00
|
|
|
if (cmSystemTools::FileExists(mod_lower, true)) {
|
2019-01-19 01:20:00 +00:00
|
|
|
if (cmDependsFortran::ModulesDiffer(mod_lower, stamp, compilerId)) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::CopyFileAlways(mod_lower, stamp)) {
|
|
|
|
std::cerr << "Error copying Fortran module from \"" << mod_lower
|
|
|
|
<< "\" to \"" << stamp << "\".\n";
|
2007-12-31 16:25:17 +00:00
|
|
|
return false;
|
2005-03-03 21:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-03-03 21:53:33 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::cerr << "Error copying Fortran module \"" << args[2] << "\". Tried \""
|
|
|
|
<< mod_upper << "\" and \"" << mod_lower << "\".\n";
|
2005-03-03 21:53:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-07 16:36:17 +00: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 14:34:04 +00:00
|
|
|
static bool cmFortranStreamContainsSequence(std::istream& ifs, const char* seq,
|
|
|
|
int len)
|
2008-01-07 16:36:17 +00:00
|
|
|
{
|
|
|
|
assert(len > 0);
|
|
|
|
|
|
|
|
int cur = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (cur < len) {
|
2008-01-07 16:36:17 +00:00
|
|
|
// Get the next character.
|
|
|
|
int token = ifs.get();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifs) {
|
2008-01-07 16:36:17 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-07 16:36:17 +00:00
|
|
|
|
|
|
|
// Check the character.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (token == static_cast<int>(seq[cur])) {
|
2008-01-07 16:36:17 +00:00
|
|
|
++cur;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2008-01-07 16:36:17 +00:00
|
|
|
// Assume the sequence has no repeating subsequence.
|
|
|
|
cur = 0;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-07 16:36:17 +00:00
|
|
|
|
|
|
|
// The entire sequence was matched.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function to compare the remaining content in two streams.
|
2016-05-16 14:34:04 +00:00
|
|
|
static bool cmFortranStreamsDiffer(std::istream& ifs1, std::istream& ifs2)
|
2008-01-07 16:36:17 +00:00
|
|
|
{
|
|
|
|
// Compare the remaining content.
|
2016-05-16 14:34:04 +00:00
|
|
|
for (;;) {
|
2008-01-07 16:36:17 +00:00
|
|
|
int ifs1_c = ifs1.get();
|
|
|
|
int ifs2_c = ifs2.get();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifs1 && !ifs2) {
|
2008-01-07 16:36:17 +00:00
|
|
|
// We have reached the end of both streams simultaneously.
|
|
|
|
// The streams are identical.
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-07 16:36:17 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ifs1 || !ifs2 || ifs1_c != ifs2_c) {
|
2008-01-07 16:36:17 +00:00
|
|
|
// We have reached the end of one stream before the other or
|
|
|
|
// found differing content. The streams are different.
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-07 16:36:17 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-19 01:20:00 +00:00
|
|
|
bool cmDependsFortran::ModulesDiffer(const std::string& modFile,
|
|
|
|
const std::string& stampFile,
|
|
|
|
const std::string& compilerId)
|
2007-12-31 16:25:17 +00:00
|
|
|
{
|
|
|
|
/*
|
2014-06-19 13:11:29 +00: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 16:25:17 +00: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 16:36:17 +00:00
|
|
|
shows that they differ only before a sequence linefeed-zero (0x0A 0x00)
|
2018-01-03 12:09:54 +00:00
|
|
|
which is located some bytes in front of the absolute path to the source
|
2008-01-07 16:36:17 +00:00
|
|
|
file.
|
2007-12-31 16:25:17 +00:00
|
|
|
|
|
|
|
sun:
|
2008-01-07 16:36:17 +00:00
|
|
|
A mod file is a binary file. Compiling twice produces identical modules.
|
2007-12-31 16:25:17 +00:00
|
|
|
|
|
|
|
others:
|
2008-01-07 16:36:17 +00:00
|
|
|
TODO ...
|
2007-12-31 16:25:17 +00:00
|
|
|
*/
|
2008-01-07 16:36:17 +00:00
|
|
|
|
|
|
|
/* Compilers which do _not_ produce different mod content when the same
|
|
|
|
* source is compiled twice
|
|
|
|
* -SunPro
|
|
|
|
*/
|
2019-01-19 01:20:00 +00:00
|
|
|
if (compilerId == "SunPro") {
|
2008-01-07 16:36:17 +00:00
|
|
|
return cmSystemTools::FilesDiffer(modFile, stampFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-07 16:36:17 +00:00
|
|
|
|
2007-12-31 16:25:17 +00:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
2019-01-19 01:20:00 +00:00
|
|
|
cmsys::ifstream finModFile(modFile.c_str(), std::ios::in | std::ios::binary);
|
|
|
|
cmsys::ifstream finStampFile(stampFile.c_str(),
|
|
|
|
std::ios::in | std::ios::binary);
|
2007-12-31 16:25:17 +00:00
|
|
|
#else
|
2019-01-19 01:20:00 +00:00
|
|
|
cmsys::ifstream finModFile(modFile.c_str());
|
|
|
|
cmsys::ifstream finStampFile(stampFile.c_str());
|
2007-12-31 16:25:17 +00:00
|
|
|
#endif
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!finModFile || !finStampFile) {
|
2007-12-31 16:25:17 +00:00
|
|
|
// At least one of the files does not exist. The modules differ.
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-31 16:25:17 +00:00
|
|
|
|
2008-01-07 16:36:17 +00:00
|
|
|
/* Compilers which _do_ produce different mod content when the same
|
|
|
|
* source is compiled twice
|
|
|
|
* -GNU
|
|
|
|
* -Intel
|
|
|
|
*
|
2012-02-26 18:44:20 +00:00
|
|
|
* Eat the stream content until all recompile only related changes
|
|
|
|
* are left behind.
|
2008-01-07 16:36:17 +00:00
|
|
|
*/
|
2019-01-19 01:20:00 +00:00
|
|
|
if (compilerId == "GNU") {
|
2014-06-19 13:11:29 +00: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-01 21:29:53 +00:00
|
|
|
bool okay = !finModFile.read(reinterpret_cast<char*>(hdr), 2).fail();
|
2014-06-19 13:11:29 +00:00
|
|
|
finModFile.seekg(0);
|
2016-06-01 21:29:53 +00:00
|
|
|
if (!okay || hdr[0] != 0x1f || hdr[1] != 0x8b) {
|
2016-05-16 14:34:04 +00:00
|
|
|
const char seq[1] = { '\n' };
|
2014-06-19 13:11:29 +00:00
|
|
|
const int seqlen = 1;
|
2008-01-07 16:36:17 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmFortranStreamContainsSequence(finModFile, seq, seqlen)) {
|
2014-06-19 13:11:29 +00: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 14:34:04 +00:00
|
|
|
}
|
2014-06-19 13:11:29 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmFortranStreamContainsSequence(finStampFile, seq, seqlen)) {
|
2014-06-19 13:11:29 +00:00
|
|
|
// The stamp must differ if the sequence is not contained.
|
|
|
|
return true;
|
2008-01-07 16:36:17 +00:00
|
|
|
}
|
2007-12-31 16:25:17 +00:00
|
|
|
}
|
2019-01-19 01:20:00 +00:00
|
|
|
} else if (compilerId == "Intel") {
|
2016-05-16 14:34:04 +00:00
|
|
|
const char seq[2] = { '\n', '\0' };
|
2008-01-07 16:36:17 +00:00
|
|
|
const int seqlen = 2;
|
2007-12-31 16:25:17 +00:00
|
|
|
|
2016-08-24 15:51:59 +00: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 14:34:04 +00:00
|
|
|
if (!cmFortranStreamContainsSequence(finModFile, seq, seqlen)) {
|
2008-01-07 16:36:17 +00: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 14:34:04 +00:00
|
|
|
}
|
2008-01-07 16:36:17 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmFortranStreamContainsSequence(finStampFile, seq, seqlen)) {
|
2008-01-07 16:36:17 +00:00
|
|
|
// The stamp must differ if the sequence is not contained.
|
|
|
|
return true;
|
2007-12-31 16:25:17 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-12-31 16:25:17 +00:00
|
|
|
|
2012-02-26 18:44:20 +00:00
|
|
|
// Compare the remaining content. If no compiler id matched above,
|
2008-01-07 16:36:17 +00:00
|
|
|
// including the case none was given, this will compare the whole
|
|
|
|
// content.
|
2016-09-08 21:43:06 +00:00
|
|
|
return cmFortranStreamsDiffer(finModFile, finStampFile);
|
2007-12-31 16:25:17 +00:00
|
|
|
}
|
2016-10-04 20:56:31 +00:00
|
|
|
|
|
|
|
std::string cmDependsFortran::MaybeConvertToRelativePath(
|
|
|
|
std::string const& base, std::string const& path)
|
|
|
|
{
|
2018-11-23 02:16:51 +00:00
|
|
|
if (!this->LocalGenerator->GetStateSnapshot().GetDirectory().ContainsBoth(
|
|
|
|
base, path)) {
|
2016-10-04 20:56:31 +00:00
|
|
|
return path;
|
|
|
|
}
|
2018-11-23 01:38:29 +00:00
|
|
|
return cmSystemTools::ForceToRelativePath(base, path);
|
2016-10-04 20:56:31 +00:00
|
|
|
}
|