1 # - Includes a public function for assisting users in trying to determine the
2 # Visual Studio service pack in use.
4 # Sets the passed in variable to one of the following values or an empty
15 # ===========================
18 # include(CMakeDetermineVSServicePack)
19 # DetermineVSServicePack( my_service_pack )
21 # if( my_service_pack )
22 # message(STATUS "Detected: ${my_service_pack}")
26 # ===========================
28 #=============================================================================
29 # Copyright 2009-2011 Kitware, Inc.
30 # Copyright 2009-2010 Philip Lowman <philip@yhbt.com>
31 # Copyright 2010-2011 Aaron C. meadows <cmake@shadowguarddev.com>
33 # Distributed under the OSI-approved BSD License (the "License");
34 # see accompanying file Copyright.txt for details.
36 # This software is distributed WITHOUT ANY WARRANTY; without even the
37 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38 # See the License for more information.
39 #=============================================================================
40 # (To distribute this file outside of CMake, substitute the full
41 # License text for the above reference.)
44 # Please do not call this function directly
45 function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version)
46 if (${_cl_version} VERSION_EQUAL "14.00.50727.42")
48 elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
49 set(_version "vc80sp1")
50 elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
52 elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
53 set(_version "vc90sp1")
54 elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01")
56 elseif(${_cl_version} VERSION_EQUAL "16.00.40219.01")
57 set(_version "vc100sp1")
58 elseif(${_cl_version} VERSION_EQUAL "17.00.50727.1")
63 set(${_OUT_VAR} ${_version} PARENT_SCOPE)
67 ############################################################
69 # Please do not call this function directly
70 function(_DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR)
71 if(EXISTS ${CMAKE_CXX_COMPILER})
73 COMMAND ${CMAKE_CXX_COMPILER} /?
74 ERROR_VARIABLE _output
78 string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
79 _cl_version "${_output}")
82 string(REGEX MATCHALL "[0-9]+"
83 _cl_version_list "${_cl_version}")
84 list(GET _cl_version_list 0 _major)
85 list(GET _cl_version_list 1 _minor)
86 list(GET _cl_version_list 2 _patch)
87 list(GET _cl_version_list 3 _tweak)
89 if("${_major}${_minor}" STREQUAL "${MSVC_VERSION}")
90 set(_cl_version ${_major}.${_minor}.${_patch}.${_tweak})
97 set(${_SUCCESS_VAR} true PARENT_SCOPE)
98 set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
103 ############################################################
105 # Please do not call this function directly
106 function(_DetermineVSServicePack_CheckVersionWithTryCompile _SUCCESS_VAR _VERSION_VAR)
107 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
108 "int main() { return 0; }\n")
112 "${CMAKE_BINARY_DIR}"
113 "${CMAKE_BINARY_DIR}/return0.cc"
114 OUTPUT_VARIABLE _output
115 COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
117 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
119 string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
120 _cl_version "${_output}")
123 string(REGEX MATCHALL "[0-9]+"
124 _cl_version_list "${_cl_version}")
126 list(GET _cl_version_list 0 _major)
127 list(GET _cl_version_list 1 _minor)
128 list(GET _cl_version_list 2 _patch)
129 list(GET _cl_version_list 3 _tweak)
131 set(${_SUCCESS_VAR} true PARENT_SCOPE)
132 set(${_VERSION_VAR} ${_major}.${_minor}.${_patch}.${_tweak} PARENT_SCOPE)
136 ############################################################
138 # Please do not call this function directly
139 function(_DetermineVSServicePack_CheckVersionWithTryRun _SUCCESS_VAR _VERSION_VAR)
140 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
141 "#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")
146 "${CMAKE_BINARY_DIR}"
147 "${CMAKE_BINARY_DIR}/return0.cc"
148 RUN_OUTPUT_VARIABLE _runoutput
151 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
153 string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
154 _cl_version "${_runoutput}")
157 set(${_SUCCESS_VAR} true PARENT_SCOPE)
158 set(${_VERSION_VAR} ${_cl_version} PARENT_SCOPE)
164 # A function to call to determine the Visual Studio service pack
165 # in use. See documentation above.
166 function(DetermineVSServicePack _pack)
167 if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
169 _DetermineVSServicePack_FastCheckVersionWithCompiler(DETERMINED_VS_SERVICE_PACK _cl_version)
170 if(NOT DETERMINED_VS_SERVICE_PACK)
171 _DetermineVSServicePack_CheckVersionWithTryCompile(DETERMINED_VS_SERVICE_PACK _cl_version)
172 if(NOT DETERMINED_VS_SERVICE_PACK)
173 _DetermineVSServicePack_CheckVersionWithTryRun(DETERMINED_VS_SERVICE_PACK _cl_version)
177 if(DETERMINED_VS_SERVICE_PACK)
180 # Call helper function to determine VS version
181 _DetermineVSServicePackFromCompiler(_sp "${_cl_version}")
183 set(${_pack} ${_sp} CACHE INTERNAL
184 "The Visual Studio Release with Service Pack")