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.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to