使用星号更改多个源文件的CMake编译器标志 [英] Changing CMake compiler flags for multiple source files using asterisks

查看:121
本文介绍了使用星号更改多个源文件的CMake编译器标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试与编译器优化相关的问题(-O2或更低版本没有问题,-O3则存在segfault),并且我希望能够为我的大部分源代码切换编译器标志,所以我可以尝试缩小段错误的来源。

I'm trying to debug a problem related to compiler optimisation (no issue with -O2 or below, segfault with -O3) and I'd like to be able to switch the compiler flags for a chunk of my source so I can try to narrow down where the segfault is coming from.

我可以将全局优化级别设置为-O2,并为单个文件更改属性,如下所示:

I can do this setting the global optimisation level to -O2, and altering the PROPERTIES for single files like so:

SET_SOURCE_FILES_PROPERTIES(file1.f90 PROPERTIES COMPILE_FLAGS -O3)

但是,例如,当我尝试使用* .f90对多个文件执行此操作时,似乎不起作用:

However, when I try to do this for multiple files using *.f90 for example, it seems to not work:

SET_SOURCE_FILES_PROPERTIES(*.f90 PROPERTIES COMPILE_FLAGS -O3)

有没有办法针对多个文件执行此操作而不用按名称指定每个文件?

Is there any way to do this for multiple files without specifying every file by name?

推荐答案

您可以全局以获取文件列表:

You can glob for a list of files:

file(GLOB MyFiles *.f90)
set_property(SOURCE ${MyFiles} PROPERTY COMPILE_FLAGS -O3)

或者,您可以设置 COMPILE_FLAGS 目标属性。通常,用与同一目标中的其他文件不同的编译标志来编译某些源文件没有太大意义。因此,除非您有充分的理由针对每个文件执行此操作,否则应始终使用目标属性。

Alternatively, you could set the COMPILE_FLAGS target property of the respective target instead. Usually, it does not make much sense to compile certain source files with different compile flags than others within the same target. So unless you have good reason to do this on a per-file basis, you should always use the target properties instead.

这篇关于使用星号更改多个源文件的CMake编译器标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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