[CMake] odd behavior when recompiling same source with different compile definitions
Nease, Brian
brian.nease at unnpp.gov
Mon Apr 7 14:34:51 EDT 2014
Hello,
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:
def.f90
---------
module def
#ifdef A
integer :: val = 4
#endif
end module def
main.f90
------------
program main
#ifdef A
use def, only: val
print*,'A: ',val
#endif
#ifdef B
print*,'B'
#endif
end program main
CMakeLists.txt
----------------------
cmake_minimum_required(VERSION 2.8)
project(confused Fortran)
add_executable(a main.f90 def.f90)
add_executable(b main.f90 def.f90)
set_target_properties(a PROPERTIES COMPILE_FLAGS "-fpp"
COMPILE_DEFINITIONS A)
set_target_properties(b PROPERTIES COMPILE_FLAGS "-fpp"
COMPILE_DEFINITIONS B)
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:
error #6580: Name in only-list does not exist. [val]
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.
If anyone could shed some insight onto what is happening here, I would be
very grateful! Is this behavior expected?
Thank you,
Brian
--
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140407/c074f359/attachment.html>
More information about the CMake
mailing list