I'm using CMake on windows with the Windows SDK and NMake Makefiles.
By default it compiles with the /MD
compiler switch.
How can I change it to compile with the /MT
switch instead?
Once you have edited the CMakeCache. txt file you rerun cmake, repeat this process until you are happy with the cache settings. The type make and your project should compile. Some projects will have install targets as well so you can type make install to install them.
So, what is the real difference? CMake is much more high-level. It's tailored to compile C++, for which you write much less build code, but can be also used for general purpose build. make has some built-in C/C++ rules as well, but they are useless at best.
CMake does check for the compiler ids by compiling special C/C++ files. So no need to manually include from Module/Compiler or Module/Platform . This will be automatically done by CMake based on its compiler and platform checks.
CMAKE_C_COMPILER holds the name of the compiler. In general cmake uses this script to find the compiler.
You can modify the CMAKE_CXX_FLAGS_<Build Type>
and/or CMAKE_C_FLAGS_<Build Type>
variables:
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
If your CMake flags already contain /MD
, you can ensure that the above commands are executed after the point at which /MD
is inserted (the later addition of /MT
overrides the conflicting existing option), or you can set the flags from scratch:
set(CMAKE_CXX_FLAGS_RELEASE "/MT") set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
Or alternatively, you could replace the existing /MD
and /MDd
values with /MT
and /MTd
respectively by doing something like:
set(CompilerFlags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE ) foreach(CompilerFlag ${CompilerFlags}) string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") endforeach()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With