更改CLion中的默认CMakeLists

更改CLion中的默认CMakeLists

本文介绍了更改CLion中的默认CMakeLists.txt以包括警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CLion中,默认的CMakeLists.txt仅设置C ++ 11编译器标志。

In CLion the default CMakeLists.txt sets the C++11 compiler flag only. I'd like to have warnings and the pedantic flag by default in all my projects.

这是默认情况下

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

并且我想默认情况下是这样,所以我不需要每次创建一个新项目时改变它。

and I'd like to have this by default so I don't have to change it every time I create a new project

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra -pedantic")

在设置 - 文件和代码模板中,我可以更改C ++头/源模板,但不能更改CMakeLists.txt模板。有没有什么办法我可以改变默认的CMakeLists.txt模板在CLion?

In the "Settings" - "File and Code Templates" I can change the C++ header/source template but not the CMakeLists.txt template. Is there any way I can change the default CMakeLists.txt template in CLion?

推荐答案

注意,这不能通过编辑CmakeLists.txt!

Be careful that this cannot be overridden by editing the CmakeLists.txt!

此外,我建议制作有问题的文件的备份副本。

Also I recommend making a backup copy of the file in question.

转到安装/解压缩CLion
,然后

Go to the location where you've installed/unzipped CLionand then

bin/cmake/share/cmake-3.2/Modules

并查找名为CMakeCXXInformation.cmake的文件

and look for the file named "CMakeCXXInformation.cmake"

在这种模式下只需写入/粘贴你的标志:

There just write/paste your flags following this model:

#This should be my default compiler flags
SET(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Werror -Wextra -pedantic -
Wshadow -Woverloaded-virtual -Winvalid-pch -Wcast-align -Wformat=2 -
Wformat-nonliteral -Wmissing-declarations -Wmissing-format-attribute -
Wmissing-include-dirs -Wredundant-decls -Wswitch-default")

您可以随意写入/粘贴到文件的顶部/底部。

You can write/paste this wherever you'd like - top/bottom of the file.

保存文件,重新加载你Cmake项目。享受!

Save the file, reload you Cmake Project. Enjoy!

(可以忽略/删除CmakeList.txt中设置的编译器标记行)

(The line with the compiler flags set in CmakeList.txt can be ignored/deleted)

 

可能是更好的解决方案:

由Intellij的任何产品支持,我认为最好的解决方案,如果你想代码仍然是可移植的是使用[实时模板]()

Since this doesn't seem to be supported by any of Intellij's products, I think the best solution, if you want the code to still be portable is to use a [live template] (https://www.jetbrains.com/idea/help/live-templates.html)

我现在使用一个名为flags的活动模板,其中我刚刚粘贴了我常用的标志和一些其他代码tidbits。
所以每当我在CMakeLists.txt中,我可以键入标志,然后按Tab键展开该文本。
你当然可以有很多版本的标志,并为它们使用活动模板将减轻每次都必须单独键入它们的负担。

I now use a live template called flags in which I just pasted my commonly used flags and also some other code tidbits.So whenever I am in CMakeLists.txt i can type flags and then press Tab to expand that text.You could of course have many versions of flags and using live templates for them will ease the burden of having to type them individually every time.

这篇关于更改CLion中的默认CMakeLists.txt以包括警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:06