# Builds ok with Visual Studio but fails with nmake

**URL:** https://discourse.cmake.org/t/builds-ok-with-visual-studio-but-fails-with-nmake/11078
**Category:** Code
**Created:** [June 21, 2024, 5:00pm UTC](https://discourse.cmake.org/t/builds-ok-with-visual-studio-but-fails-with-nmake/11078 "2024-06-21T17:00:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [June 21, 2024, 5:00pm UTC](https://discourse.cmake.org/t/builds-ok-with-visual-studio-but-fails-with-nmake/11078/1 "2024-06-21T17:00:10Z")

</div>

I have a fortran project that has a target that involves compiling a number of modules using the Intel compiler. CMAKE\_Fortran\_MODULE\_DIRECTORY is set to a common include directory for the target. However, I need the mod file for one of the modules to be created in a different include directory. I use set\_source\_files\_properties to set the /module: compiler option for the source file to set the required include directory and I add the directory to the list of include directories for the target. This all works fine when building using the Visual Studio generator, however, when using the nmake generator the build fails when an attempt is made to copy the mod file from the common include directory. Does anyone have a suggestion of how to prevent the copy from the wrong location in the nmake build?

---

<div class="post-metadata">

### Author: ![Nocaster60](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@Nocaster60](https://discourse.cmake.org/u/Nocaster60)
#### Post date: [June 24, 2024, 7:58am UTC](https://discourse.cmake.org/t/builds-ok-with-visual-studio-but-fails-with-nmake/11078/2 "2024-06-24T07:58:23Z")

</div>

To answer my own question: for the targets that required it, I reset CMAKE\_Fortran\_MODULE\_DIRECTORY before the target is created so that it had its own module directory and added a post build event that copied the required mod files to the common include directory.
