ENH: Implementing explicit cmake_copy_f90_mod callback to copy Fortran90 modules to the stamp files more reliably. This removes the temporary hack for per-platform upper-/lower- case.

This commit is contained in:
Brad King 2005-03-03 16:53:33 -05:00
parent 860a8e370c
commit 2444cd3828
3 changed files with 68 additions and 13 deletions

View File

@ -143,12 +143,8 @@ bool cmDependsFortran::WriteDependencies(std::ostream& os)
// Require only modules not provided in the same source. // Require only modules not provided in the same source.
if(parser.Provides.find(*i) == parser.Provides.end()) if(parser.Provides.find(*i) == parser.Provides.end())
{ {
// Temporary hack for Fortran: choose case depending on platform // Always use lower case for the mod stamp file name.
#if defined(__sgi)
std::string m = cmSystemTools::UpperCase(*i);
#else
std::string m = cmSystemTools::LowerCase(*i); std::string m = cmSystemTools::LowerCase(*i);
#endif
os << m_TargetFile.c_str() << ": " << m.c_str() << ".mod.stamp" os << m_TargetFile.c_str() << ": " << m.c_str() << ".mod.stamp"
<< std::endl; << std::endl;
os << m_TargetFile.c_str() << ".requires: " << i->c_str() << ".mod.proxy" os << m_TargetFile.c_str() << ".requires: " << i->c_str() << ".mod.proxy"
@ -182,14 +178,12 @@ bool cmDependsFortran::WriteDependencies(std::ostream& os)
for(std::set<cmStdString>::const_iterator i = parser.Provides.begin(); for(std::set<cmStdString>::const_iterator i = parser.Provides.begin();
i != parser.Provides.end(); ++i) i != parser.Provides.end(); ++i)
{ {
// Temporary hack for Fortran: choose case depending on platform // Always use lower case for the mod stamp file name. The
#if defined(__sgi) // cmake_copy_f90_mod will call back to this class, which will
std::string m = cmSystemTools::UpperCase(*i); // try various cases for the real mod file name.
#else
std::string m = cmSystemTools::LowerCase(*i); std::string m = cmSystemTools::LowerCase(*i);
#endif os << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod "
os << "\t@$(CMAKE_COMMAND) -E copy_if_different " << i->c_str() << " " << m.c_str() << ".mod.stamp\n";
<< m.c_str() << ".mod " << m.c_str() << ".mod.stamp\n";
} }
os << "\t@touch " << m_TargetFile.c_str() << ".provides\n"; os << "\t@touch " << m_TargetFile.c_str() << ".provides\n";
} }
@ -258,6 +252,53 @@ bool cmDependsFortran::CheckDependencies(std::istream&)
return true; return true;
} }
//----------------------------------------------------------------------------
bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
{
// Implements
//
// $(CMAKE_COMMAND) -E cmake_copy_f90_mod input.mod output.mod.stamp
//
// 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];
mod += ".mod";
std::string stamp = args[3];
std::string mod_upper = cmSystemTools::UpperCase(mod.c_str());
std::string mod_lower = cmSystemTools::LowerCase(mod.c_str());
if(cmSystemTools::FileExists(mod_upper.c_str()))
{
if(!cmSystemTools::CopyFileIfDifferent(mod_upper.c_str(), stamp.c_str()))
{
std::cerr << "Error copying Fortran module from \""
<< mod_upper.c_str() << "\" to \"" << stamp.c_str()
<< "\".\n";
return false;
}
return true;
}
else if(cmSystemTools::FileExists(mod_lower.c_str()))
{
if(!cmSystemTools::CopyFileIfDifferent(mod_lower.c_str(), stamp.c_str()))
{
std::cerr << "Error copying Fortran module from \""
<< mod_lower.c_str() << "\" to \"" << stamp.c_str()
<< "\".\n";
return false;
}
return true;
}
std::cerr << "Error copying Fortran module \"" << args[2].c_str()
<< "\". Tried \"" << mod_upper.c_str()
<< "\" and \"" << mod_lower.c_str() << "\".\n";
return false;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmDependsFortran::FindIncludeFile(const char* dir, bool cmDependsFortran::FindIncludeFile(const char* dir,
const char* includeName, const char* includeName,

View File

@ -39,6 +39,11 @@ public:
/** Virtual destructor to cleanup subclasses properly. */ /** Virtual destructor to cleanup subclasses properly. */
virtual ~cmDependsFortran(); virtual ~cmDependsFortran();
/** Callback from build system after a .mod file has been generated
by a Fortran90 compiler to copy the .mod file to the
corresponding stamp file. */
static bool CopyModule(const std::vector<std::string>& args);
/** Method to find an included file in the include path. Fortran /** Method to find an included file in the include path. Fortran
always searches the directory containing the including source always searches the directory containing the including source
first. */ first. */

View File

@ -23,11 +23,12 @@
#include "cmCommand.h" #include "cmCommand.h"
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
# include "cmVariableWatch.h" # include "cmVariableWatch.h"
# include "cmVersion.h" # include "cmVersion.h"
#endif #endif
#include "cmLocalUnixMakefileGenerator2.h" #include "cmLocalUnixMakefileGenerator2.h" // For -E cmake_depends callback.
// only build kdevelop generator on non-windows platforms // only build kdevelop generator on non-windows platforms
// when not bootstrapping cmake // when not bootstrapping cmake
@ -834,6 +835,14 @@ int cmake::CMakeCommand(std::vector<std::string>& args)
return cmLocalUnixMakefileGenerator2::ScanDependencies(args)? 0 : 1; return cmLocalUnixMakefileGenerator2::ScanDependencies(args)? 0 : 1;
} }
#if defined(CMAKE_BUILD_WITH_CMAKE)
// Internal CMake Fortran module support.
else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
{
return cmDependsFortran::CopyModule(args)? 0 : 1;
}
#endif
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
// Write registry value // Write registry value
else if (args[1] == "write_regv" && args.size() > 3) else if (args[1] == "write_regv" && args.size() > 3)