1# - Includes a public function for assisting users in trying to determine the 2# Visual Studio service pack in use. 3# 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 10# 11# Usage: 12# =========================== 13# 14# if(MSVC) 15# include(CMakeDetermineVSServicePack) 16# DetermineVSServicePack( my_service_pack ) 17# 18# if( my_service_pack ) 19# message(STATUS "Detected: ${my_service_pack}") 20# endif() 21# endif() 22# 23# =========================== 24 25#============================================================================= 26# Copyright 2009-2010 Kitware, Inc. 27# Copyright 2009-2010 Philip Lowman <philip@yhbt.com> 28# 29# Distributed under the OSI-approved BSD License (the "License"); 30# see accompanying file Copyright.txt for details. 31# 32# This software is distributed WITHOUT ANY WARRANTY; without even the 33# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 34# See the License for more information. 35#============================================================================= 36# (To distribute this file outside of CMake, substitute the full 37# License text for the above reference.) 38 39# [INTERNAL] 40# Please do not call this function directly 41function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version) 42 if (${_cl_version} VERSION_EQUAL "14.00.50727.42") 43 set(_version "vc80") 44 elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762") 45 set(_version "vc80sp1") 46 elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08") 47 set(_version "vc90") 48 elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01") 49 set(_version "vc90sp1") 50 elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01") 51 set(_version "vc100") 52 else() 53 set(_version "") 54 endif() 55 set(${_OUT_VAR} ${_version} PARENT_SCOPE) 56endfunction() 57 58# 59# A function to call to determine the Visual Studio service pack 60# in use. See documentation above. 61function(DetermineVSServicePack _pack) 62 if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack}) 63 if(${CMAKE_BUILD_TOOL} STREQUAL "nmake") 64 EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} "/?" 65 ERROR_VARIABLE _output) 66 set(DETERMINED_VS_SERVICE_PACK ${_output}) 67 else() 68 file(WRITE "${CMAKE_BINARY_DIR}/return0.cc" 69 "int main() { return 0; }\n") 70 71 try_compile(DETERMINED_VS_SERVICE_PACK 72 "${CMAKE_BINARY_DIR}" 73 "${CMAKE_BINARY_DIR}/return0.cc" 74 OUTPUT_VARIABLE _output 75 COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc") 76 77 file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc") 78 endif() 79 80 if(DETERMINED_VS_SERVICE_PACK AND _output) 81 string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+" 82 _cl_version "${_output}") 83 if(_cl_version) 84 string(REGEX MATCHALL "[0-9]+" 85 _cl_version_list "${_cl_version}") 86 list(GET _cl_version_list 0 _major) 87 list(GET _cl_version_list 1 _minor) 88 list(GET _cl_version_list 2 _patch) 89 list(GET _cl_version_list 3 _tweak) 90 91 set(_cl_version_string ${_major}.${_minor}.${_patch}.${_tweak}) 92 93 # Call helper function to determine VS version 94 _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}") 95 if(_sp) 96 #set(${_pack} "${_sp}(${_cl_version_string})" CACHE INTERNAL 97 set(${_pack} "${_sp}" CACHE INTERNAL 98 "The Visual Studio Release with Service Pack") 99 endif() 100 endif() 101 endif() 102 endif() 103endfunction() 104