Broken cmake build when building in parallel - Fortran submodules
I'm developing a small Fortran project, and using cmake to generate a Makefile on Linux. I'm using cmake version 3.9.0-rc5. Since my project uses Fortran submodules (new in Fortran 2008), I need to use at least cmake version 3.7.0 (#16234 (closed))
This seems to be related to #17017 (closed), except instead of having nested submodules, I have two targets that require the same source files - the targets are a shared and static library of the same source.
I want to build both a static and dynamic library of the project, which builds fine when done serially, but apparently results in a race condition when building in parallel. Building one library deletes a source file that is also required by the other library. The race condition is not always reproducible, sometimes it builds successfully on my system and sometimes it doesn't. I guess that's the definition of a race condition...
Output of a broken build:
>cmake --version
cmake version 3.9.0-rc5
CMake suite maintained and supported by Kitware (kitware.com/cmake).
> cmake ../ && make -j8
-- The Fortran compiler identification is GNU 7.1.1
-- Check for working Fortran compiler: /home/chris/bin/gfortran
-- Check for working Fortran compiler: /home/chris/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /home/chris/bin/gfortran supports Fortran 90
-- Checking whether /home/chris/bin/gfortran supports Fortran 90 -- yes
-- Build Type: Debug
--
-- BLAS/LAPACK Summary:
-- Looking for Fortran sgemm
-- Looking for Fortran sgemm - found
-- A library with BLAS API found.
-- Looking for Fortran cheev
-- Looking for Fortran cheev - found
-- A library with LAPACK API found.
-- LAPACK Libraries:
-- LAPACK Libraries: /usr/lib64/libopenblas.so;/usr/lib64/libopenblas.so
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chris/Projects/learn_dg/build
Scanning dependencies of target core-static
Scanning dependencies of target core-shared
[ 3%] Building Fortran object CMakeFiles/core-static.dir/src/fortranlib/src/lib_array.f90.o
[ 9%] Building Fortran object CMakeFiles/core-shared.dir/src/linalg/mod_linalg.f90.o
[ 9%] Building Fortran object CMakeFiles/core-static.dir/src/legendre/mod_legendre.f90.o
[ 12%] Building Fortran object CMakeFiles/core-shared.dir/src/fortranlib/src/lib_array.f90.o
[ 18%] Building Fortran object CMakeFiles/core-shared.dir/src/legendre/mod_legendre.f90.o
[ 18%] Building Fortran object CMakeFiles/core-static.dir/src/linalg/mod_linalg.f90.o
[ 21%] Building Fortran object CMakeFiles/core-shared.dir/src/misc/mod_misc.f90.o
[ 25%] Building Fortran object CMakeFiles/core-static.dir/src/misc/mod_misc.f90.o
f951: Fatal Error: Can't rename module file ‘lib/mod_linalg.mod0’ to ‘lib/mod_linalg.mod’: No such file or directory
compilation terminated.
f951: Fatal Error: Can't rename module file ‘lib/mod_legendre.mod0’ to ‘lib/mod_legendre.mod’: No such file or directory
compilation terminated.
CMakeFiles/core-shared.dir/build.make:86: recipe for target 'CMakeFiles/core-shared.dir/src/legendre/mod_legendre.f90.o' failed
make[3]: *** [CMakeFiles/core-shared.dir/src/legendre/mod_legendre.f90.o] Error 1
CMakeFiles/core-static.dir/build.make:302: recipe for target 'CMakeFiles/core-static.dir/src/linalg/mod_linalg.f90.o' failed
make[3]: *** [CMakeFiles/core-static.dir/src/linalg/mod_linalg.f90.o] Error 1
CMakeFiles/core-shared.dir/build.make:102: recipe for target 'CMakeFiles/core-shared.dir/src/legendre/mod_legendre.f90.o.provides' failed
make[2]: *** [CMakeFiles/core-shared.dir/src/legendre/mod_legendre.f90.o.provides] Error 2
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/core-static.dir/build.make:318: recipe for target 'CMakeFiles/core-static.dir/src/linalg/mod_linalg.f90.o.provides' failed
make[2]: *** [CMakeFiles/core-static.dir/src/linalg/mod_linalg.f90.o.provides] Error 2
make[2]: *** Waiting for unfinished jobs....
Error copying Fortran module "lib/mod_legendre". Tried "lib/MOD_LEGENDRE.mod" and "lib/mod_legendre.mod".
CMakeFiles/core-static.dir/depend.make:67: recipe for target 'CMakeFiles/core-static.dir/src/legendre/mod_legendre.f90.o.provides.build' failed
make[3]: *** [CMakeFiles/core-static.dir/src/legendre/mod_legendre.f90.o.provides.build] Error 1
CMakeFiles/core-static.dir/build.make:102: recipe for target 'CMakeFiles/core-static.dir/src/legendre/mod_legendre.f90.o.provides' failed
make[2]: *** [CMakeFiles/core-static.dir/src/legendre/mod_legendre.f90.o.provides] Error 2
CMakeFiles/Makefile2:181: recipe for target 'CMakeFiles/core-shared.dir/all' failed
make[1]: *** [CMakeFiles/core-shared.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:143: recipe for target 'CMakeFiles/core-static.dir/all' failed
make[1]: *** [CMakeFiles/core-static.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2