尽管声称cmake如此出色,但它的文档似乎还有很多不足(除非我完全不了解基本知识)。
我试图为一组也依赖于其他库的fortran程序编写cmake文件(这些库已经为我的系统编译,但是我也想为这些库制作cmake文件)。
我在在线示例中找到的许多命令都没有出现在官方文档中,这有点令人不安。例如,http: //www.vtk.org/Wiki/CMakeForFortranExample 包含以下行
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
Run Code Online (Sandbox Code Playgroud)
但是当我将其包含在自己的CMakeLists.txt中时,出现错误
Missing variable is:
CMAKE_fortran_COMPILER
Run Code Online (Sandbox Code Playgroud)
我想念什么?!
编辑:当前CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
enable_language(fortran)
project(fortranTest)
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
Run Code Online (Sandbox Code Playgroud)
编辑2
我仍然没有弄清楚如何包括依赖库。
语言名称区分大小写。发布后,我得到:
~/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
Run Code Online (Sandbox Code Playgroud)
但是,通过将文件改为(注意它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)
Run Code Online (Sandbox Code Playgroud)
你得到:
~/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
Run Code Online (Sandbox Code Playgroud)
如果允许完成,它将按预期工作。但是,为了确定编译器标志,有更好的方法来标识编译器。在引用的示例中使用的方法仅适用于未包装编译器的系统,这意味着不会通过Cray mpif90
或ftn
Cray 调用编译器的系统。更好的方法是检查:
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
...
endif()
Run Code Online (Sandbox Code Playgroud)
可以通过检查CMake模块目录中的文件找到可能的名称列表。 Modules/CMakeFortranCompilerId.F.in
归档时间: |
|
查看次数: |
17787 次 |
最近记录: |