sourceryinstitute / OpenCoarrays

A parallel application binary interface for Fortran 2018 compilers.
http://www.opencoarrays.org
BSD 3-Clause "New" or "Revised" License
243 stars 58 forks source link

CMake build error on fpm-dev-build branch: make can't find a .mod file #759

Open rouson opened 2 years ago

rouson commented 2 years ago

What happened

A test failed to compile because make couldn't find a required .mod file that is in the build tree.

System Information

uname -a
Darwin CLaSS.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Step-by-step reproduction of the error

With Homebrew installed, execute

brew tap fortran-lang/fortran
brew install fpm open-mpi cmake
git clone -b fpm-dev-build git@github.com:sourceryinstitute/opencoarrays
cd opencoarrays
export CC=`which gcc-11`
export CXX=`which g++-11`
export FC=`which gfortran-11`
cmake -B build .
cd build
make -j 8

for which the trailing output is

[ 78%] Generating teams_subset
/Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/tests/unit/teams/team-number.f90:34:7:

   34 |   use oc_assertions_interface, only : assert
      |       1
Fatal Error: Cannot open module file 'oc_assertions_interface.mod' for reading at (1): No such file or directory
compilation terminated.
Error: comand:
   `/usr/local/bin/gfortran-11 -fcoarray=lib -Wl,-flat_namespace -Wl,-commons,use_dylibs -L/usr/local/Cellar/libevent/2.1.12/lib -I/usr/local/Cellar/open-mpi/4.1.4/include -I/usr/local/Cellar/open-mpi/4.1.4/lib -DPREFIX_NAME=_gfortran_caf_ -DGCC_GE_7 -DGCC_GE_8 -DHAVE_MPI -DMPI_WORKING_MODULE -O3 -DNDEBUG -O3 -o /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/bin/OpenCoarrays-2.10.0-17-g7f75c50-tests/team_number /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/tests/unit/teams/team-number.f90 /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libopencoarrays_test_utilities.a /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libopencoarrays_mod.a /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libcaf_mpi.a /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_usempif08.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_usempi_ignore_tkr.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_mpifh.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi.dylib`
failed to compile.
make[2]: *** [tests/unit/teams/team_number] Error 1
make[1]: *** [tests/unit/teams/CMakeFiles/build_team_number.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 78%] Built target build_image_fail_and_sync_test_2
/Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/tests/unit/teams/teams_subset.f90:6:7:

    6 |   use oc_assertions_interface, only : assert
      |       1
Fatal Error: Cannot open module file 'oc_assertions_interface.mod' for reading at (1): No such file or directory
compilation terminated.
Error: comand:
   `/usr/local/bin/gfortran-11 -fcoarray=lib -Wl,-flat_namespace -Wl,-commons,use_dylibs -L/usr/local/Cellar/libevent/2.1.12/lib -I/usr/local/Cellar/open-mpi/4.1.4/include -I/usr/local/Cellar/open-mpi/4.1.4/lib -DPREFIX_NAME=_gfortran_caf_ -DGCC_GE_7 -DGCC_GE_8 -DHAVE_MPI -DMPI_WORKING_MODULE -O3 -DNDEBUG -O3 -o /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/bin/OpenCoarrays-2.10.0-17-g7f75c50-tests/teams_subset /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/tests/unit/teams/teams_subset.f90 /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libopencoarrays_test_utilities.a /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libopencoarrays_mod.a /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libcaf_mpi.a /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_usempif08.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_usempi_ignore_tkr.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_mpifh.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi.dylib`
failed to compile.
make[2]: *** [tests/unit/teams/teams_subset] Error 1
make[1]: *** [tests/unit/teams/CMakeFiles/build_teams_subset.dir/all] Error 2
[ 78%] Built target build_image_fail_and_sync_test_3
[ 78%] Built target build_image_fail_and_failed_images_test_1
[ 78%] Built target build_image_fail_and_stopped_images_test_1
[ 78%] Built target build_image_fail_and_get_test_1
[ 78%] Built target build_image_fail_and_status_test_1
make: *** [all] Error 2
rouson commented 2 years ago

Commenting out lines 1-2 in tests/unit/teams/CMakeLists.txt eliminates the above two errors and leaves one similar error (see below), which in turn can be eliminated by commenting out line 3 in the same file. Each of the aforementioned lines invokes the function defined at line 563 in the project root CMakeLists.txt file. I suspect that the ultimate cause is related to the fact that I moved the entire tests directory from its previous location just inside src one level up to the project root directory. Otherwise, one of the biggest changes is that we recently recently released version 2.10.0, which adds support for building natively on Windows (without requiring Windows Subsystem for Linux).

/Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/tests/unit/teams/get-communicator.F90:32:7:

   32 |   use opencoarrays, only : get_communicator
      |       1
Fatal Error: Cannot open module file 'opencoarrays.mod' for reading at (1): No such file or directory
compilation terminated.
Error: comand:
   `/usr/local/bin/gfortran-11 -fcoarray=lib -Wl,-flat_namespace -Wl,-commons,use_dylibs -L/usr/local/Cellar/libevent/2.1.12/lib -I/usr/local/Cellar/open-mpi/4.1.4/include -I/usr/local/Cellar/open-mpi/4.1.4/lib -DPREFIX_NAME=_gfortran_caf_ -DGCC_GE_7 -DGCC_GE_8 -DHAVE_MPI -DMPI_WORKING_MODULE -O3 -DNDEBUG -O3 -o /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/bin/OpenCoarrays-2.10.0-17-g7f75c50-tests/get_communicator /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/tests/unit/teams/get-communicator.F90 /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libopencoarrays_test_utilities.a /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libopencoarrays_mod.a /Users/rouson/Repositories/sourceryinstitute/tmp/opencoarrays/build/lib/libcaf_mpi.a /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_usempif08.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_usempi_ignore_tkr.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi_mpifh.dylib /usr/local/Cellar/open-mpi/4.1.4/lib/libmpi.dylib`
failed to compile.
make[2]: *** [tests/unit/teams/get_communicator] Error 1
make[1]: *** [tests/unit/teams/CMakeFiles/build_get_communicator.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 77%] Built target build_image_fail_and_sync_test_2
[ 77%] Built target build_image_fail_and_sync_test_3
[ 77%] Built target build_image_fail_and_status_test_1
[ 77%] Built target build_image_fail_and_get_test_1
[ 77%] Built target build_image_fail_and_failed_images_test_1
[ 77%] Built target build_image_fail_and_stopped_images_test_1
[ 77%] Built target build_teams_coarray_get
make: *** [all] Error 2
bradking commented 2 years ago

The failure occurs in a custom command that invokes the bin/caf tool. That builds module-consuming code outside of CMake's code model, so module (include) directories need to be handled explicitly. See explanation in https://github.com/sourceryinstitute/OpenCoarrays/pull/758#pullrequestreview-1006079316.