From 210b0b99a96a37cb19de7e703c12f99a4a925926 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 28 Feb 2020 10:22:23 -0500 Subject: 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 --- Modules/Compiler/XL-Fortran.cmake | 1 + Source/cmLocalCommonGenerator.cxx | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Modules/Compiler/XL-Fortran.cmake b/Modules/Compiler/XL-Fortran.cmake index 1683dff..e01ec8e 100644 --- a/Modules/Compiler/XL-Fortran.cmake +++ b/Modules/Compiler/XL-Fortran.cmake @@ -8,6 +8,7 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-qfixed") # [=] 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") diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 025ef7e..278ec8b 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/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 -- cgit v0.12