cmake在linux上复制fortran模块失败

时间:2012-07-12 16:03:38

标签: linux cmake fortran

我有一个使用cmake构建的fortran代码构建。这目前在Mac OS X上运行,但是当我尝试在Linux上构建它时,它失败了。 Cmake成功生成了makefile,但是当我尝试运行makefile时,它在尝试复制模块时失败了。

顶级cmake文件是:

cmake_minimum_required (VERSION 2.8)

# Start Project and note the language used.
project (v3fit_suite Fortran)

# Set a directories to build all binary files.
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/bin)
set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/lib)

# Fortran specific settings. The first setting tells the compiler to use the C preprocessor. The second places a common directory to place all of the module files.
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp")
set (CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)

# List all the subdirectories these are in library dependancy order.
add_subdirectory (LIBSTELL)
add_subdirectory (VMEC2000)
add_subdirectory (V3FITA)
add_subdirectory (MAKEGRID)
add_subdirectory (V3POST)
add_subdirectory (V3RFUN)

应将所有模块复制到构建/模块。当我在Linux上运行带有VERBOSE = 1的Makefile时,我得到:

/usr/bin/cmake -H/home/user/reconstruction -B/home/user/reconstruction --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/user/reconstruction/CMakeFiles /home/user/reconstruction/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/user/reconstruction'
make -f LIBSTELL/CMakeFiles/stell.dir/build.make LIBSTELL/CMakeFiles/stell.dir/depend
make[2]: Entering directory `/home/user/reconstruction'
cd /home/user/reconstruction && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/user/reconstruction /home/user/reconstruction/LIBSTELL /home/user/reconstruction /home/user/reconstruction/LIBSTELL /home/user/reconstruction/LIBSTELL/CMakeFiles/stell.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/user/reconstruction'
make -f LIBSTELL/CMakeFiles/stell.dir/build.make LIBSTELL/CMakeFiles/stell.dir/requires
make[2]: Entering directory `/home/user/reconstruction'
make -f LIBSTELL/CMakeFiles/stell.dir/build.make LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o.provides.build
make[3]: Entering directory `/home/user/reconstruction'
/usr/bin/cmake -E cmake_progress_report /home/user/reconstruction/CMakeFiles 
[  0%] Building Fortran object LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o
cd /home/user/reconstruction/LIBSTELL && /usr/bin/f95  -o CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o  -cpp  -J../build/modules   -c /home/user/reconstruction/LIBSTELL/Sources/Modules/stel_kinds.f
/usr/bin/cmake -E cmake_copy_f90_mod build/modules/stel_kinds LIBSTELL/CMakeFiles/stell.dir/stel_kinds.mod.stamp GNU
Error copying Fortran module "build/modules/stel_kinds".  Tried "build/modules/STEL_KINDS.mod" and "build/modules/stel_kinds.mod".
make[3]: *** [LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o.provides.build] Error 1
make[3]: Leaving directory `/home/user/reconstruction'
make[2]: *** [LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o.provides] Error 2
make[2]: Leaving directory `/home/user/reconstruction'
make[1]: *** [LIBSTELL/CMakeFiles/stell.dir/all] Error 2
make[1]: Leaving directory `/home/user/reconstruction'
make: *** [all] Error 2

当使用gfortran作为我的编译器而不是f95时,我遇到了同样的问题。为什么这适用于Mac OS X但在Linux上失败?在Mac OS X上,我安装了2.8.8版本的cmake,在Linux版本2.8上。

1 个答案:

答案 0 :(得分:0)

原来有一个看似无关的错误导致了这个问题。我有一些声明要添加一个空的包含路径。

find_library (NETCDF_F netcdff PATHS ${NETCDF_LIB_PATH})
find_file (NETCDF_I netcdf.inc ${NETCDF_INC_PATH})
if (NETCDF_C AND NETCDF_F AND NETCDF_I)
    message (STATUS "Using netcdf")
    set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -D NETCDF -I ${NETCDF_INC_PATH}")
endif ()

即使'NETCDF_INC_PATH'为空,if语句也总是如此。这导致编译器命令行中出现了一个额外的-I,这使得一切都搞砸了。