1
# CMakeVerifyManifest.cmake
3
# This script is used to verify that embeded manifests and
4
# side by side manifests for a project match. To run this
5
# script, cd to a directory and run the script with cmake -P.
6
# On the command line you can pass in versions that are OK even
7
# if not found in the .manifest files. For example,
8
# cmake -Dallow_versions=8.0.50608.0 -PCmakeVerifyManifest.cmake
9
# could be used to allow an embeded manifest of 8.0.50608.0
10
# to be used in a project even if that version was not found
11
# in the .manifest file.
13
# This script first recursively globs *.manifest files from
14
# the current directory. Then globs *.exe and *.dll. Each
15
# .exe and .dll is scanned for embeded manifests and the versions
16
# of CRT are compared to those found in the .manifest files
17
# from the first glob.
19
#=============================================================================
20
# Copyright 2008-2009 Kitware, Inc.
22
# Distributed under the OSI-approved BSD License (the "License");
23
# see accompanying file Copyright.txt for details.
25
# This software is distributed WITHOUT ANY WARRANTY; without even the
26
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
# See the License for more information.
28
#=============================================================================
29
# (To distributed this file outside of CMake, substitute the full
30
# License text for the above reference.)
34
# function to extract the CRT version from a file
35
# this can be passed a .exe, .dll, or a .manifest file
36
# it will put the list of versions found into the variable
37
# specified by list_var
38
function(crt_version file list_var)
39
file(STRINGS "${file}" strings REGEX "Microsoft.VC...CRT" NEWLINE_CONSUME)
43
REPLACE ".*<assembly.*\"Microsoft.VC...CRT\".*version=\"([^\"]*)\".*</assembly>.*$" "\\1"
45
if(NOT "${version}" STREQUAL "")
46
list(APPEND version_list ${version})
48
message(FATAL_ERROR "Parse error could not find version in [${s}]")
51
if(NOT DEFINED has_match)
52
message("Information: no embeded manifest in: ${file}")
55
list(APPEND version_list ${${list_var}})
56
list(REMOVE_DUPLICATES version_list)
58
set(${list_var} ${version_list} PARENT_SCOPE)
60
endfunction(crt_version)
61
set(fatal_error FALSE)
65
# test a file against the shipped manifest versions
67
function(check_version file manifest_versions)
68
set(manifest_versions ${manifest_versions} ${allow_versions})
69
# collect versions for a given file
70
crt_version(${file} file_versions)
72
foreach(ver ${file_versions})
73
list(FIND manifest_versions "${ver}" found_version)
74
if("${found_version}" EQUAL -1)
75
message("ERROR: ${file} uses ${ver} not found in shipped manifests:[${manifest_versions}].")
76
set(fatal_error TRUE PARENT_SCOPE)
79
list(LENGTH file_versions len)
81
message("WARNING: found more than one version of MICROSOFT.VC80.CRT referenced in ${file}: [${file_versions}]")
85
# collect up the versions of CRT that are shipped
87
set(manifest_version_list )
88
file(GLOB_RECURSE manifest_files "*.manifest")
89
foreach(f ${manifest_files})
90
crt_version("${f}" manifest_version_list)
92
list(LENGTH manifest_version_list LEN)
94
message(FATAL_ERROR "No .manifest files found, no version check can be done.")
96
message("Versions found in ${manifest_files}: ${manifest_version_list}")
97
if(DEFINED allow_versions)
98
message("Extra versions allowed: ${allow_versions}")
101
# now find all .exe and .dll files
102
# and call check_version on each of them
103
file(GLOB_RECURSE exe_files "*.exe")
104
file(GLOB_RECURSE dll_files "*.dll")
105
set(exe_files ${exe_files} ${dll_files})
106
foreach(f ${exe_files})
107
check_version(${f} "${manifest_version_list}")
110
# report a fatal error if there were any so that cmake will return
113
message(FATAL_ERROR "This distribution embeds dll "
114
" versions that it does not ship, and may not work on other machines.")