WriteBasicConfigVersionFile.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. WriteBasicConfigVersionFile
  5. ---------------------------
  6. .. deprecated:: 3.0
  7. Use the identical command :command:`write_basic_package_version_file()`
  8. from module :module:`CMakePackageConfigHelpers`.
  9. .. code-block:: cmake
  10. WRITE_BASIC_CONFIG_VERSION_FILE(filename
  11. [VERSION major.minor.patch]
  12. COMPATIBILITY (AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion)
  13. [ARCH_INDEPENDENT]
  14. )
  15. #]=======================================================================]
  16. function(WRITE_BASIC_CONFIG_VERSION_FILE _filename)
  17. set(options ARCH_INDEPENDENT )
  18. set(oneValueArgs VERSION COMPATIBILITY )
  19. set(multiValueArgs )
  20. cmake_parse_arguments(CVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  21. if(CVF_UNPARSED_ARGUMENTS)
  22. message(FATAL_ERROR "Unknown keywords given to WRITE_BASIC_CONFIG_VERSION_FILE(): \"${CVF_UNPARSED_ARGUMENTS}\"")
  23. endif()
  24. set(versionTemplateFile "${CMAKE_ROOT}/Modules/BasicConfigVersion-${CVF_COMPATIBILITY}.cmake.in")
  25. if(NOT EXISTS "${versionTemplateFile}")
  26. message(FATAL_ERROR "Bad COMPATIBILITY value used for WRITE_BASIC_CONFIG_VERSION_FILE(): \"${CVF_COMPATIBILITY}\"")
  27. endif()
  28. if("${CVF_VERSION}" STREQUAL "")
  29. if ("${PROJECT_VERSION}" STREQUAL "")
  30. message(FATAL_ERROR "No VERSION specified for WRITE_BASIC_CONFIG_VERSION_FILE()")
  31. else()
  32. set(CVF_VERSION "${PROJECT_VERSION}")
  33. endif()
  34. endif()
  35. if(NOT CVF_ARCH_INDEPENDENT)
  36. set(CVF_ARCH_INDEPENDENT_CHECK "
  37. # if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
  38. if(\"\${CMAKE_SIZEOF_VOID_P}\" STREQUAL \"\" OR \"${CMAKE_SIZEOF_VOID_P}\" STREQUAL \"\")
  39. return()
  40. endif()
  41. # check that the installed version has the same 32/64bit-ness as the one which is currently searching:
  42. if(NOT CMAKE_SIZEOF_VOID_P STREQUAL \"${CMAKE_SIZEOF_VOID_P}\")
  43. math(EXPR installedBits \"${CMAKE_SIZEOF_VOID_P} * 8\")
  44. set(PACKAGE_VERSION \"\${PACKAGE_VERSION} (\${installedBits}bit)\")
  45. set(PACKAGE_VERSION_UNSUITABLE TRUE)
  46. endif()")
  47. endif()
  48. configure_file("${versionTemplateFile}" "${_filename}" @ONLY)
  49. endfunction()