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
12 # ===========================
15 # include(CMakeDetermineVSServicePack)
16 # DetermineVSServicePack( my_service_pack )
18 # if( my_service_pack )
19 # message(STATUS "Detected: ${my_service_pack}")
23 # ===========================
26 # Please do not call this function directly
27 function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version)
28 if (${_cl_version} VERSION_EQUAL "14.00.50727.42")
30 elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
31 set(_version "vc80sp1")
32 elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
34 elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
35 set(_version "vc90sp1")
39 set(${_OUT_VAR} ${_version} PARENT_SCOPE)
43 # A function to call to determine the Visual Studio service pack
44 # in use. See documentation above.
45 function(DetermineVSServicePack _pack)
46 if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
47 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc"
48 "int main() { return 0; }\n")
50 try_compile(DETERMINED_VS_SERVICE_PACK
52 "${CMAKE_BINARY_DIR}/return0.cc"
53 OUTPUT_VARIABLE _output
54 COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
56 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
58 if(DETERMINED_VS_SERVICE_PACK AND _output)
59 string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+"
60 _cl_version "${_output}")
62 string(REGEX MATCHALL "[0-9]+"
63 _cl_version_list "${_cl_version}")
64 list(GET _cl_version_list 0 _major)
65 list(GET _cl_version_list 1 _minor)
66 list(GET _cl_version_list 2 _patch)
67 list(GET _cl_version_list 3 _tweak)
69 set(_cl_version_string ${_major}.${_minor}.${_patch}.${_tweak})
71 # Call helper function to determine VS version
72 _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}")
74 set(${_pack} ${_sp} CACHE INTERNAL
75 "The Visual Studio Release with Service Pack")