<div dir="ltr"><div dir="ltr"><div>Hi Bill,</div><div><br></div><div>Thanks a lot for your quick response! Using your idea I could set the Fortran module directory per module target, and add those directories as target_include_directories to the executables. Worked like a charm!<br></div><div><br></div><div>Lukas<br></div><div><br></div><div>PS. As example, I adapted my cat/dog CMakeLists.txt to this to get to work, in parallel build 'n all:</div><div><br></div><div>project(pets LANGUAGES Fortran)<br><br>file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/catdir)<br>file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/dogdir)<br><br>set(catdir "${CMAKE_BINARY_DIR}/catdir")<br>set(dogdir "${CMAKE_BINARY_DIR}/dogdir")<br><br>set(CMAKE_Fortran_SOURCE_FILES_EXTENSIONS F)<br>set(CMAKE_Fortran_FLAGS "-cpp -std=f2008 -ffree-form")<br><br>add_library(catModule STATIC "src/pets.F")<br>target_compile_options(catModule PUBLIC "-Dcat")<br>set_target_properties(catModule PROPERTIES Fortran_MODULE_DIRECTORY ${catdir})<br><br>add_library(dogModule STATIC "src/pets.F")<br>set_target_properties(dogModule PROPERTIES Fortran_MODULE_DIRECTORY ${dogdir})<br><br>add_executable(cat "src/main.F")<br>target_include_directories(cat PUBLIC ${catdir})<br>add_dependencies(cat catModule)<br>target_link_libraries(cat catModule)<br>target_compile_options(cat PUBLIC "-Dcat")<br><br>add_executable(dog "src/main.F")<br>target_include_directories(dog PUBLIC ${dogdir})<br>add_dependencies(dog dogModule)<br>target_link_libraries(dog dogModule)<br></div><div><br></div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 4, 2020 at 11:10 AM Bill Somerville <<a href="mailto:bill@classdesign.com">bill@classdesign.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 04/03/2020 09:24, Lukas van de Wiel wrote:<br>
> we are running a Fortran code containing several dozen modules. These <br>
> are build in two versions, differentiated by #ifdef statements. The <br>
> archive files of the two versions are being kept apart by different <br>
> file names, but the .mod files have fixed names, based on the name of <br>
> the module. During a parallel build, a .mod file of one version may be <br>
> overwritten by the partner .mod file while the first one is still <br>
> required by other bits of ode that depends on it.<br>
><br>
> To circumvent it, I wrote .mod files of each variety in their own <br>
> directory using<br>
><br>
> target_compile_option(moduleTarget PUBLIC -JdirectoryName)<br>
><br>
Hi Lukas,<br>
<br>
we do something similar. We have it working by setting the target <br>
property Fortran_MODULE_DIRECTORY, in our case that is on a static <br>
library which contains the Fortran object code. We have two versions, <br>
one built with OpenMP and another without. One library has a default <br>
module directory and for the other we set the property above to a <br>
sub-directory of the binary directory, e.g. <br>
"set_target_properties(<target>, Fortran_MODULE_DIRECTORY, <br>
${CMAKE_BINARY_DIR}/fortran_modules_omp)". We also set the property on <br>
the final executables where required so I assume it does not propagate <br>
outwards from the static library to executables linking it :(<br>
<br>
Regards<br>
Bill Somerville.<br>
<br>
-- <br>
<br>
Powered by <a href="http://kitware.com/cmake" rel="noreferrer" target="_blank">kitware.com/cmake</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit <a href="https://cmake.org/services" rel="noreferrer" target="_blank">https://cmake.org/services</a><br>
<br>
Visit other Kitware open-source projects at <a href="https://www.kitware.com/platforms" rel="noreferrer" target="_blank">https://www.kitware.com/platforms</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
<br>
This mailing list is deprecated in favor of <a href="https://discourse.cmake.org" rel="noreferrer" target="_blank">https://discourse.cmake.org</a><br>
</blockquote></div></div>