CMakeLists.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. cmake_minimum_required (VERSION 3.18...3.19)
  2. project (TestVersionRange LANGUAGES NONE)
  3. find_package (${Python} ${Python_REQUESTED_VERSION} EXACT COMPONENTS Interpreter)
  4. if (NOT ${Python}_FOUND)
  5. message (FATAL_ERROR "Failed to find ${Python} ${Python_REQUESTED_VERSION}")
  6. endif()
  7. if (Python_REQUESTED_VERSION VERSION_LESS 3.0)
  8. set (IN_VERSION_RANGE 2.0...<3.0)
  9. set (OUT_VERSION_RANGE 2.0...<${${Python}_VERSION})
  10. else()
  11. set (IN_VERSION_RANGE 3.0...<4.0)
  12. set (OUT_VERSION_RANGE 3.0...<${${Python}_VERSION})
  13. endif()
  14. function (FIND_PYTHON EXPECTED_VERSION)
  15. unset (_${Python}_EXECUTABLE CACHE)
  16. unset (_${Python}_LIBRARY_RELEASE CACHE)
  17. unset (_${Python}_INCLUDE_DIR CACHE)
  18. unset (${Python}_FOUND)
  19. find_package (${ARGN})
  20. if (EXPECTED_VERSION STREQUAL "NONE")
  21. if (${Python}_FOUND)
  22. message (SEND_ERROR "Unexpectedly found version: ${${Python}_VERSION} for ${ARGN}")
  23. endif()
  24. return()
  25. endif()
  26. if (NOT ${Python}_FOUND)
  27. message (SEND_ERROR "Not found: ${ARGN}")
  28. elseif (NOT ${Python}_VERSION VERSION_EQUAL EXPECTED_VERSION)
  29. message (SEND_ERROR "Wrong version: ${${Python}_VERSION} for ${ARGN}")
  30. endif()
  31. endfunction()
  32. find_python (${${Python}_VERSION} ${Python} ${IN_VERSION_RANGE} COMPONENTS Interpreter)
  33. if (${Python}_FIND_IMPLEMENTATIONS STREQUAL "IronPython")
  34. find_python (${${Python}_VERSION} ${Python} ${IN_VERSION_RANGE} COMPONENTS Compiler)
  35. else()
  36. find_python (${${Python}_VERSION} ${Python} ${IN_VERSION_RANGE} COMPONENTS Development)
  37. endif()
  38. find_python ("NONE" ${Python} ${OUT_VERSION_RANGE} COMPONENTS Interpreter)
  39. if (${Python}_FIND_IMPLEMENTATIONS STREQUAL "IronPython")
  40. find_python ("NONE" ${Python} ${OUT_VERSION_RANGE} COMPONENTS Compiler)
  41. else()
  42. find_python ("NONE" ${Python} ${OUT_VERSION_RANGE} COMPONENTS Development)
  43. endif()
  44. find_python ("NONE" ${Python} 5...6 COMPONENTS Interpreter)