CMakeDetermineVSServicePack.cmake 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # - Includes a public function for assisting users in trying to determine the
  2. # Visual Studio service pack in use.
  3. #
  4. # Sets the passed in variable to one of the following values or an empty
  5. # string if unknown.
  6. # vc80
  7. # vc80sp1
  8. # vc90
  9. # vc90sp1
  10. #
  11. # Usage:
  12. # ===========================
  13. #
  14. # if(MSVC)
  15. # include(CMakeDetermineVSServicePack)
  16. # DetermineVSServicePack( my_service_pack )
  17. #
  18. # if( my_service_pack )
  19. # message(STATUS "Detected: ${my_service_pack}")
  20. # endif()
  21. # endif()
  22. #
  23. # ===========================
  24. #=============================================================================
  25. # Copyright 2009-2010 Kitware, Inc.
  26. # Copyright 2009-2010 Philip Lowman <[email protected]>
  27. #
  28. # Distributed under the OSI-approved BSD License (the "License");
  29. # see accompanying file Copyright.txt for details.
  30. #
  31. # This software is distributed WITHOUT ANY WARRANTY; without even the
  32. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  33. # See the License for more information.
  34. #=============================================================================
  35. # (To distribute this file outside of CMake, substitute the full
  36. # License text for the above reference.)
  37. # [INTERNAL]
  38. # Please do not call this function directly
  39. function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version)
  40. if (${_cl_version} VERSION_EQUAL "14.00.50727.42")
  41. set(_version "vc80")
  42. elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
  43. set(_version "vc80sp1")
  44. elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
  45. set(_version "vc90")
  46. elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
  47. set(_version "vc90sp1")
  48. elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01")
  49. set(_version "vc100")
  50. else()
  51. set(_version "")
  52. endif()
  53. set(${_OUT_VAR} ${_version} PARENT_SCOPE)
  54. endfunction()
  55. #
  56. # A function to call to determine the Visual Studio service pack
  57. # in use. See documentation above.
  58. function(DetermineVSServicePack _pack)
  59. if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
  60. file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
  61. "int main() { return 0; }\n")
  62. try_compile(DETERMINED_VS_SERVICE_PACK
  63. "${CMAKE_BINARY_DIR}"
  64. "${CMAKE_BINARY_DIR}/return0.cc"
  65. OUTPUT_VARIABLE _output
  66. COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
  67. file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
  68. if(DETERMINED_VS_SERVICE_PACK AND _output)
  69. string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
  70. _cl_version "${_output}")
  71. if(_cl_version)
  72. string(REGEX MATCHALL "[0-9]+"
  73. _cl_version_list "${_cl_version}")
  74. list(GET _cl_version_list 0 _major)
  75. list(GET _cl_version_list 1 _minor)
  76. list(GET _cl_version_list 2 _patch)
  77. list(GET _cl_version_list 3 _tweak)
  78. set(_cl_version_string ${_major}.${_minor}.${_patch}.${_tweak})
  79. # Call helper function to determine VS version
  80. _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}")
  81. if(_sp)
  82. set(${_pack} ${_sp} CACHE INTERNAL
  83. "The Visual Studio Release with Service Pack")
  84. endif()
  85. endif()
  86. endif()
  87. endif()
  88. endfunction()