1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4 
5 #include "cmConfigure.h" // IWYU pragma: keep
6 
7 #include <iosfwd>
8 #include <memory>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 #include "cmDepends.h"
14 
15 class cmDependsFortranInternals;
16 class cmFortranSourceInfo;
17 class cmLocalUnixMakefileGenerator3;
18 
19 /** \class cmDependsFortran
20  * \brief Dependency scanner for Fortran object files.
21  */
22 class cmDependsFortran : public cmDepends
23 {
24 public:
25   /** Checking instances need to know the build directory name and the
26       relative path from the build directory to the target file.  */
27   cmDependsFortran();
28 
29   /** Scanning need to know the build directory name, the relative
30       path from the build directory to the target file, the source
31       file from which to start scanning, the include file search
32       path, and the target directory.  */
33   cmDependsFortran(cmLocalUnixMakefileGenerator3* lg);
34 
35   /** Virtual destructor to cleanup subclasses properly.  */
36   ~cmDependsFortran() override;
37 
38   cmDependsFortran(cmDependsFortran const&) = delete;
39   cmDependsFortran& operator=(cmDependsFortran const&) = delete;
40 
41   /** Callback from build system after a .mod file has been generated
42       by a Fortran90 compiler to copy the .mod file to the
43       corresponding stamp file.  */
44   static bool CopyModule(const std::vector<std::string>& args);
45 
46   /** Determine if a mod file and the corresponding mod.stamp file
47       are representing  different module information. */
48   static bool ModulesDiffer(const std::string& modFile,
49                             const std::string& stampFile,
50                             const std::string& compilerId);
51 
52 protected:
53   // Finalize the dependency information for the target.
54   bool Finalize(std::ostream& makeDepends,
55                 std::ostream& internalDepends) override;
56 
57   // Find all the modules required by the target.
58   void LocateModules();
59   void MatchLocalModules();
60   void MatchRemoteModules(std::istream& fin, const std::string& stampDir);
61   void ConsiderModule(const std::string& name, const std::string& stampDir);
62   bool FindModule(std::string const& name, std::string& module);
63 
64   // Implement writing/checking methods required by superclass.
65   bool WriteDependencies(const std::set<std::string>& sources,
66                          const std::string& file, std::ostream& makeDepends,
67                          std::ostream& internalDepends) override;
68 
69   // Actually write the dependencies to the streams.
70   bool WriteDependenciesReal(std::string const& obj,
71                              cmFortranSourceInfo const& info,
72                              std::string const& mod_dir,
73                              std::string const& stamp_dir,
74                              std::ostream& makeDepends,
75                              std::ostream& internalDepends,
76                              bool buildingIntrinsics);
77 
78   // The source file from which to start scanning.
79   std::string SourceFile;
80 
81   std::string CompilerId;
82   std::string SModSep;
83   std::string SModExt;
84 
85   std::set<std::string> PPDefinitions;
86 
87   // Internal implementation details.
88   std::unique_ptr<cmDependsFortranInternals> Internal;
89 };
90