Browse Source

XL: Fix using Fortran modules from their output directory

The XL Fortran compiler's `-qmoddir=` flag sets the module output
directory but does not add the directory to the search path for using
modules.  This is inconsistent with other compilers like the GNU Fortran
compiler's `-J` flag that does both.  In order to make these consistent,
add the module output directory with a `-I` flag on the XL Fortran
compiler so that it will be searched when using modules too.

This fixes our `FortranModules` test's coverage of submodules on
Ninja + XL.  That test places module files in a subdirectory that with
Ninja is not the current working directory when the compiler runs.

Fixes: #20400
Brad King 5 years ago
parent
commit
210b0b99a9
2 changed files with 10 additions and 0 deletions
  1. 1 0
      Modules/Compiler/XL-Fortran.cmake
  2. 9 0
      Source/cmLocalCommonGenerator.cxx

+ 1 - 0
Modules/Compiler/XL-Fortran.cmake

@@ -8,6 +8,7 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-qfixed") # [=<right_margin>]
 set(CMAKE_Fortran_FORMAT_FREE_FLAG "-qfree") # [=f90|ibm]
 
 set(CMAKE_Fortran_MODDIR_FLAG "-qmoddir=")
+set(CMAKE_Fortran_MODDIR_INCLUDE_FLAG "-I") # -qmoddir= does not affect search path
 
 set(CMAKE_Fortran_DEFINE_FLAG "-WF,-D")
 

+ 9 - 0
Source/cmLocalCommonGenerator.cxx

@@ -50,6 +50,15 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
       this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"),
       mod_dir);
     this->AppendFlags(flags, modflag);
+    // Some compilers do not search their own module output directory
+    // for using other modules.  Add an include directory explicitly
+    // for consistency with compilers that do search it.
+    std::string incflag =
+      this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_INCLUDE_FLAG");
+    if (!incflag.empty()) {
+      incflag = cmStrCat(incflag, mod_dir);
+      this->AppendFlags(flags, incflag);
+    }
   }
 
   // If there is a separate module path flag then duplicate the