protobuf-config-version.cmake.in 2.7 KB

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