【问题标题】:CMake not recognizing FORTRAN source in mixed C++/FORTRAN programCMake 无法识别混合 C++/FORTRAN 程序中的 FORTRAN 源
【发布时间】:2015-04-10 17:39:59
【问题描述】:

我正在将我的一个项目转移到我曾经使用自动工具(autoconf、automake 等)的 CMake(因为语法简单)。我遇到了一个小问题,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 代码。在 autotools 中,这不是问题。此外,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

【问题讨论】:

    标签: c++ cmake fortran


    【解决方案1】:

    尝试将 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)
    

    【讨论】:

    • 这正是我所需要的,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    相关资源
    最近更新 更多