Search code examples
cmakemsvcrtlibmysql

Why does this CMake project not set the appropriate MSVC runtime?


I'm trying to understand why the libmysql CMake project configured with /MD and /MDd flags does not generate the appropriate Visual Studio 10 project files. The appropriate CMAKE_ macros have been configured, as shown:

macros

Yet the generated projects are still showing unexpected Runtime Library settings:

enter image description here

Is the CMake GUI for some reason unreliable, or is it possible that another option is overriding the CRT settings?


Solution

  • I found that the cmake project for libmysql has an OS-specific cmake file for Windows which forces static runtimes to be used when generating the Visual Studio solution:

     75   # Force static runtime libraries
     83   FOREACH(flag
     84    CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
     85    CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
     86    CMAKE_CXX_FLAGS_RELEASE  CMAKE_CXX_FLAGS_RELWITHDEBINFO
     87    CMAKE_CXX_FLAGS_DEBUG  CMAKE_CXX_FLAGS_DEBUG_INIT)
     88    STRING(REPLACE "/MD"  "/MT" "${flag}" "${${flag}}")
     89    SET("${flag}" "${${flag}} /EHsc")
     98   ENDFOREACH()