CMake的其他调试选项 [英] CMake additional Debug Options

查看:108
本文介绍了CMake的其他调试选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用调试符号编译代码时,我通常还希望启用某些编译时和运行时检查,例如:

  gfortran -c -o hello.o -g -O0 -Wall -fcheck-all -fbacktrace hello.f90 

(是的,它是Fortran,但我认为它可以与其他语言一样使用。)



如果我想使用英特尔Fortran编译器,命令如下所示:

  ifort -c -o hello.o -g -O0 -warn all -check all -traceback hello.f90 

在CMake中这样编译的唯一方法是到目前为止发现的内容是这样的:

  IF($ {CMAKE_Fortran_COMPILER_ID} MATCHES GNU)
set(CMAKE_Fortran_FLAGS_DEBUG $ {CMAKE_Fortran_FLAGS_DEBUG} -Wall -fcheck = all -fbacktrace)
ELSEIF($ {CMAKE_Fortran_COMPILER_ID} MATCHES Intel)
set(CMAKE_Fortran_FLAGS_DEBUG $ {CMAKE_Fortran_FLAGS_nBcheck- ll -traceback)
ELSE()
消息(警告无法确定编译器ID:$ {CMAKE_Fortran_COMPILER_ID})
ENDIF($ {CMAKE_Fortran_COMPILER_ID}匹配 GNU)

但这引入了我在开始使用CMake时要避免的所有硬编码标志。有没有一种方法可以根据其操作来添加编译器开关,例如启用所有编译时警告或启用所有运行时检查?

解决方案

CMake警告API:即将推出。 / p>

该讨论提出了以下命令,例如 add_compile_warnings target_compile_warnings add_compile_options 的模型 target_compile_definitions ,警告级别例如:




  • all(编译器专有的 all,例如/ Wall或-Wall) ;

  • 默认值;

  • 无;

  • 所有(如果没有,则为编译器提供所有可能的警告)该选项使用最大级别p



您可以研究建议的API并在讨论中暴露您不满意的需求。


When compiling code with debug symbols, I usually also want to enable certain compile-time and run-time checks, like so:

gfortran -c -o hello.o -g -O0 -Wall -fcheck-all -fbacktrace hello.f90

(Yes, it's Fortran, but I assume that it'd work with other languages just the same.)

If I wanted to compile the same with the Intel Fortran Compiler, the command would look like this:

ifort -c -o hello.o -g -O0 -warn all -check all -traceback hello.f90

The only way to compile like this in CMake that I have found so far is something like this:

IF(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")
    set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -Wall -fcheck=all -fbacktrace")
ELSEIF(${CMAKE_Fortran_COMPILER_ID} MATCHES "Intel")
    set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -warn all -check all -traceback")
ELSE()
    message(WARNING "Unable to determine Compiler ID: ${CMAKE_Fortran_COMPILER_ID}")
ENDIF(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU")

But this introduces all the hardcoded flags that I wanted to avoid when starting to use CMake. Is there a way to add compiler switches based on what they do, like "Enable all Compile time Warnings" or "Enable all Runtime Checks"?

解决方案

CMake warning API: coming soon.

The discussion proposes commands like add_compile_warnings or target_compile_warnings, following the model of add_compile_options and target_compile_definitions, with warning levels such as:

  • all (compiler specific "all", e.g. /Wall or -Wall);
  • default;
  • none;
  • everything (all possible warnings for compiler, if there is no such option use maximum level plus some warnings explicitly).

You may study the proposed API and perhaps expose your unsatisfied needs in the discussion.

这篇关于CMake的其他调试选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆