How to create cmake build configuration without de

2019-05-30 15:51发布

问题:

I think default configuration types one can describe like this:

Debug          : w/ debug symbols, w/o optimization
Release        : w/o debug symbols, w/ optimization
RelWithDebInfo : w/ debug symbols, w/ optimization
MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries

But I need new one:

MyConf         : w/o debug symbols, w/o optimization

So, how to create it?

回答1:

About table

Configurations in terms of gcc/clang compilers (CMake 3.4.1):

  • Debug: -g
  • Release: -O3 -DNDEBUG
  • RelWithDebInfo: -O2 -g -DNDEBUG
  • MinSizeRel: -Os -DNDEBUG

It means:

  +---------------+--------------+--------------+----------+
  |               | optimization | assert works | stripped |
  +---------------+--------------+--------------+----------|
  |     Debug     |     no       |     yes      |    no    |
  |    Release    |    full      |      no      |   yes    |
  | RelWithDebInfo|    good      |      no      |    no    |
  |   MinSizeRel  |    size      |      no      |   yes    |
  +---------------+--------------+--------------+----------+

So I don't agree with your MinSizeRel description because in this case I think both MinSizeRel and Release are stripped.

About question

As far as I understand you want no extra flags at all (no -g, -O* or -DNDEBUG). For Makefile-like generators:

> cmake -H. -B_builds -DCMAKE_BUILD_TYPE=MyConf -DCMAKE_CXX_FLAGS_MYCONF=""
> cmake --build _builds

For generators like Visual Studio you need to use CMAKE_CONFIGURATION_TYPES (see this answer):

> cmake -H. -B_builds -DCMAKE_CONFIGURATION_TYPES="Release;Debug;RelWithDebInfo;MinSizeRel;MyConf" -DCMAKE_CXX_FLAGS_MYCONF="/Od" -DCMAKE_EXE_LINKER_FLAGS_MYCONF=""
> cmake --build _builds --config MyConf


标签: c++ cmake