2013-10-15 19:17:36 +04:00
#.rst:
# CMakeDetermineVSServicePack
# ---------------------------
#
2014-04-10 19:01:46 +04:00
# Deprecated. Do not use.
2013-10-15 19:17:36 +04:00
#
2014-04-10 19:01:46 +04:00
# The functionality of this module has been superseded by the
# :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable that contains
# the compiler version number.
2009-04-14 08:50:23 +04:00
#
2014-04-10 19:01:46 +04:00
# Determine the Visual Studio service pack of the 'cl' in use.
2013-10-15 19:17:36 +04:00
#
2014-04-10 19:01:46 +04:00
# Usage::
2013-10-15 19:17:36 +04:00
#
# if(MSVC)
# include(CMakeDetermineVSServicePack)
# DetermineVSServicePack( my_service_pack )
# if( my_service_pack )
# message(STATUS "Detected: ${my_service_pack}")
# endif()
# endif()
#
2013-06-21 16:48:58 +04:00
# Function DetermineVSServicePack sets the given variable to one of the
2014-04-10 19:01:46 +04:00
# following values or an empty string if unknown::
2013-10-15 19:17:36 +04:00
#
# vc80, vc80sp1
# vc90, vc90sp1
# vc100, vc100sp1
2014-04-10 20:26:21 +04:00
# vc110, vc110sp1, vc110sp2, vc110sp3, vc110sp4
2009-09-28 19:46:51 +04:00
#=============================================================================
2013-06-21 16:48:58 +04:00
# Copyright 2009-2013 Kitware, Inc.
2010-10-01 05:24:28 +04:00
# Copyright 2009-2010 Philip Lowman <philip@yhbt.com>
2011-06-15 16:33:40 +04:00
# Copyright 2010-2011 Aaron C. meadows <cmake@shadowguarddev.com>
2009-09-28 19:46:51 +04:00
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# 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.
#=============================================================================
2010-08-07 04:48:47 +04:00
# (To distribute this file outside of CMake, substitute the full
2009-09-28 19:46:51 +04:00
# License text for the above reference.)
2014-04-10 19:03:41 +04:00
if ( NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8 )
message ( DEPRECATION
" T h i s m o d u l e i s d e p r e c a t e d a n d s h o u l d n o t b e u s e d . "
" U s e t h e C M A K E _ < L A N G > _ C O M P I L E R _ V E R S I O N v a r i a b l e i n s t e a d . "
)
endif ( )
2009-04-14 08:50:23 +04:00
# [INTERNAL]
# Please do not call this function directly
function ( _DetermineVSServicePackFromCompiler _OUT_VAR _cl_version )
if ( ${ _cl_version } VERSION_EQUAL "14.00.50727.42" )
set ( _version "vc80" )
elseif ( ${ _cl_version } VERSION_EQUAL "14.00.50727.762" )
set ( _version "vc80sp1" )
elseif ( ${ _cl_version } VERSION_EQUAL "15.00.21022.08" )
set ( _version "vc90" )
elseif ( ${ _cl_version } VERSION_EQUAL "15.00.30729.01" )
set ( _version "vc90sp1" )
2010-10-01 05:24:28 +04:00
elseif ( ${ _cl_version } VERSION_EQUAL "16.00.30319.01" )
set ( _version "vc100" )
2011-06-15 16:33:40 +04:00
elseif ( ${ _cl_version } VERSION_EQUAL "16.00.40219.01" )
set ( _version "vc100sp1" )
2012-09-22 07:11:18 +04:00
elseif ( ${ _cl_version } VERSION_EQUAL "17.00.50727.1" )
set ( _version "vc110" )
2013-06-21 16:51:13 +04:00
elseif ( ${ _cl_version } VERSION_EQUAL "17.00.51106.1" )
set ( _version "vc110sp1" )
elseif ( ${ _cl_version } VERSION_EQUAL "17.00.60315.1" )
set ( _version "vc110sp2" )
2013-06-28 17:43:10 +04:00
elseif ( ${ _cl_version } VERSION_EQUAL "17.00.60610.1" )
set ( _version "vc110sp3" )
2014-04-10 20:26:21 +04:00
elseif ( ${ _cl_version } VERSION_EQUAL "17.00.61030" )
set ( _version "vc110sp4" )
2009-04-14 08:50:23 +04:00
else ( )
set ( _version "" )
endif ( )
set ( ${ _OUT_VAR } ${ _version } PARENT_SCOPE )
endfunction ( )
2011-06-15 16:33:40 +04:00
############################################################
# [INTERNAL]
# Please do not call this function directly
function ( _DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR )
if ( EXISTS ${ CMAKE_CXX_COMPILER } )
execute_process (
C O M M A N D $ { C M A K E _ C X X _ C O M P I L E R } / ?
E R R O R _ V A R I A B L E _ o u t p u t
O U T P U T _ Q U I E T
)
2014-04-10 19:03:32 +04:00
if ( _output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)" )
set ( _cl_version ${ CMAKE_MATCH_1 } )
set ( _major ${ CMAKE_MATCH_2 } )
set ( _minor ${ CMAKE_MATCH_3 } )
2011-06-15 16:33:40 +04:00
if ( "${_major}${_minor}" STREQUAL "${MSVC_VERSION}" )
set ( ${ _SUCCESS_VAR } true PARENT_SCOPE )
set ( ${ _VERSION_VAR } ${ _cl_version } PARENT_SCOPE )
2014-04-10 19:03:32 +04:00
endif ( )
2011-06-15 16:33:40 +04:00
endif ( )
endif ( )
endfunction ( )
############################################################
# [INTERNAL]
# Please do not call this function directly
function ( _DetermineVSServicePack_CheckVersionWithTryCompile _SUCCESS_VAR _VERSION_VAR )
file ( WRITE "${CMAKE_BINARY_DIR}/return0.cc"
" i n t main ( ) { r e t u r n 0 ; } \ n " )
try_compile (
_ C o m p i l e R e s u l t
" $ { C M A K E _ B I N A R Y _ D I R } "
" $ { C M A K E _ B I N A R Y _ D I R } / r e t u r n 0 . c c "
O U T P U T _ V A R I A B L E _ o u t p u t
C O P Y _ F I L E " $ { C M A K E _ B I N A R Y _ D I R } / r e t u r n 0 . c c " )
file ( REMOVE "${CMAKE_BINARY_DIR}/return0.cc" )
2014-04-10 19:03:32 +04:00
if ( _output MATCHES "Compiler Version (([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\.([0-9]+))?)" )
2011-06-15 16:33:40 +04:00
set ( ${ _SUCCESS_VAR } true PARENT_SCOPE )
2014-04-10 19:03:32 +04:00
set ( ${ _VERSION_VAR } "${CMAKE_MATCH_1}" PARENT_SCOPE )
2011-06-15 16:33:40 +04:00
endif ( )
endfunction ( )
############################################################
# [INTERNAL]
# Please do not call this function directly
function ( _DetermineVSServicePack_CheckVersionWithTryRun _SUCCESS_VAR _VERSION_VAR )
file ( WRITE "${CMAKE_BINARY_DIR}/return0.cc"
" #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")
try_run (
_ R u n R e s u l t
_ C o m p i l e R e s u l t
" $ { C M A K E _ B I N A R Y _ D I R } "
" $ { C M A K E _ B I N A R Y _ D I R } / r e t u r n 0 . c c "
R U N _ O U T P U T _ V A R I A B L E _ r u n o u t p u t
)
file ( REMOVE "${CMAKE_BINARY_DIR}/return0.cc" )
string ( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+.[0-9]+"
_ c l _ v e r s i o n " $ { _ r u n o u t p u t } " )
if ( _cl_version )
set ( ${ _SUCCESS_VAR } true PARENT_SCOPE )
set ( ${ _VERSION_VAR } ${ _cl_version } PARENT_SCOPE )
endif ( )
endfunction ( )
2009-04-14 08:50:23 +04:00
#
# A function to call to determine the Visual Studio service pack
# in use. See documentation above.
function ( DetermineVSServicePack _pack )
if ( NOT DETERMINED_VS_SERVICE_PACK OR NOT ${ _pack } )
2011-06-15 16:33:40 +04:00
_DetermineVSServicePack_FastCheckVersionWithCompiler ( DETERMINED_VS_SERVICE_PACK _cl_version )
if ( NOT DETERMINED_VS_SERVICE_PACK )
_DetermineVSServicePack_CheckVersionWithTryCompile ( DETERMINED_VS_SERVICE_PACK _cl_version )
if ( NOT DETERMINED_VS_SERVICE_PACK )
_DetermineVSServicePack_CheckVersionWithTryRun ( DETERMINED_VS_SERVICE_PACK _cl_version )
endif ( )
endif ( )
if ( DETERMINED_VS_SERVICE_PACK )
2009-04-14 08:50:23 +04:00
if ( _cl_version )
# Call helper function to determine VS version
2011-06-15 16:33:40 +04:00
_DetermineVSServicePackFromCompiler ( _sp "${_cl_version}" )
2009-04-14 08:50:23 +04:00
if ( _sp )
set ( ${ _pack } ${ _sp } CACHE INTERNAL
" T h e V i s u a l S t u d i o R e l e a s e w i t h S e r v i c e P a c k " )
endif ( )
endif ( )
endif ( )
endif ( )
endfunction ( )