| 1 | # Module for locating Visual Leak Detector. |
| 2 | # |
| 3 | # Customizable variables: |
| 4 | # VLD_ROOT_DIR |
| 5 | # This variable points to the Visual Leak Detector root directory. By |
| 6 | # default, the module looks for the installation directory by examining the |
| 7 | # Program Files/Program Files (x86) folders and the VLDROOT environment |
| 8 | # variable. |
| 9 | # |
| 10 | # Read-only variables: |
| 11 | # VLD_FOUND |
| 12 | # Indicates that the library has been found. |
| 13 | # |
| 14 | # VLD_INCLUDE_DIRS |
| 15 | # Points to the Visual Leak Detector include directory. |
| 16 | # |
| 17 | # VLD_LIBRARY_DIRS |
| 18 | # Points to the Visual Leak Detector directory that contains the libraries. |
| 19 | # The content of this variable can be passed to link_directories. |
| 20 | # |
| 21 | # VLD_LIBRARIES |
| 22 | # Points to the Visual Leak Detector libraries that can be passed to |
| 23 | # target_link_libararies. |
| 24 | # |
| 25 | # |
| 26 | # Copyright (c) 2012 Sergiu Dotenco |
| 27 | # |
| 28 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 29 | # of this software and associated documentation files (the "Software"), to deal |
| 30 | # in the Software without restriction, including without limitation the rights |
| 31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 32 | # copies of the Software, and to permit persons to whom the Software is |
| 33 | # furnished to do so, subject to the following conditions: |
| 34 | # |
| 35 | # The above copyright notice and this permission notice shall be included in all |
| 36 | # copies or substantial portions of the Software. |
| 37 | # |
| 38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 44 | # SOFTWARE. |
| 45 | |
| 46 | INCLUDE (FindPackageHandleStandardArgs) |
| 47 | |
| 48 | SET (_VLD_POSSIBLE_LIB_SUFFIXES lib) |
| 49 | |
| 50 | # Version 2.0 uses vld_x86 and vld_x64 instead of simply vld as library names |
| 51 | IF (CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 52 | LIST (APPEND _VLD_POSSIBLE_LIB_SUFFIXES lib/Win32) |
| 53 | ELSEIF (CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 54 | LIST (APPEND _VLD_POSSIBLE_LIB_SUFFIXES lib/Win64) |
| 55 | ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 56 | |
| 57 | SET (PFILES "ProgramFiles") |
| 58 | SET (PFILES_X86 "ProgramFiles(x86)") # hack to avoid escaping issues in cmake 3.1 |
| 59 | |
| 60 | FIND_PATH (VLD_ROOT_DIR |
| 61 | NAMES include/vld.h |
| 62 | PATHS ENV VLDROOT |
| 63 | "$ENV{PFILES}/Visual Leak Detector" |
| 64 | "$ENV{PFILES_X86}/Visual Leak Detector" |
| 65 | "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Visual Leak Detector;InstallLocation]" |
| 66 | "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Visual Leak Detector;InstallLocation]" |
| 67 | DOC "VLD root directory") |
| 68 | |
| 69 | FIND_PATH (VLD_INCLUDE_DIR |
| 70 | NAMES vld.h |
| 71 | HINTS ${VLD_ROOT_DIR} |
| 72 | PATH_SUFFIXES include |
| 73 | DOC "VLD include directory") |
| 74 | |
| 75 | FIND_LIBRARY (VLD_LIBRARY_DEBUG |
| 76 | NAMES vld |
| 77 | HINTS ${VLD_ROOT_DIR} |
| 78 | PATH_SUFFIXES ${_VLD_POSSIBLE_LIB_SUFFIXES} |
| 79 | DOC "VLD debug library") |
| 80 | |
| 81 | IF (VLD_ROOT_DIR) |
| 82 | SET (_VLD_VERSION_FILE ${VLD_ROOT_DIR}/CHANGES.txt) |
| 83 | |
| 84 | IF (EXISTS ${_VLD_VERSION_FILE}) |
| 85 | SET (_VLD_VERSION_REGEX |
| 86 | "Visual Leak Detector \\(VLD\\) Version (([0-9]+)\\.([0-9]+)([a-z]|(.([0-9]+)))?)") |
| 87 | FILE (STRINGS ${_VLD_VERSION_FILE} _VLD_VERSION_TMP REGEX |
| 88 | ${_VLD_VERSION_REGEX}) |
| 89 | |
| 90 | STRING (REGEX REPLACE ${_VLD_VERSION_REGEX} "\\1" _VLD_VERSION_TMP |
| 91 | "${_VLD_VERSION_TMP}") |
| 92 | |
| 93 | STRING (REGEX REPLACE "([0-9]+).([0-9]+).*" "\\1" VLD_VERSION_MAJOR |
| 94 | "${_VLD_VERSION_TMP}") |
| 95 | STRING (REGEX REPLACE "([0-9]+).([0-9]+).*" "\\2" VLD_VERSION_MINOR |
| 96 | "${_VLD_VERSION_TMP}") |
| 97 | |
| 98 | SET (VLD_VERSION ${VLD_VERSION_MAJOR}.${VLD_VERSION_MINOR}) |
| 99 | |
| 100 | IF ("${_VLD_VERSION_TMP}" MATCHES "^([0-9]+).([0-9]+).([0-9]+)$") |
| 101 | # major.minor.patch version numbering scheme |
| 102 | STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\3" |
| 103 | VLD_VERSION_PATCH "${_VLD_VERSION_TMP}") |
| 104 | SET (VLD_VERSION "${VLD_VERSION}.${VLD_VERSION_PATCH}") |
| 105 | SET (VLD_VERSION_COUNT 3) |
| 106 | ELSE ("${_VLD_VERSION_TMP}" MATCHES "^([0-9]+).([0-9]+).([0-9]+)$") |
| 107 | # major.minor version numbering scheme. The trailing letter is ignored. |
| 108 | SET (VLD_VERSION_COUNT 2) |
| 109 | ENDIF ("${_VLD_VERSION_TMP}" MATCHES "^([0-9]+).([0-9]+).([0-9]+)$") |
| 110 | ENDIF (EXISTS ${_VLD_VERSION_FILE}) |
| 111 | ENDIF (VLD_ROOT_DIR) |
| 112 | |
| 113 | IF (VLD_LIBRARY_DEBUG) |
| 114 | SET (VLD_LIBRARY debug ${VLD_LIBRARY_DEBUG} CACHE DOC "VLD library") |
| 115 | GET_FILENAME_COMPONENT (_VLD_LIBRARY_DIR ${VLD_LIBRARY_DEBUG} PATH) |
| 116 | SET (VLD_LIBRARY_DIR ${_VLD_LIBRARY_DIR} CACHE PATH "VLD library directory") |
| 117 | ENDIF (VLD_LIBRARY_DEBUG) |
| 118 | |
| 119 | SET (VLD_INCLUDE_DIRS ${VLD_INCLUDE_DIR}) |
| 120 | SET (VLD_LIBRARY_DIRS ${VLD_LIBRARY_DIR}) |
| 121 | SET (VLD_LIBRARIES ${VLD_LIBRARY}) |
| 122 | |
| 123 | MARK_AS_ADVANCED (VLD_INCLUDE_DIR VLD_LIBRARY_DIR VLD_LIBRARY_DEBUG VLD_LIBRARY) |
| 124 | |
| 125 | FIND_PACKAGE_HANDLE_STANDARD_ARGS (VLD REQUIRED_VARS VLD_ROOT_DIR |
| 126 | VLD_INCLUDE_DIR VLD_LIBRARY VERSION_VAR VLD_VERSION) |