[CMake] Force MSVC runtime for debug builds

Stephan Menzel stephan.menzel at gmail.com
Mon Nov 7 03:37:15 EST 2016


Hello everyone,

I'm looking for a way to force Debug configurations in generated MSVC
solutions to use the Release runtime instead of the default "Debug". e.g.
/MD rather than /MDd.

My use case is an ever recurring problem of creating libraries that are
linked in plug-in fashion against Release only applications. I want for my
Debug configuration to have debug info and no optimization but still use
the release runtime so I can link them.

I tried replacing /MDd with /MD in CMAKE_CXX_FLAGS_DEBUG. This yielded
objects built with /MD alright but failed to link into an executable with
stuff like that:

error LNK2038: mismatch detected for 'RuntimeLibrary': value
'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in Test.obj

>From what I gather all the obj are actually compiled for Release runtime
without optimization and Debug info just like I need it. But then the main
obj is built and linked in Debug mode, causing the executable to not be
created.

Is there a way to solve this? Like a generic CMake executable flag or
something that I can use to force the other runtime?

Please note that using RelWithDebInfo and turning off optimization is not
exactly what I need as I still want that mode much the way it is.

Cheers,
Stephan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161107/7a17715d/attachment.html>


More information about the CMake mailing list