1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 CMakeDetermineVSServicePack
6 ---------------------------
12 The functionality of this module has been superseded by the
13 :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable that contains
14 the compiler version number.
16 Determine the Visual Studio service pack of the 'cl' in use.
21 include(CMakeDetermineVSServicePack)
22 DetermineVSServicePack( my_service_pack )
24 message(STATUS "Detected: ${my_service_pack}")
28 Function DetermineVSServicePack sets the given variable to one of the
29 following values or an empty string if unknown::
34 vc110, vc110sp1, vc110sp2, vc110sp3, vc110sp4
35 #]=======================================================================]
37 if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
39 "This module is deprecated and should not be used. "
40 "Use the CMAKE_<LANG>_COMPILER_VERSION variable instead."
45 # Please do not call this function directly
46 function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version)
47 if (${_cl_version} VERSION_EQUAL "14.00.50727.42")
49 elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
50 set(_version "vc80sp1")
51 elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
53 elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
54 set(_version "vc90sp1")
55 elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01")
57 elseif(${_cl_version} VERSION_EQUAL "16.00.40219.01")
58 set(_version "vc100sp1")
59 elseif(${_cl_version} VERSION_EQUAL "17.00.50727.1")
61 elseif(${_cl_version} VERSION_EQUAL "17.00.51106.1")
62 set(_version "vc110sp1")
63 elseif(${_cl_version} VERSION_EQUAL "17.00.60315.1")
64 set(_version "vc110sp2")
65 elseif(${_cl_version} VERSION_EQUAL "17.00.60610.1")
66 set(_version "vc110sp3")
67 elseif(${_cl_version} VERSION_EQUAL "17.00.61030")
68 set(_version "vc110sp4")
72 set(${_OUT_VAR} ${_version} PARENT_SCOPE)
76 ############################################################
78 # Please do not call this function directly
79 function(_DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR)
80 if(EXISTS ${CMAKE_CXX_COMPILER})
82 COMMAND ${CMAKE_CXX_COMPILER} -?
83 ERROR_VARIABLE _output
87 if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
88 set(_cl_version ${CMAKE_MATCH_1})
89 set(_major ${CMAKE_MATCH_2})
90 set(_minor ${CMAKE_MATCH_3})
91 if("${_major}${_minor}" STREQUAL "${MSVC_VERSION}")
92 set(${_SUCCESS_VAR} true PARENT_SCOPE)
93 set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
99 ############################################################
101 # Please do not call this function directly
102 function(_DetermineVSServicePack_CheckVersionWithTryCompile _SUCCESS_VAR _VERSION_VAR)
103 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
104 "int main() { return 0; }\n")
108 SOURCES "${CMAKE_BINARY_DIR}/return0.cc"
109 OUTPUT_VARIABLE _output
110 COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
112 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
114 if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
115 set(${_SUCCESS_VAR} true PARENT_SCOPE)
116 set(${_VERSION_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE)
120 ############################################################
122 # Please do not call this function directly
123 function(_DetermineVSServicePack_CheckVersionWithTryRun _SUCCESS_VAR _VERSION_VAR)
124 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
125 "#include <stdio.h>\n\nconst unsigned int CompilerVersion=_MSC_FULL_VER;\n\nint main(int argc, char* argv[])\n{\n int M( CompilerVersion/10000000);\n int m((CompilerVersion%10000000)/100000);\n int b(CompilerVersion%100000);\n\n printf(\"%d.%02d.%05d.01\",M,m,b);\n return 0;\n}\n")
130 SOURCES "${CMAKE_BINARY_DIR}/return0.cc"
131 RUN_OUTPUT_VARIABLE _runoutput
134 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
136 string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
137 _cl_version "${_runoutput}")
140 set(${_SUCCESS_VAR} true PARENT_SCOPE)
141 set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
147 # A function to call to determine the Visual Studio service pack
148 # in use. See documentation above.
149 function(DetermineVSServicePack _pack)
150 if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
152 _DetermineVSServicePack_FastCheckVersionWithCompiler(DETERMINED_VS_SERVICE_PACK _cl_version)
153 if(NOT DETERMINED_VS_SERVICE_PACK)
154 _DetermineVSServicePack_CheckVersionWithTryCompile(DETERMINED_VS_SERVICE_PACK _cl_version)
155 if(NOT DETERMINED_VS_SERVICE_PACK)
156 _DetermineVSServicePack_CheckVersionWithTryRun(DETERMINED_VS_SERVICE_PACK _cl_version)
160 if(DETERMINED_VS_SERVICE_PACK)
163 # Call helper function to determine VS version
164 _DetermineVSServicePackFromCompiler(_sp "${_cl_version}")
166 set(${_pack} ${_sp} CACHE INTERNAL
167 "The Visual Studio Release with Service Pack")