[CMake] copying fortran .mod files in different directories

Bill Somerville bill at classdesign.com
Wed Mar 4 05:02:16 EST 2020


On 04/03/2020 09:24, Lukas van de Wiel wrote:
> we are running a Fortran code containing several dozen modules. These 
> are build in two versions, differentiated by #ifdef statements. The 
> archive files of the two versions are being kept apart by different 
> file names, but the .mod files have fixed names, based on the name of 
> the module. During a parallel build, a .mod file of one version may be 
> overwritten by the partner .mod file while the first one is still 
> required by other bits of ode that depends on it.
>
> To circumvent it, I wrote .mod files of each variety in their own 
> directory using
>
> target_compile_option(moduleTarget PUBLIC -JdirectoryName)
>
Hi Lukas,

we do something similar. We have it working by setting the target 
property Fortran_MODULE_DIRECTORY, in our case that is on a static 
library which contains the Fortran object code. We have two versions, 
one built with OpenMP and another without. One library has a default 
module directory and for the other we set the property above to a 
sub-directory of the binary directory, e.g. 
"set_target_properties(<target>, Fortran_MODULE_DIRECTORY, 
${CMAKE_BINARY_DIR}/fortran_modules_omp)". We also set the property on 
the final executables where required so I assume it does not propagate 
outwards from the static library to executables linking it :(

Regards
Bill Somerville.



More information about the CMake mailing list