与cmake声称一样好,它的文档似乎还有很多不足之处(除非我完全没有理解基础知识)。
我正在尝试为一组fortran程序编写一个cmake文件,这些程序也依赖于其他一些库(已经为我的系统编译,但我也想为这些库创建一个cmake文件)。 / p>
我在网上示例中找到的很多命令都没有出现在官方文档中,这有点令人不安......例如,http://www.vtk.org/Wiki/CMakeForFortranExample包含行
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
然而,当我在我自己的CMakeLists.txt中包含它时,我收到错误
Missing variable is:
CMAKE_fortran_COMPILER
我缺少什么?!
编辑:当前CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
enable_language(fortran)
project(fortranTest)
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
修改2
我还没有弄清楚如何包含依赖库。
答案 0 :(得分:4)
语言名称区分大小写。发布后,我得到:
~/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
调用编译器。更好的方法是检查:
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
...
endif()
可以通过检查CMake Module目录中的文件找到可能的名称列表Modules/CMakeFortranCompilerId.F.in