Can Cmake generate a single makefile that supports both debug and release

c, c++, cmake

Solution

As far as I know, this cannot be achieved using a single set of build scripts. However, what you can do is have two sub-directories of your working area:

build/
build/debug
build/release

Then do:

$ cd build
$
$ cd build/debug
$ cmake -DCMAKE_BUILD_TYPE=Debug ../..
$ make
$
$ cd ../release
$ cmake -DCMAKE_BUILD_TYPE=Release ../..
$ make

If necessary, you can add another build script in the `build` directory as such:

#!/bin/sh
cd debug   && make && cd ..
cd release && make && cd ..

Problem

It seems like we need to create separate folder for each build type (debug/release), run cmake on each, and generate separate makefile for debug/release configuration. Is it possible to create one single makefile using cmake that supports both debug/release configuration at the same time and when we actually run "make" that will create separate folders for the intermediate and final products (like the dlls, exe).

Original source

Related problems