You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.6 KiB

  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 <philip@yhbt.com>
  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. if(${CMAKE_BUILD_TOOL} STREQUAL "nmake")
  61. EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} "/?"
  62. ERROR_VARIABLE _output)
  63. set(DETERMINED_VS_SERVICE_PACK ${_output})
  64. else()
  65. file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
  66. "int main() { return 0; }\n")
  67. try_compile(DETERMINED_VS_SERVICE_PACK
  68. "${CMAKE_BINARY_DIR}"
  69. "${CMAKE_BINARY_DIR}/return0.cc"
  70. OUTPUT_VARIABLE _output
  71. COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
  72. file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
  73. endif()
  74. if(DETERMINED_VS_SERVICE_PACK AND _output)
  75. string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
  76. _cl_version "${_output}")
  77. if(_cl_version)
  78. string(REGEX MATCHALL "[0-9]+"
  79. _cl_version_list "${_cl_version}")
  80. list(GET _cl_version_list 0 _major)
  81. list(GET _cl_version_list 1 _minor)
  82. list(GET _cl_version_list 2 _patch)
  83. list(GET _cl_version_list 3 _tweak)
  84. set(_cl_version_string ${_major}.${_minor}.${_patch}.${_tweak})
  85. # Call helper function to determine VS version
  86. _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}")
  87. if(_sp)
  88. #set(${_pack} "${_sp}(${_cl_version_string})" CACHE INTERNAL
  89. set(${_pack} "${_sp}" CACHE INTERNAL
  90. "The Visual Studio Release with Service Pack")
  91. endif()
  92. endif()
  93. endif()
  94. endif()
  95. endfunction()