CMake 无法识别混合 C++/FORTRAN 程序中的 FORTRAN 源

CMake not recognizing FORTRAN source in mixed C++/FORTRAN program

本文关键字:FORTRAN 程序 C++ 识别 混合 CMake      更新时间:2023-10-16

我正在将我的一个项目转移到CMake(因为语法的简单性),我曾经使用过自动工具(autoconf,automake等)。我遇到了一个小问题,CMake 没有意识到我的源代码树中有 FORTRAN 代码。

我构建的一个库依赖于C++和FORTRAN源代码。我使用以下语法来构建库

add_library(matrix
  double/matrix_constructor_double.cpp
  double/matrix_io_double.cpp
  double/matrix_miscmath_double.cpp
  double/matrix_miscop_double.cpp
  double/matrix_overload_double.cpp
  double/matrix_setters_double.cpp
  double/eigsrt_double.f
  double/pkconv_double.f)

CMake 运行良好,但是当我尝试制作项目时,我得到以下结果:

Scanning dependencies of target matrix
[ 45%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_constructor_double.cpp.o
[ 50%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_io_double.cpp.o
[ 54%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_miscmath_double.cpp.o
[ 59%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_miscop_double.cpp.o
[ 63%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_overload_double.cpp.o
[ 68%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_setters_double.cpp.o

它只是完全忽略了我指定了 FORTRAN 代码。在自动化工具中,这不是问题。此外,CMake 也不承认我有 FORTRAN 代码,即

-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dbwy/git_repo/chronusq/build

如果我尝试手动指定 FORTRAN 编译器,我会得到以下内容

CMake Warning:
  Manually-specified variables were not used by the project:
    CMAKE_Fortran_COMPILER

我的CMake中是否缺少一些与FORTRAN一起使用的功能?我正在使用 cmake 3.0.2

尝试将 Fortran 指定为 cmake 项目的语言。默认情况下,仅启用 C 和 C++:

(可选)可以指定项目支持的语言。示例语言有C,CXX(即C++),Fortran等。默认情况下,如果未提供语言选项,则启用 C 和 CXX。指定语言 NONE,或使用 LANGUAGES 关键字并列出任何语言,以跳过启用任何语言。

http://www.cmake.org/cmake/help/v3.2/command/project.html

像这样:

project(foo C CXX Fortran)