[CMake] CMAKE fortran mod directories search paths awkwardness

William Clodius w.clodius at icloud.com
Tue Jul 10 14:47:10 EDT 2018


I have had a boggle involving cmake that took several days to resolve. I had originally testing Fortran code with modules (and submodules) using gfortran exclusively. This used a directory structure roughly of the form

…/source/CMakeCache.txt
…/source/CMakeFiles/*
…/source/CmakeLists.txt
…/source/...
…/source/mod_dir/*
…/source/…

Where mod_dir was intended to be there depository for the *.mod and *.smod files. I then decided  to also test with the fort compiler and went to the directory structure

…/source/CmakeLists.txt
...
…/source/gfortran_test/CMakeCache.txt
…/source/gfortran_test/CMakeFiles/*
…/source/gfortran_test/…
…/source/gfortran_test/mod_dir/*
…/source/gfortran_test/…
…/source...
…/source/ifort_test/CMakeCache.txt
…/source/ifort_test/CMakeFiles/*
…/source/ifort_test/…
…/source/ifort_test/mod_dir/*
…/source/ifort_test/…
…/source...
…/source/mod_dir/*
…
 where …/source/gfortran_test/mod_dir/ and …/source/ifort_test/mod_dir/ were intended to be the repositories for the *.mod and *.smod files when the source code in …/source is compiled using gfortran and ifort, respectively. Note that I failed to delete …/source/mod_dir and its files in going to this structure. 

This structure initially worked with no problems. I was able to compile and execute code with both gfortran and ifort. Then working in ifort I added an overloaded function in one of my modules. When I went to testing with gfortran in …/source/gfortran_test/, however, compilation would stop claiming that the new overloaded function did not have an explicit interface. I was finally able to fix the problem by eliminating the …/source/mod_dir and its associated files. As near as I can tell the Makefile generated by make in the …/source/gfortran_test/ directory was telling gfortran to write its *.mod and *.smod files to …/source/gfortran_test/mod_dir/ and applying clean to that directory, but having …/source/mod_dir/ as one of the directories on its search path (and apparently the default directory searched for *.mod files) and NOT applying make clean to that directory. As a result gfortran was finding older *.mod and *.smod files in …/source/mod_dir/ that did not define the new overloaded function, and assumed that those files were the proper files to use for the explicit interfaces. I don’t know if ifort was also searching that directory, but not using the *.mod and *.smod files as they did not have the expected ifort structure.





More information about the CMake mailing list