[CMake] How to support separate debug and release build directories?

Braden McDaniel braden at endoframe.com
Fri Jun 21 10:47:19 EDT 2019


On Fri, 2019-06-21 at 15:28 +0100, David Aldrich wrote:
> > > I would also like this to work if I use the make targets e.g.
> > make
> > > debug.
> > 
> > I think that's outside the scope of the Makefile generator.  For
> > that
> > generator, CMAKE_BUILD_TYPE is a configuration-wide setting.  If
> > you
> > want a different configuration, you need a different build
> > directory
> > (where "build directory" is wherever you run cmake).
> 
> If I don't use make targets (so that user can type 'make debug' etc)
> the build command would be more cumbersome:
> 
> cmake3 --build -D CMAKE_BUILD_TYPE=Debug .

Assuming that command actually triggers a reconfigure (when previously
configured with a different CMAKE_BUILD_TYPE), you'll most likely hose
incremental builds of the other build type(s).  (And if it doesn't
trigger a reconfigure in that case, it's pretty certainly not doing
what you want.)

> What would best practice be to provide convenient commands for our
> developers to easily build the target ?

For the Makefile generator, best practice is to use separate build
directories (i.e., places where you run cmake) for different
configurations (i.e., different settings recorded during the
configuration step).

If you want to provide developers with some known set(s) of
configuration settings, I suggest wrapper scripts that invoke cmake
with those settings.

-- 
Braden McDaniel <braden at endoframe.com>



More information about the CMake mailing list