[CMake] select debug or optimized at make time instead of at cmake time

Brad King brad.king at kitware.com
Fri Oct 6 09:27:22 EDT 2006


Richard Fuchs wrote:
> Is there a way to be able to select if the build will be debug or
> optimized at make time instead of during cmake time?
> 
> So, I can SET(CMAKE_BUILD_TYPE Debug) or SET(CMAKE_BUILD_TYPE Release)
> for debug or optimized code respectively, then when I run make, the
> corresponding compiler flags are set.  What I'd like to be able to do is
> have it so that when I run 'make', it uses debug flags and when a run
> something like 'make release', it'll use the optimize flags.  Is
> something like this possible?

Not with the current Makefile generators.  The Xcode and Visual Studio
generators do this because the native tools support multiple
configurations chosen at build time.  The current Makefile generator
design is single-configuration only, so CMAKE_BUILD_TYPE is used to
select which one to build.

You might be able to fake it by having a tiny top level CMakeLists.txt
file that just contains custom targets called "debug" and "release" that
use ctest --build-and-test to drive builds of a sub-project setting
CMAKE_BUILD_TYPE to debug or release respectively.

-Brad


More information about the CMake mailing list