2013-10-15 19:17:36 +04:00
|
|
|
#.rst:
|
|
|
|
# CMakeVerifyManifest
|
|
|
|
# -------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
2009-10-21 21:28:50 +04:00
|
|
|
# CMakeVerifyManifest.cmake
|
|
|
|
#
|
2016-03-29 21:24:20 +03:00
|
|
|
# This script is used to verify that embedded manifests and side by side
|
2013-10-15 19:17:36 +04:00
|
|
|
# manifests for a project match. To run this script, cd to a directory
|
|
|
|
# and run the script with cmake -P. On the command line you can pass in
|
|
|
|
# versions that are OK even if not found in the .manifest files. For
|
|
|
|
# example, cmake -Dallow_versions=8.0.50608.0
|
2016-03-29 21:24:20 +03:00
|
|
|
# -PCmakeVerifyManifest.cmake could be used to allow an embedded manifest
|
2013-10-15 19:17:36 +04:00
|
|
|
# of 8.0.50608.0 to be used in a project even if that version was not
|
|
|
|
# found in the .manifest file.
|
2009-10-21 21:28:50 +04:00
|
|
|
|
|
|
|
# This script first recursively globs *.manifest files from
|
|
|
|
# the current directory. Then globs *.exe and *.dll. Each
|
2016-03-29 21:24:20 +03:00
|
|
|
# .exe and .dll is scanned for embedded manifests and the versions
|
2009-10-21 21:28:50 +04:00
|
|
|
# of CRT are compared to those found in the .manifest files
|
|
|
|
# from the first glob.
|
|
|
|
|
2009-10-21 21:44:33 +04:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2008-2009 Kitware, Inc.
|
|
|
|
#
|
|
|
|
# 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-10-21 21:44:33 +04:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
|
|
|
|
2009-10-21 21:34:45 +04:00
|
|
|
# crt_version:
|
2009-10-21 21:28:50 +04:00
|
|
|
# function to extract the CRT version from a file
|
|
|
|
# this can be passed a .exe, .dll, or a .manifest file
|
|
|
|
# it will put the list of versions found into the variable
|
|
|
|
# specified by list_var
|
|
|
|
function(crt_version file list_var)
|
2009-10-27 23:01:47 +03:00
|
|
|
file(STRINGS "${file}" strings REGEX "Microsoft.VC...CRT" NEWLINE_CONSUME)
|
2009-10-21 21:28:50 +04:00
|
|
|
foreach(s ${strings})
|
|
|
|
set(has_match 1)
|
|
|
|
string(REGEX
|
2012-08-13 21:42:58 +04:00
|
|
|
REPLACE ".*<assembly.*\"Microsoft.VC...CRT\".*version=\"([^\"]*)\".*</assembly>.*$" "\\1"
|
2009-10-21 21:28:50 +04:00
|
|
|
version "${s}")
|
|
|
|
if(NOT "${version}" STREQUAL "")
|
|
|
|
list(APPEND version_list ${version})
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Parse error could not find version in [${s}]")
|
|
|
|
endif()
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2009-10-21 21:28:50 +04:00
|
|
|
if(NOT DEFINED has_match)
|
2016-03-29 21:24:20 +03:00
|
|
|
message("Information: no embedded manifest in: ${file}")
|
2009-10-21 21:28:50 +04:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
list(APPEND version_list ${${list_var}})
|
|
|
|
list(REMOVE_DUPLICATES version_list)
|
|
|
|
if(version_list)
|
|
|
|
set(${list_var} ${version_list} PARENT_SCOPE)
|
|
|
|
endif()
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2009-10-21 21:28:50 +04:00
|
|
|
set(fatal_error FALSE)
|
2009-10-21 21:34:45 +04:00
|
|
|
|
|
|
|
# check_version:
|
2012-08-13 21:42:58 +04:00
|
|
|
#
|
2009-10-21 21:28:50 +04:00
|
|
|
# test a file against the shipped manifest versions
|
|
|
|
# for a directory
|
|
|
|
function(check_version file manifest_versions)
|
|
|
|
set(manifest_versions ${manifest_versions} ${allow_versions})
|
|
|
|
# collect versions for a given file
|
|
|
|
crt_version(${file} file_versions)
|
2012-08-13 21:42:58 +04:00
|
|
|
# see if the versions
|
2009-10-21 21:28:50 +04:00
|
|
|
foreach(ver ${file_versions})
|
|
|
|
list(FIND manifest_versions "${ver}" found_version)
|
|
|
|
if("${found_version}" EQUAL -1)
|
2009-10-28 17:29:24 +03:00
|
|
|
message("ERROR: ${file} uses ${ver} not found in shipped manifests:[${manifest_versions}].")
|
2009-10-21 21:28:50 +04:00
|
|
|
set(fatal_error TRUE PARENT_SCOPE)
|
|
|
|
endif()
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2009-10-21 21:28:50 +04:00
|
|
|
list(LENGTH file_versions len)
|
|
|
|
if(${len} GREATER 1)
|
|
|
|
message("WARNING: found more than one version of MICROSOFT.VC80.CRT referenced in ${file}: [${file_versions}]")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# collect up the versions of CRT that are shipped
|
|
|
|
# in .manifest files
|
|
|
|
set(manifest_version_list )
|
|
|
|
file(GLOB_RECURSE manifest_files "*.manifest")
|
|
|
|
foreach(f ${manifest_files})
|
|
|
|
crt_version("${f}" manifest_version_list)
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2009-10-27 23:01:47 +03:00
|
|
|
list(LENGTH manifest_version_list LEN)
|
|
|
|
if(LEN EQUAL 0)
|
|
|
|
message(FATAL_ERROR "No .manifest files found, no version check can be done.")
|
|
|
|
endif()
|
2009-10-21 21:28:50 +04:00
|
|
|
message("Versions found in ${manifest_files}: ${manifest_version_list}")
|
2009-10-21 21:37:53 +04:00
|
|
|
if(DEFINED allow_versions)
|
|
|
|
message("Extra versions allowed: ${allow_versions}")
|
|
|
|
endif()
|
2009-10-21 21:28:50 +04:00
|
|
|
|
|
|
|
# now find all .exe and .dll files
|
|
|
|
# and call check_version on each of them
|
|
|
|
file(GLOB_RECURSE exe_files "*.exe")
|
|
|
|
file(GLOB_RECURSE dll_files "*.dll")
|
|
|
|
set(exe_files ${exe_files} ${dll_files})
|
|
|
|
foreach(f ${exe_files})
|
2009-10-28 17:29:24 +03:00
|
|
|
check_version(${f} "${manifest_version_list}")
|
2009-10-21 21:28:50 +04:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# report a fatal error if there were any so that cmake will return
|
|
|
|
# a non zero value
|
|
|
|
if(fatal_error)
|
2009-10-28 17:29:24 +03:00
|
|
|
message(FATAL_ERROR "This distribution embeds dll "
|
|
|
|
" versions that it does not ship, and may not work on other machines.")
|
2009-10-21 21:28:50 +04:00
|
|
|
endif()
|