语言名称区分大小写。如发布的那样,我得到:
~/cmt> cmake ./
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_fortran_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_fortran_COMPILER
CMake Error: Could not find cmake module file:/home/tgallagher/cmt/CMakeFiles/CMakefortranCompiler.cmake
CMake Error: Could not find cmake module file:CMakefortranInformation.cmake
CMake Error: CMAKE_fortran_COMPILER not set, after EnableLanguage
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- 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
^C
但是,通过将文件更改为(注意它是Fortran
而不是fortran
在enable_language()
:
cmake_minimum_required(VERSION 2.6)
enable_language(Fortran)
project(fortranTest)
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
你得到:
~/cmt> cmake ./
-- The Fortran compiler identification is GNU
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
^C
如果允许完成,它将按预期工作。但是,为了确定编译器标志,有更好的方法来识别编译器。引用示例中使用的方法仅适用于未包装编译器的系统,这意味着不通过 Cray 之类的方法mpif90
或ftn
在 Cray 上调用编译器的系统。更好的方法是检查:
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
...
endif()
通过检查 CMake 模块目录中的文件可以找到可能的名称列表Modules/CMakeFortranCompilerId.F.in