<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">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.<br>
<br>
The package has a directory structure<br>
<br>
src/<br>
src/dir1<br>
src/dir2<br>
:<br>
:<br>
<br>
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. <br>
<br>
Here's my CMakeLists.txt snippet in the src directory<br>
<br>
<br>
set(DIR1_FILES dir1/file1_module.F dir2/file2_module.F)<br>
set(DIR2_FILES dir2/file3_module.F dir2/file4_module.F)<br>
set(F_PREPROCESS_FILES ${DIR1_FILES} ${DIR2_FILES})<br>
<br>
<br>
set(F90Library_SOURCE_FILES)<br>
foreach (src_file ${F_PREPROCESS_FILES})<br>
<br>
get_filename_component(filename "${src_file}" NAME_WE)<br>
set(F_file ${CMAKE_CURRENT_SOURCE_DIR}/${src_file})<br>
set(new_file_f90 ${CMAKE_CURRENT_BINARY_DIR}/${filename}.f90)<br>
message(STATUS "new_file_f90=${new_file_f90}")<br>
<br>
add_custom_command(OUTPUT "${new_file_f90}"<br>
COMMAND ${CMAKE_C_COMPILER} -E ${CMAKE_CPP_FLAGS} ${F_file} ${grep_filter} | grep -v \\!\\!CPP\\!\\! | grep -v ^\# > ${new_file_f90}<br>
IMPLICIT_DEPENDS Fortran "${F_file}"<br>
COMMENT "\tPreprocessing ${src_file}"<br>
VERBATIM)<br>
list(APPEND PGSLibIface_SOURCE_FILES ${new_file_f90}) <br>
endforeach()<br>
<br>
<br>
# --- Library<br>
add_library(mylib ${F90Library_SOURCE_FILES})<br>
<br>
<br>
When I try to build, the error I see is the following<br>
<br>
Preprocessing dir1/file1_module.F<br>
Preprocessing dir1/file2_module.F<br>
Preprocessing dir2/file3_module.F<br>
Preprocessing dir2/file4_module.F<br>
Scanning dependencies of target mylib<br>
Building Fortran object src/CMakeFiles/mylib.dir/file1_module.f90.o<br>
make[2]: *** No rule to make target `src/file1_module.f90.provides', needed by `src/CMakeFiles/mylib.dir/file1_module.mod.proxy'. Stop.<br>
make[1]: *** [src/CMakeFiles/mylib.dir/all] Error 2<br>
make: *** [all] Error 2<br>
<br>
In the the CMakeFiles/mylib.dir/, I have the files<br>
<br>
src/CMakeFiles/mylib.dir/file1_module.f90.o<br>
src/CMakeFiles/mylib.dir/file1_module.f90.o.provides.build<br>
src/CMakeFiles/mylib.dir/file1_module.mod.stamp<br>
<br>
but nothing ending in *.provides or *.proxy. I assume these are files that CMake uses to construct the correct compile order for the modules.<br>
<br>
I could flatten the directory structure, however I'd rather not do that and try to preserve the original file organization.
<br>
<br>
Thanks in advance for any help!<br>
<br>
<br>
<br>
<div><br>
<div style="font-family:Tahoma; font-size:13px">Lori A. Pritchett-Sheats
<div>Los Alamos National Laboratory</div>
<div>CCS-2, Computational Physics</div>
<div>505-665-6675</div>
</div>
</div>
</div>
</body>
</html>