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.
23 include(CMakeDetermineVSServicePack)
24 DetermineVSServicePack(my_service_pack)
26 message(STATUS "Detected: ${my_service_pack}")
30 Function DetermineVSServicePack sets the given variable to one of the
31 following values or an empty string if unknown::
36 vc110, vc110sp1, vc110sp2, vc110sp3, vc110sp4
37 #]=======================================================================]
39 if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
41 "This module is deprecated and should not be used. "
42 "Use the CMAKE_<LANG>_COMPILER_VERSION variable instead."
47 # Please do not call this function directly
48 function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version)
49 if (${_cl_version} VERSION_EQUAL "14.00.50727.42")
51 elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
52 set(_version "vc80sp1")
53 elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
55 elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
56 set(_version "vc90sp1")
57 elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01")
59 elseif(${_cl_version} VERSION_EQUAL "16.00.40219.01")
60 set(_version "vc100sp1")
61 elseif(${_cl_version} VERSION_EQUAL "17.00.50727.1")
63 elseif(${_cl_version} VERSION_EQUAL "17.00.51106.1")
64 set(_version "vc110sp1")
65 elseif(${_cl_version} VERSION_EQUAL "17.00.60315.1")
66 set(_version "vc110sp2")
67 elseif(${_cl_version} VERSION_EQUAL "17.00.60610.1")
68 set(_version "vc110sp3")
69 elseif(${_cl_version} VERSION_EQUAL "17.00.61030")
70 set(_version "vc110sp4")
74 set(${_OUT_VAR} ${_version} PARENT_SCOPE)
78 ############################################################
80 # Please do not call this function directly
81 function(_DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR)
82 if(EXISTS ${CMAKE_CXX_COMPILER})
84 COMMAND ${CMAKE_CXX_COMPILER} -?
85 ERROR_VARIABLE _output
89 if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
90 set(_cl_version ${CMAKE_MATCH_1})
91 set(_major ${CMAKE_MATCH_2})
92 set(_minor ${CMAKE_MATCH_3})
93 if("${_major}${_minor}" STREQUAL "${MSVC_VERSION}")
94 set(${_SUCCESS_VAR} true PARENT_SCOPE)
95 set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
101 ############################################################
103 # Please do not call this function directly
104 function(_DetermineVSServicePack_CheckVersionWithTryCompile _SUCCESS_VAR _VERSION_VAR)
105 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
106 "int main() { return 0; }\n")
110 SOURCES "${CMAKE_BINARY_DIR}/return0.cc"
111 OUTPUT_VARIABLE _output
112 COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
114 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
116 if(_output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)")
117 set(${_SUCCESS_VAR} true PARENT_SCOPE)
118 set(${_VERSION_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE)
122 ############################################################
124 # Please do not call this function directly
125 function(_DetermineVSServicePack_CheckVersionWithTryRun _SUCCESS_VAR _VERSION_VAR)
126 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
127 "#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")
132 SOURCES "${CMAKE_BINARY_DIR}/return0.cc"
133 RUN_OUTPUT_VARIABLE _runoutput
136 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
138 string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
139 _cl_version "${_runoutput}")
142 set(${_SUCCESS_VAR} true PARENT_SCOPE)
143 set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
149 # A function to call to determine the Visual Studio service pack
150 # in use. See documentation above.
151 function(DetermineVSServicePack _pack)
152 if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
154 _DetermineVSServicePack_FastCheckVersionWithCompiler(DETERMINED_VS_SERVICE_PACK _cl_version)
155 if(NOT DETERMINED_VS_SERVICE_PACK)
156 _DetermineVSServicePack_CheckVersionWithTryCompile(DETERMINED_VS_SERVICE_PACK _cl_version)
157 if(NOT DETERMINED_VS_SERVICE_PACK)
158 _DetermineVSServicePack_CheckVersionWithTryRun(DETERMINED_VS_SERVICE_PACK _cl_version)
162 if(DETERMINED_VS_SERVICE_PACK)
165 # Call helper function to determine VS version
166 _DetermineVSServicePackFromCompiler(_sp "${_cl_version}")
168 set(${_pack} ${_sp} CACHE INTERNAL
169 "The Visual Studio Release with Service Pack")