[CMake] CMake project with fpp preprocessed Fortran source file failed

turbulent 909937233 at qq.com
Sun Jan 1 21:16:25 EST 2017


Hi,

I'm trying to use fpp preprocessor in a Fortran project built with CMake. For example, 
I have two source files. The file x.f90 defines module x:

module x
#ifdef ENABLE_Z
  use z
#endif
  implicit none
end module x

The module z used in module x is defined in z.f90 as followed:

module z
  implicit none
  integer :: z_a
end module z

Below is the CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)

project(foo Fortran)

set_source_files_properties(x.f90
  PROPERTIES
  COMPILE_DEFINITIONS "ENABLE_Z"
  )

add_library(mylib
  x.f90
  z.f90
  )

I use "MinGW Makefile" generator and Intel Parallel Studio XE 2015 to build mylib 
under windows 7 command console: 

D:\dev\cmake\fortran_depend_fpp\build>cmake -G"MinGW Makefiles" -DCMAKE_Fortran_
COMPILER=ifort ..\src
-- The Fortran compiler identification is Intel 15.0.2.20150121
-- Check for working Fortran compiler: C:/Intel/Composer XE 2015/bin/intel64/ifo
rt.exe
-- Check for working Fortran compiler: C:/Intel/Composer XE 2015/bin/intel64/ifo
rt.exe  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/Intel/Composer XE 2015/bin/intel64/ifort.exe supports For
tran 90
-- Checking whether C:/Intel/Composer XE 2015/bin/intel64/ifort.exe supports For
tran 90 -- yes
-- Configuring done
-- Generating done
-- Build files have been written to: D:/dev/cmake/fortran_depend_fpp/build

When building library mylib, it failed:

D:\dev\cmake\fortran_depend_fpp\build>mingw32-make mylib
Scanning dependencies of target mylib
[ 33%] Building Fortran object CMakeFiles/mylib.dir/x.f90.obj
D:\dev\cmake\fortran_depend_fpp\src\x.f90(4): error #7002: Error in opening the
compiled module file.  Check INCLUDE paths.   [Z]
  use z
------^
compilation aborted for D:\dev\cmake\fortran_depend_fpp\src\x.f90 (code 1)
CMakeFiles\mylib.dir\build.make:61: recipe for target 'CMakeFiles/mylib.dir/x.f9
0.obj' failed
mingw32-make[3]: *** [CMakeFiles/mylib.dir/x.f90.obj] Error 1
CMakeFiles\Makefile2:104: recipe for target 'CMakeFiles/mylib.dir/all' failed
mingw32-make[2]: *** [CMakeFiles/mylib.dir/all] Error 2
CMakeFiles\Makefile2:117: recipe for target 'CMakeFiles/mylib.dir/rule' failed
mingw32-make[1]: *** [CMakeFiles/mylib.dir/rule] Error 2
Makefile:130: recipe for target 'mylib' failed
mingw32-make: *** [mylib] Error 2

The reason is that x.f90 is compiled before z.f90. It seems that the makefile doesn't 
contain the rule about module x's dependency on module z. How could I correct it? 
Thanks in advance for your suggestions.

BTW: the "Visual Studio 12 2013" generator works fine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170102/bf07c9c4/attachment.html>


More information about the CMake mailing list