CMakeLists.txt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. cmake_minimum_required(VERSION 3.5)
  2. project(TestExactVersion LANGUAGES C)
  3. find_package(Python${Python_MAJOR_VERSION} ${Python_REQUESTED_VERSION} COMPONENTS Interpreter Development)
  4. if(NOT Python${Python_MAJOR_VERSION}_FOUND)
  5. message (FATAL_ERROR "Failed to find Python ${Python_REQUESTED_VERSION}")
  6. endif()
  7. if(NOT Python${Python_MAJOR_VERSION}_Interpreter_FOUND)
  8. message (FATAL_ERROR "Failed to find Python ${Python_REQUESTED_VERSION} Interpreter")
  9. endif()
  10. if(NOT Python${Python_MAJOR_VERSION}_Development_FOUND)
  11. message (FATAL_ERROR "Failed to find Python ${Python_REQUESTED_VERSION} Development")
  12. endif()
  13. if(NOT TARGET Python${Python_MAJOR_VERSION}::Interpreter)
  14. message(SEND_ERROR "Python${Python_MAJOR_VERSION}::Interpreter not found")
  15. endif()
  16. if(NOT TARGET Python${Python_MAJOR_VERSION}::Python)
  17. message(SEND_ERROR "Python${Python_MAJOR_VERSION}::Python not found")
  18. endif()
  19. if(NOT TARGET Python${Python_MAJOR_VERSION}::Module)
  20. message(SEND_ERROR "Python${Python_MAJOR_VERSION}::Module not found")
  21. endif()
  22. # reset artifacts and second search with exact version already founded
  23. unset(Python${Python_MAJOR_VERSION}_EXECUTABLE)
  24. unset(_Python${Python_MAJOR_VERSION}_EXECUTABLE CACHE)
  25. unset(_Python${Python_MAJOR_VERSION}_LIBRARY_RELEASE CACHE)
  26. unset(_Python${Python_MAJOR_VERSION}_INCLUDE_DIR CACHE)
  27. set(Python_REQUESTED_VERSION ${Python${Python_MAJOR_VERSION}_VERSION})
  28. find_package(Python${Python_MAJOR_VERSION} ${Python_REQUESTED_VERSION} EXACT COMPONENTS Interpreter Development)
  29. if(NOT Python${Python_MAJOR_VERSION}_FOUND)
  30. message (FATAL_ERROR "Failed to find Python ${Python_REQUESTED_VERSION}")
  31. endif()
  32. if(NOT Python${Python_MAJOR_VERSION}_Interpreter_FOUND)
  33. message (FATAL_ERROR "Failed to find Python ${Python_REQUESTED_VERSION} Interpreter")
  34. endif()
  35. if(NOT Python${Python_MAJOR_VERSION}_Development_FOUND)
  36. message (FATAL_ERROR "Failed to find Python ${Python_REQUESTED_VERSION} Development")
  37. endif()
  38. if(NOT TARGET Python${Python_MAJOR_VERSION}::Interpreter)
  39. message(SEND_ERROR "Python${Python_MAJOR_VERSION}::Interpreter not found")
  40. endif()
  41. if(NOT TARGET Python${Python_MAJOR_VERSION}::Python)
  42. message(SEND_ERROR "Python${Python_MAJOR_VERSION}::Python not found")
  43. endif()
  44. if(NOT TARGET Python${Python_MAJOR_VERSION}::Module)
  45. message(SEND_ERROR "Python${Python_MAJOR_VERSION}::Module not found")
  46. endif()