简体   繁体   中英

How to customize vcxproj generation by CMake

I want to use CMake to generate.vcxproj files. Then I open specific project/solution and work in VS as usual. How do I customize default configurations, generated by VS generator? In particular, how do I specify in my cmake files (whatever it should be) that I need release runtime for "Debug" configuration? (ie /MD instead of /MDd).

As far as I understand, such an option is VS-specific (VS/MSBuild flag) and thus is not manupulated my CMake naturally.

In particular, how do I specify in my cmake files (whatever it should be) that I need release runtime for "Debug" configuration? (ie /MD instead of /MDd).

This will work:

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
    CACHE STRING "MSVC runtime library selection")

Then all of the targets you build in all configurations will use -MD . See the documentation here: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html

The default value is MultiThreaded$<$<CONFIG:Debug>:Debug>DLL which uses -MDd for the Debug configuration and -MD for all others. This uses generator expressions , which are out of scope for this question.


An alternative: you can lean in to CMake's defaults and use the RelWithDebInfo build config. If you need to override the optimization flags, you can always set CMAKE_CXX_FLAGS_RELWITHDEBINFO .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM