[Cmake] CMAKE_BUILD_TYPE, Makefiles, and MSVC

Brad King brad.king at kitware.com
Tue Jul 13 17:49:09 EDT 2004


paul. wrote:
> Hello CMakers,
> 
> When using the command line client, the CMAKE_BUILD_TYPE does an 
> excellent job of emulating MSVC's build types. I can make a subfolder 
> DEBUG or RELEASE or what have you, and the build of that type will go 
> into that folder. Very handy, because we need to keep different types of 
> builds around.
> 
> That is, if I have:
> IF(CMAKE_BUILD_TYPE MATCHES Release)
>     SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/RELEASE)
> ENDIF(CMAKE_BUILD_TYPE MATCHES Release)
> IF(CMAKE_BUILD_TYPE MATCHES Debug)
>     SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/DEBUG)
> ENDIF(CMAKE_BUILD_TYPE MATCHES Debug)
> 
> I get my binaries put in the appropriate place, either 
> ${PROJECT_BINARY_DIR}/RELEASE or ${PROJECT_BINARY_DIR}/DEBUG.
> 
> 
> However, we also have windows developers using MSVC. If they run cmake 
> and then build, they get
> ${PROJECT_BINARY_DIR}/DEBUG/Release
> ${PROJECT_BINARY_DIR}/DEBUG/Debug
> ${PROJECT_BINARY_DIR}/RELEASE/Release
> ${PROJECT_BINARY_DIR}/RELEASE/Debug
> 
> 
> I understand that MSVC is operating on a post-cmake-run build style, 
> while I need to regenerate my cmake cache to have the same effect on 
> Makefile targets. Is there some way to unify this behavior? To be able 
> to 'make Debug' and 'make Release' from the commandline (having the 
> Makefile emulate MSVC), OR to be able to only have one build style in 
> MSVC until the cache is regenerated (having MSVC emulate the Makefile)? 
> Because of the (very large) amount of media that we need to copy, and 
> the different libraries we need to link in depending on this type, it 
> would be handy to not have to special case windows builds.
> 
> - paul
> 
> ps - the CMAKE_BUILD_TYPE 'None' has come in handy already; interesting 
> option!

CMake tries to generate native build systems that work as expected by 
users of that build system.

When using a visual studio generator the intention is to have the 
configuration selected at build-time just as in native visual studio 
projects.

When using a makefile generator the intention is to have only one build 
configuration for that tree...either "Debug" or "Release".  This 
configuration is chosen by CMAKE_BUILD_TYPE.  Your 
EXECUTABLE_OUTPUT_PATH trick does not work as well as you think because 
there are not separate .obj files compiled for each configuration (so 
you are getting mixed libraries).

You will have to create separate build trees for each configuration you 
want to build using makefiles.  Yes this means separate runs of cmake. 
You cannot create a "make Debug" or "make Release" target in the current 
implementation.  Something like this would require a new makefile 
generator to be written.  The current generator follows the UNIX 
(autotools) convention of one configuration per build tree.

-Brad


More information about the Cmake mailing list