CMakeDetermineVSServicePack.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 Kitware, Inc.
  26. # Copyright 2009 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 distributed 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. else()
  49. set(_version "")
  50. endif()
  51. set(${_OUT_VAR} ${_version} PARENT_SCOPE)
  52. endfunction()
  53. #
  54. # A function to call to determine the Visual Studio service pack
  55. # in use. See documentation above.
  56. function(DetermineVSServicePack _pack)
  57. if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
  58. file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
  59. "int main() { return 0; }\n")
  60. try_compile(DETERMINED_VS_SERVICE_PACK
  61. "${CMAKE_BINARY_DIR}"
  62. "${CMAKE_BINARY_DIR}/return0.cc"
  63. OUTPUT_VARIABLE _output
  64. COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
  65. file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
  66. if(DETERMINED_VS_SERVICE_PACK AND _output)
  67. string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
  68. _cl_version "${_output}")
  69. if(_cl_version)
  70. string(REGEX MATCHALL "[0-9]+"
  71. _cl_version_list "${_cl_version}")
  72. list(GET _cl_version_list 0 _major)
  73. list(GET _cl_version_list 1 _minor)
  74. list(GET _cl_version_list 2 _patch)
  75. list(GET _cl_version_list 3 _tweak)
  76. set(_cl_version_string ${_major}.${_minor}.${_patch}.${_tweak})
  77. # Call helper function to determine VS version
  78. _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}")
  79. if(_sp)
  80. set(${_pack} ${_sp} CACHE INTERNAL
  81. "The Visual Studio Release with Service Pack")
  82. endif()
  83. endif()
  84. endif()
  85. endif()
  86. endfunction()