configure_msvc.cmake 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. macro(configure_msvc_runtime)
  2. if(MSVC)
  3. # Default to statically-linked runtime.
  4. if("${MSVC_RUNTIME}" STREQUAL "")
  5. set(MSVC_RUNTIME "static")
  6. endif()
  7. # Set compiler options.
  8. set(variables
  9. CMAKE_C_FLAGS_DEBUG
  10. CMAKE_C_FLAGS_MINSIZEREL
  11. CMAKE_C_FLAGS_RELEASE
  12. CMAKE_C_FLAGS_RELWITHDEBINFO
  13. CMAKE_CXX_FLAGS_DEBUG
  14. CMAKE_CXX_FLAGS_MINSIZEREL
  15. CMAKE_CXX_FLAGS_RELEASE
  16. CMAKE_CXX_FLAGS_RELWITHDEBINFO
  17. )
  18. if(${MSVC_RUNTIME} STREQUAL "static")
  19. message(STATUS
  20. "MSVC -> forcing use of statically-linked runtime."
  21. )
  22. foreach(variable ${variables})
  23. if(${variable} MATCHES "/MD")
  24. string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
  25. endif()
  26. endforeach()
  27. else()
  28. message(STATUS
  29. "MSVC -> forcing use of dynamically-linked runtime."
  30. )
  31. foreach(variable ${variables})
  32. if(${variable} MATCHES "/MT")
  33. string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
  34. endif()
  35. endforeach()
  36. endif()
  37. endif()
  38. endmacro()