[CMake] Fortran Macro in 2.2

William A. Hoffman billlist at nycap.rr.com
Thu Oct 20 10:49:48 EDT 2005


You may want to try cmake's native fortran support.

PROJECT(foo FORTRAN)
ADD_EXECUTABLE(foo foo.f)



At 10:41 AM 10/20/2005, Karl Merkley wrote:
>I am using Mac OS X CMake version 2.2.1 or cvs  CMake version 2.3-20050922.
>
>I have a macro that we use to compile fortran code.  However, it looks like it no longer works with the latest code.
>
># Define a macro to compile Fortran code
>MACRO(F77 var outvar)
>  SET(new_objs "")
>  FOREACH(var_src ${var})
>    GET_FILENAME_COMPONENT(var_src_file "${var_src}" NAME_WE)
>    SET(var_obj ${var_src_file}${CML_OBJ_EXT})
>    # this is a generated file
>    SET_SOURCE_FILES_PROPERTIES(${var_obj} PROPERTIES GENERATED ON)
>    SET(new_objs ${new_objs} "${var_obj}")
>    ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${var_obj}
>                       COMMAND ${CML_FXX_COMPILER}
>                       ARGS ${CML_FXX_OUT} ${CMAKE_CURRENT_BINARY_DIR}/${var_obj} ${CML_FXX_INCLUDE} ${CML_FXX_FLAGS} ${var_src}
>                       DEPENDS ${var_src}
>                       COMMENT "${CML_FXX_COMPILER} object file"
>                       )
>  ENDFOREACH(var_src)
>  SET(${outvar} ${new_objs})
>ENDMACRO(F77)
>
>The macro gets invoked as
>
>F77("${INR_F_SRCS}"    INR_F_OBJS)
>
>The list of source files have  .f  extensions and the return argument contains the list of object files that are produced.  The object files then get added to a library.
>
>ADD_LIBRARY(cml_lib  ${INR_C_SRCS}  ${INR_F_OBJS} )
>
>There is a lot more that goes on in the CMakeLists.txt but this is the core of the problem.  When I run cmake/make the C files get added to the library but the object files do not.  When I look in the build.make file, there are instructions to compile the Fortran code but there is no dependency on the object files to be added to the library so they never get built and never get added to the library.
>
>Can anybody suggest a way to work around this?  I have a customer who is trying to build the library on Mac OS X 10.4 system which I don't have.  I would like to be able to provide a solution ASAP.
>
>  Thanks,
>         Karl
>
>_______________________________________________
>CMake mailing list
>CMake at cmake.org
>http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list