[CMake] Compiling Fortran Modules And

Pritchett-Sheats, Lori lpritch at lanl.gov
Mon May 13 14:08:46 EDT 2013


I'm converting a Fortran package that was using GNU make to build to CMake, but I've run into a problem compiling F90 module code where the source code is stored under many directories.

The package has a directory structure

src/
      src/dir1
      src/dir2
      :
      :

Each dir* has *.F files that must be preprocessed to *.f90 files and then compiled. In the original build system, the package had an empty 'build' directory under src. The processed files were created there and then the library was built from these files was also generated there. I tried to do something similar with CMake but I see errors  from make about 'No rules to make target ' pointing to files that do not exist under the CMakeFiles directories, however the object file and the *.mod files are there, so I know I'm compiling correctly.

Here's my CMakeLists.txt snippet in the src directory


set(DIR1_FILES dir1/file1_module.F dir2/file2_module.F)
set(DIR2_FILES dir2/file3_module.F dir2/file4_module.F)
set(F_PREPROCESS_FILES ${DIR1_FILES} ${DIR2_FILES})


set(F90Library_SOURCE_FILES)
foreach (src_file ${F_PREPROCESS_FILES})

  get_filename_component(filename "${src_file}" NAME_WE)
  set(F_file ${CMAKE_CURRENT_SOURCE_DIR}/${src_file})
  set(new_file_f90 ${CMAKE_CURRENT_BINARY_DIR}/${filename}.f90)
  message(STATUS "new_file_f90=${new_file_f90}")

  add_custom_command(OUTPUT "${new_file_f90}"
      COMMAND ${CMAKE_C_COMPILER} -E ${CMAKE_CPP_FLAGS} ${F_file} ${grep_filter} | grep -v \\!\\!CPP\\!\\! | grep -v ^\#  > ${new_file_f90}
      IMPLICIT_DEPENDS Fortran "${F_file}"
      COMMENT "\tPreprocessing ${src_file}"
      VERBATIM)
  list(APPEND PGSLibIface_SOURCE_FILES ${new_file_f90})
endforeach()


# --- Library
add_library(mylib ${F90Library_SOURCE_FILES})


When I try to build, the error I see is the following

  Preprocessing dir1/file1_module.F
  Preprocessing dir1/file2_module.F
  Preprocessing dir2/file3_module.F
  Preprocessing dir2/file4_module.F
  Scanning dependencies of target mylib
  Building Fortran object src/CMakeFiles/mylib.dir/file1_module.f90.o
make[2]: *** No rule to make target `src/file1_module.f90.provides', needed by `src/CMakeFiles/mylib.dir/file1_module.mod.proxy'.  Stop.
make[1]: *** [src/CMakeFiles/mylib.dir/all] Error 2
make: *** [all] Error 2

In the the CMakeFiles/mylib.dir/, I have the files

src/CMakeFiles/mylib.dir/file1_module.f90.o
src/CMakeFiles/mylib.dir/file1_module.f90.o.provides.build
src/CMakeFiles/mylib.dir/file1_module.mod.stamp

but nothing ending in *.provides or *.proxy. I assume these are files that CMake uses to construct the correct compile order for the modules.

I could flatten the directory structure, however I'd rather not do that and try to preserve the original file organization.

Thanks in advance for any help!




Lori A. Pritchett-Sheats
Los Alamos National Laboratory
CCS-2, Computational Physics
505-665-6675
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130513/5c2bad98/attachment.htm>


More information about the CMake mailing list