ENH: make this work for older versions of OSX
[cmake.git] / Modules / CMakeDetermineVSServicePack.cmake
blobe1452ceb020e65555672e183eec5a6d76d5a46de
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
5 # string if unknown.
6 #    vc80
7 #    vc80sp1
8 #    vc90
9 #    vc90sp1
11 # Usage:
12 # ===========================
14 #    if(MSVC)
15 #       include(CMakeDetermineVSServicePack)
16 #       DetermineVSServicePack( my_service_pack )
18 #       if( my_service_pack )
19 #           message(STATUS "Detected: ${my_service_pack}")
20 #       endif()
21 #    endif()
23 # ===========================
24                 
25 # [INTERNAL]
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")
29        set(_version "vc80")
30    elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762")
31        set(_version "vc80sp1")
32    elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08")
33        set(_version "vc90")
34    elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01")
35        set(_version "vc90sp1")
36    else()
37        set(_version "")
38    endif()
39    set(${_OUT_VAR} ${_version} PARENT_SCOPE)
40 endfunction()
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
51             "${CMAKE_BINARY_DIR}"
52             "${CMAKE_BINARY_DIR}/return0.cc"
53             OUTPUT_VARIABLE _output
54             COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc")
55         
56         file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc")
57                 
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}")
61             if(_cl_version)
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})
70                 
71                 # Call helper function to determine VS version
72                 _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}")
73                 if(_sp)
74                     set(${_pack} ${_sp} CACHE INTERNAL
75                         "The Visual Studio Release with Service Pack")
76                 endif()
77             endif()
78         endif()
79     endif()
80 endfunction()