Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 1 | set(PACKAGE_VERSION "@protobuf_VERSION@") |
| 2 | set(${PACKAGE_FIND_NAME}_VERSION_PRERELEASE "@protobuf_VERSION_PRERELEASE@" PARENT_SCOPE) |
| 3 | |
| 4 | # Prerelease versions cannot be passed in directly via the find_package command, |
| 5 | # so we allow users to specify it in a variable |
| 6 | if(NOT DEFINED "${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE") |
| 7 | set("${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}" "") |
| 8 | else() |
| 9 | set(PACKAGE_FIND_VERSION ${PACKAGE_FIND_VERSION}-${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}) |
| 10 | endif() |
| 11 | set(PACKAGE_FIND_VERSION_PRERELEASE "${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}") |
| 12 | |
| 13 | # VERSION_EQUAL ignores the prerelease strings, so we use STREQUAL. |
| 14 | if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) |
| 15 | set(PACKAGE_VERSION_EXACT TRUE) |
| 16 | endif() |
| 17 | |
| 18 | set(PACKAGE_VERSION_COMPATIBLE TRUE) #Assume true until shown otherwise |
| 19 | |
| 20 | if(PACKAGE_FIND_VERSION) #Only perform version checks if one is given |
| 21 | if(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL "@protobuf_VERSION_MAJOR@") |
| 22 | set(PACKAGE_VERSION_COMPATIBLE FALSE) |
| 23 | elseif(PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) |
| 24 | set(PACKAGE_VERSION_COMPATIBLE FALSE) |
| 25 | elseif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) |
| 26 | # Do not match prerelease versions to non-prerelease version requests. |
| 27 | if(NOT "@protobuf_VERSION_PRERELEASE@" STREQUAL "" AND PACKAGE_FIND_VERSION_PRERELEASE STREQUAL "") |
| 28 | message(AUTHOR_WARNING "To use this prerelease version of ${PACKAGE_FIND_NAME}, set ${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE to '@protobuf_VERSION_PRERELEASE@' or greater.") |
| 29 | set(PACKAGE_VERSION_COMPATIBLE FALSE) |
| 30 | endif() |
| 31 | |
| 32 | # Not robustly SemVer compliant, but protobuf never uses '.' separated prerelease identifiers. |
| 33 | if(PACKAGE_FIND_VERSION_PRERELEASE STRGREATER "@protobuf_VERSION_PRERELEASE@") |
| 34 | set(PACKAGE_VERSION_COMPATIBLE FALSE) |
| 35 | endif() |
| 36 | endif() |
| 37 | endif() |
| 38 | |
| 39 | # Check and save build options used to create this package |
| 40 | macro(_check_and_save_build_option OPTION VALUE) |
| 41 | if(DEFINED ${PACKAGE_FIND_NAME}_${OPTION} AND |
| 42 | NOT ${PACKAGE_FIND_NAME}_${OPTION} STREQUAL ${VALUE}) |
| 43 | set(PACKAGE_VERSION_UNSUITABLE TRUE) |
| 44 | endif() |
| 45 | set(${PACKAGE_FIND_NAME}_${OPTION} ${VALUE} PARENT_SCOPE) |
| 46 | endmacro() |
| 47 | _check_and_save_build_option(WITH_ZLIB @protobuf_WITH_ZLIB@) |
| 48 | _check_and_save_build_option(MSVC_STATIC_RUNTIME @protobuf_MSVC_STATIC_RUNTIME@) |
| 49 | _check_and_save_build_option(BUILD_SHARED_LIBS @protobuf_BUILD_SHARED_LIBS@) |
| 50 | |
| 51 | # if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: |
| 52 | if(CMAKE_SIZEOF_VOID_P AND "@CMAKE_SIZEOF_VOID_P@") |
| 53 | # check that the installed version has the same 32/64bit-ness as the one which is currently searching: |
| 54 | if(NOT CMAKE_SIZEOF_VOID_P EQUAL "@CMAKE_SIZEOF_VOID_P@") |
| 55 | math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8") |
| 56 | set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") |
| 57 | set(PACKAGE_VERSION_UNSUITABLE TRUE) |
| 58 | endif() |
| 59 | endif() |
| 60 | |