File: GetMSVCVersion.cmake

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (127 lines) | stat: -rw-r--r-- 4,867 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#.rst:
# GetMSVCVersion
# --------------
#
#
#
# get_msvc_major_version(<var>)
# get_msvc_minor_version(<var>)
# get_msvc_combined_major_minor_version(<var>)
# get_msvc_major_minor_version(<major_var> <minor_var>)
# get_msvc_unique_decimal_version(<var>)
#
# This family of functions is designed to be used to convert
# MSVC_VERSION from the compiler version number to the Visual Studio
# decimal version number (2012 is 11.0, 2015 is 14.0). All take a name
# of a variable in <var> to return their results in.
#
# Consider Visual Studio 2013, which reports 1800 in MSVC_VERSION (and
# the _MSC_VER preprocessor macro). It is also known as VS 12 or 12.0.
# (Minor versions are rarely used, except in the case of 7.1 aka
# VS.NET 2003) The functions would return this output for 2013:
#
# get_msvc_major_version: 12
# get_msvc_minor_version: 0
# get_msvc_combined_major_minor_version: 120
# get_msvc_major_minor_version: 12 in <major_var>, 0 in <minor_var>
# get_msvc_unique_decimal_version: 12  (this returns with a decimal and
# minor when needed to be precise, e.g. 7.1)
#
# The variable is not modified if not building with MSVC.

#=============================================================================
# Copyright 2015 Ryan Pavlik <ryan.pavlik@gmail.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see below.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
#
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
#   nor the names of their contributors may be used to endorse or promote
#   products derived from this software without specific prior written
#   permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

# This function serves as the main implementation, with the others just
# tweaking the result.
function(get_msvc_combined_major_minor_version _var)
    if(NOT MSVC)
        return()
    endif()
    math(EXPR _vs_ver "${MSVC_VERSION} / 10 - 60")

    # VS 2015 changed the pattern because they skipped VS 13
    if(_vs_ver GREATER 120)
        math(EXPR _vs_ver "${_vs_ver} + 10")
    endif()
    set(${_var} ${_vs_ver} PARENT_SCOPE)
endfunction()

# This function is also used as backend to some implementation, though
# its contents are simpler, no real business logic to speak of.
function(get_msvc_major_minor_version _major_var _minor_var)
    if(NOT MSVC)
        return()
    endif()
    get_msvc_combined_major_minor_version(_vs_ver)

    math(EXPR _vs_minor "${_vs_ver} % 10")
    math(EXPR _vs_major "(${_vs_ver} - ${_vs_minor}) / 10")
    set(${_major_var} ${_vs_major} PARENT_SCOPE)
    set(${_minor_var} ${_vs_minor} PARENT_SCOPE)
endfunction()

function(get_msvc_major_version _var)
    if(NOT MSVC)
        return()
    endif()
    get_msvc_major_minor_version(_vs_ver _dummy)
    set(${_var} ${_vs_ver} PARENT_SCOPE)
endfunction()

function(get_msvc_minor_version _var)
    if(NOT MSVC)
        return()
    endif()
    get_msvc_major_minor_version(_dummy _vs_ver)
    set(${_var} ${_vs_ver} PARENT_SCOPE)
endfunction()

function(get_msvc_unique_decimal_version _var)
    if(NOT MSVC)
        return()
    endif()
    get_msvc_major_minor_version(_vs_major _vs_minor)
    set(_vs_ver ${_vs_major})
    if(_vs_minor GREATER 0)
        set(_vs_ver "${_vs_ver}.${_vs_minor}")
    endif()
    set(${_var} ${_vs_ver} PARENT_SCOPE)
endfunction()