WriteBasicConfigVersionFile.cmake 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #
  7. #
  8. #
  9. # ::
  10. #
  11. # WRITE_BASIC_CONFIG_VERSION_FILE( filename
  12. # [VERSION major.minor.patch]
  13. # COMPATIBILITY (AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion)
  14. # )
  15. #
  16. #
  17. #
  18. # Deprecated, see WRITE_BASIC_PACKAGE_VERSION_FILE(), it is identical.
  19. function(WRITE_BASIC_CONFIG_VERSION_FILE _filename)
  20. set(options )
  21. set(oneValueArgs VERSION COMPATIBILITY )
  22. set(multiValueArgs )
  23. cmake_parse_arguments(CVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  24. if(CVF_UNPARSED_ARGUMENTS)
  25. message(FATAL_ERROR "Unknown keywords given to WRITE_BASIC_CONFIG_VERSION_FILE(): \"${CVF_UNPARSED_ARGUMENTS}\"")
  26. endif()
  27. set(versionTemplateFile "${CMAKE_ROOT}/Modules/BasicConfigVersion-${CVF_COMPATIBILITY}.cmake.in")
  28. if(NOT EXISTS "${versionTemplateFile}")
  29. message(FATAL_ERROR "Bad COMPATIBILITY value used for WRITE_BASIC_CONFIG_VERSION_FILE(): \"${CVF_COMPATIBILITY}\"")
  30. endif()
  31. if("${CVF_VERSION}" STREQUAL "")
  32. if ("${PROJECT_VERSION}" STREQUAL "")
  33. message(FATAL_ERROR "No VERSION specified for WRITE_BASIC_CONFIG_VERSION_FILE()")
  34. else()
  35. set(CVF_VERSION "${PROJECT_VERSION}")
  36. endif()
  37. endif()
  38. configure_file("${versionTemplateFile}" "${_filename}" @ONLY)
  39. endfunction()