1 | INCLUDE(FindPackageHandleStandardArgs) |
---|
2 | INCLUDE(CompareVersionStrings) |
---|
3 | |
---|
4 | FUNCTION(FIND_PACKAGE_HANDLE_ADVANCED_ARGS _name _fail_msg _version) |
---|
5 | |
---|
6 | # Modify the message to include version requirements |
---|
7 | IF("${_fail_msg}" STREQUAL "DEFAULT_MSG") |
---|
8 | SET(_fail_msg_adv "Could NOT find ${_name}") |
---|
9 | ELSE("${_fail_msg}" STREQUAL "DEFAULT_MSG") |
---|
10 | SET(_fail_msg_adv "${_fail_msg}") |
---|
11 | ENDIF("${_fail_msg}" STREQUAL "DEFAULT_MSG") |
---|
12 | IF(${_name}_FIND_VERSION_EXACT) |
---|
13 | SET(_fail_msg_adv "${_fail_msg_adv} (version requirements: exactly ${${_name}_FIND_VERSION}") |
---|
14 | ELSE(${_name}_FIND_VERSION_EXACT) |
---|
15 | SET(_fail_msg_adv "${_fail_msg_adv} (version requirements: at least ${${_name}_FIND_VERSION}") |
---|
16 | ENDIF(${_name}_FIND_VERSION_EXACT) |
---|
17 | FIND_PACKAGE_HANDLE_STANDARD_ARGS("${_name}" "${_fail_msg_adv}" ${ARGN}) |
---|
18 | STRING(TOUPPER ${_name} _NAME_UPPER) |
---|
19 | |
---|
20 | # Also check version requirements if given to FindPackage(...) |
---|
21 | IF(${_name}_FIND_VERSION) |
---|
22 | # Note: the last argument of the function tells it to cut the first |
---|
23 | # version string instead of padding it with zeros if necessary |
---|
24 | COMPARE_VERSION_STRINGS("${_version}" "${${_name}_FIND_VERSION}" _compatible TRUE) |
---|
25 | IF(${_name}_FIND_VERSION_EXACT AND NOT _compatible EQUAL 0) |
---|
26 | MESSAGE(FATAL_ERROR "Exact ${_name} version required is ${${_name}_FIND_VERSION}\n" |
---|
27 | "Your version is ${_version}") |
---|
28 | SET(${_NAME_UPPER}_FOUND FALSE) |
---|
29 | ELSEIF(_compatible LESS 0) |
---|
30 | MESSAGE(FATAL_ERROR "Minimum ${_name} version required is ${${_name}_FIND_VERSION}\n" |
---|
31 | "Your version is ${_version}") |
---|
32 | SET(${_NAME_UPPER}_FOUND FALSE) |
---|
33 | ENDIF(${_name}_FIND_VERSION_EXACT AND NOT _compatible EQUAL 0) |
---|
34 | ENDIF(${_name}_FIND_VERSION) |
---|
35 | |
---|
36 | # Raise scope (FindPackageHandleStandardArgs uses PARENT_SCOPE) |
---|
37 | SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE) |
---|
38 | |
---|
39 | ENDFUNCTION(FIND_PACKAGE_HANDLE_ADVANCED_ARGS) |
---|