Does anyone how to see which build flags are used by CMake with gcc in debug and release configuration by default?
Asked
Active
Viewed 1,219 times
0
-
Related ["Which variable for compiler flags of CMake's ADD_LIBRARY function?"](https://stackoverflow.com/questions/42696024/which-variable-for-compiler-flags-of-cmakes-add-library-function). It really depends on the platform/compiler you are using. So you have to run a CMake "hello world" project to see what is used. – Florian Jul 03 '18 at 09:05
-
1The defaults are defined in [`Modules/Compiler/GNU.cmake`](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Compiler/GNU.cmake#L43) – Florian Jul 03 '18 at 09:09
-
If one of the answers below fixes your issue, you should accept it (click the check mark next to the appropriate answer). That does two things. It lets everyone know your issue has been resolved to your satisfaction, and it gives the person that helps you credit for the assist. [See here](http://meta.stackexchange.com/a/5235) for a full explanation. – hellow Jul 04 '18 at 06:27
2 Answers
2
There is cmake-gui, which will print you all variables which are used in your current project.
If you are in the process of building, you can execute
make VERBOSE=1
to see the actual commands (including the flags of course)

hellow
- 12,430
- 7
- 56
- 79
1
Turning my comments into an answer
The defaults for GNU are defined in Modules/Compiler/GNU.cmake
:
# Initial configuration flags. string(APPEND CMAKE_${lang}_FLAGS_INIT " ") string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG") string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
But the rest really depends on the platform/compiler you are using. So you have to run a CMake "hello world" project to see what is used (see @hellow's answer).
Referencess

Florian
- 39,996
- 9
- 133
- 149