blob: 3fa01763ee65365edafad15443d8f08e7afc3884 [file] [log] [blame]
Walter Gray0420eab2016-05-27 22:55:57 -07001set(PACKAGE_VERSION "@protobuf_VERSION@")
Walter Gray5ebcfc12016-06-09 15:38:39 -07002set(${PACKAGE_FIND_NAME}_VERSION_PRERELEASE "@protobuf_VERSION_PRERELEASE@" PARENT_SCOPE)
Walter Gray02a28a82016-05-19 15:24:18 -07003
Walter Gray5ebcfc12016-06-09 15:38:39 -07004# Prerelease versions cannot be passed in directly via the find_package command,
5# so we allow users to specify it in a variable
Walter Gray55204472016-07-12 15:19:32 -07006if(NOT DEFINED "${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE")
Walter Gray5ebcfc12016-06-09 15:38:39 -07007 set("${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}" "")
8else()
9 set(PACKAGE_FIND_VERSION ${PACKAGE_FIND_VERSION}-${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE})
10endif()
11set(PACKAGE_FIND_VERSION_PRERELEASE "${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}")
12
13# VERSION_EQUAL ignores the prerelease strings, so we use STREQUAL.
Walter Gray0420eab2016-05-27 22:55:57 -070014if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
15 set(PACKAGE_VERSION_EXACT TRUE)
Walter Gray02a28a82016-05-19 15:24:18 -070016endif()
17
Walter Gray0420eab2016-05-27 22:55:57 -070018set(PACKAGE_VERSION_COMPATIBLE TRUE) #Assume true until shown otherwise
19
Walter Grayae85cb82017-05-30 14:07:34 -070020if(PACKAGE_FIND_VERSION) #Only perform version checks if one is given
21 if(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL "@protobuf_VERSION_MAJOR@")
Walter Gray0420eab2016-05-27 22:55:57 -070022 set(PACKAGE_VERSION_COMPATIBLE FALSE)
Walter Grayae85cb82017-05-30 14:07:34 -070023 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()
Walter Gray0420eab2016-05-27 22:55:57 -070031
Walter Grayae85cb82017-05-30 14:07:34 -070032 # 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()
Walter Gray0420eab2016-05-27 22:55:57 -070036 endif()
37endif()
Walter Gray02a28a82016-05-19 15:24:18 -070038
Walter Gray78b34982016-06-09 13:03:59 -070039# Check and save build options used to create this package
40macro(_check_and_save_build_option OPTION VALUE)
41 if(DEFINED ${PACKAGE_FIND_NAME}_${OPTION} AND
Walter Graya183a0d2017-05-30 14:11:46 -070042 NOT ${PACKAGE_FIND_NAME}_${OPTION} STREQUAL ${VALUE})
Walter Gray78b34982016-06-09 13:03:59 -070043 set(PACKAGE_VERSION_UNSUITABLE TRUE)
44 endif()
Walter Graydf3f8cf2017-05-30 14:56:02 -070045 set(${PACKAGE_FIND_NAME}_${OPTION} ${VALUE} PARENT_SCOPE)
Walter Gray78b34982016-06-09 13:03:59 -070046endmacro()
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@)
Walter Gray02a28a82016-05-19 15:24:18 -070050
Walter Gray78b34982016-06-09 13:03:59 -070051# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
Walter Grayd8c58652017-05-30 14:09:42 -070052if(CMAKE_SIZEOF_VOID_P AND "@CMAKE_SIZEOF_VOID_P@")
Walter Gray78b34982016-06-09 13:03:59 -070053 # check that the installed version has the same 32/64bit-ness as the one which is currently searching:
Walter Grayd8c58652017-05-30 14:09:42 -070054 if(NOT CMAKE_SIZEOF_VOID_P EQUAL "@CMAKE_SIZEOF_VOID_P@")
Walter Gray78b34982016-06-09 13:03:59 -070055 math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
56 set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
57 set(PACKAGE_VERSION_UNSUITABLE TRUE)
58 endif()
Walter Gray02a28a82016-05-19 15:24:18 -070059endif()
Walter Gray0420eab2016-05-27 22:55:57 -070060