<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hello,<br></div><div><br></div>I am trying to compile the same source files into two different executables, each with their own compile definitions applied. However, I notice some odd behavior when I do this. In my situation I have two files main.f90 and def.f90. The main.f90 file, has a #ifdef to use a value from the def.f90 file. The first time I run cmake / make, everything goes ok. However, if I 'touch' main.f90 (so that it will rebuild only that file), then 'make' aborts saying that the value does not exist. I've put a small example together below to help illustrate:<br>
<br>def.f90<br>---------<br><span style="font-family:courier new,monospace">module def<br></span><div><span style="font-family:courier new,monospace"><br>#ifdef A<br></span></div><div><span style="font-family:courier new,monospace"> integer :: val = 4<br>
</span></div><div><span style="font-family:courier new,monospace">#endif<br></span></div><span style="font-family:courier new,monospace"><br>end module def</span><br></div><br>main.f90<br>------------<br></div><span style="font-family:courier new,monospace">program main<br>
</span></div><span style="font-family:courier new,monospace"><br>#ifdef A<br></span></div><span style="font-family:courier new,monospace"> use def, only: val<br></span></div><span style="font-family:courier new,monospace"> print*,'A: ',val<br>
</span></div><span style="font-family:courier new,monospace">#endif<br><br></span></div><span style="font-family:courier new,monospace">#ifdef B<br></span></div><span style="font-family:courier new,monospace"> print*,'B'<br>
</span></div><span style="font-family:courier new,monospace">#endif<br><br></span></div><span style="font-family:courier new,monospace">end program main</span><br></div></div></div><br></div>CMakeLists.txt<br>----------------------<br>
</div><span style="font-family:courier new,monospace">cmake_minimum_required(VERSION 2.8)<br></span></div><span style="font-family:courier new,monospace">project(confused Fortran)<br></span></div><span style="font-family:courier new,monospace">add_executable(a main.f90 def.f90)<br>
</span></div><span style="font-family:courier new,monospace">add_executable(b main.f90 def.f90)<br></span></div><span style="font-family:courier new,monospace">set_target_properties(a PROPERTIES COMPILE_FLAGS "-fpp"<br>
COMPILE_DEFINITIONS A)<br>set_target_properties(b PROPERTIES COMPILE_FLAGS "-fpp"<br> COMPILE_DEFINITIONS B)</span><br><br></div>As I mentioned, the first time I run cmake / make, everything works fine. The executables are created and produce the expected output. If I 'touch' main.f90 and run cmake / make, though, it aborts saying:<br>
<br></div><span style="font-family:courier new,monospace">error #6580: Name in only-list does not exist. [val]</span><br><br>It's like CMake is trying to rebuild 'a' using the def.o object from 'b'. Interestingly, if I touch def.f90, then everything will be rebuilt just fine. <br>
<br>If anyone could shed some insight onto what is happening here, I would be very grateful! Is this behavior expected?<br><br>Thank you,<br>Brian<br><div><br></div></div>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">Bechtel Marine Propulsion Corporation and Bechtel Plant Machinery, Inc., wholly owned subsidiaries of Bechtel National Inc., are Prime Contractors for the United States Naval Nuclear Propulsion Program.</font>