Change default CMakeLists.txt in CLion to include warnings

独自空忆成欢 提交于 2019-11-29 07:11:59

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

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

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

bin/cmake/share/cmake-3.2/Modules

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.

Save the file, reload you Cmake Project. Enjoy!

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

 

Probably a better solution:

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)

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!