RequiredArtifacts.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. enable_language(C)
  2. include(CTest)
  3. if(CMake_TEST_FindPython2)
  4. find_package(Python2 REQUIRED COMPONENTS Interpreter Development)
  5. if (NOT Python2_FOUND)
  6. message (FATAL_ERROR "Failed to find Python 2")
  7. endif()
  8. set(USER_EXECUTABLE "${Python2_EXECUTABLE}")
  9. set(USER_LIBRARY "${Python2_LIBRARY_RELEASE}")
  10. set(USER_INCLUDE_DIR "${Python2_INCLUDE_DIRS}")
  11. else()
  12. set(USER_EXECUTABLE "/path/to/invalid-exe${CMAKE_EXECUTABLE_SUFFIX}")
  13. set(USER_LIBRARY "/path/to/invalid-lib${CMAKE_C_LINK_LIBRARY_SUFFIX}")
  14. set(USER_INCLUDE_DIR "/path/to/invalid/dir")
  15. endif()
  16. # check some combinations for modules search without interpreter
  17. if(CMake_TEST_FindPython3_SABIModule)
  18. block(SCOPE_FOR VARIABLES)
  19. find_package(Python3 REQUIRED COMPONENTS Development.SABIModule)
  20. if (NOT Python3_FOUND)
  21. message (FATAL_ERROR "Failed to find Python 3")
  22. endif()
  23. if (Python3_Development_FOUND)
  24. message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
  25. endif()
  26. if (Python3_Interpreter_FOUND)
  27. message (FATAL_ERROR "Python 3, COMPONENT 'Interpreter' unexpectedly found")
  28. endif()
  29. if (Python3_Development.Embed_FOUND)
  30. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
  31. endif()
  32. if (Python3_Development.Module_FOUND)
  33. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' unexpectedly found")
  34. endif()
  35. if (NOT Python3_Development.SABIModule_FOUND)
  36. message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' not found")
  37. endif()
  38. unset(_Python3_SABI_LIBRARY_RELEASE CACHE)
  39. endblock()
  40. endif()
  41. block(SCOPE_FOR VARIABLES)
  42. set(components Development.Module)
  43. if (CMake_TEST_FindPython3_SABIModule)
  44. list (APPEND components Development.SABIModule)
  45. endif()
  46. find_package(Python3 REQUIRED COMPONENTS ${components})
  47. if (NOT Python3_FOUND)
  48. message (FATAL_ERROR "Failed to find Python 3")
  49. endif()
  50. if (Python3_Development_FOUND)
  51. message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
  52. endif()
  53. if (Python3_Interpreter_FOUND)
  54. message (FATAL_ERROR "Python 3, COMPONENT 'Interpreter' unexpectedly found")
  55. endif()
  56. if (Python3_Development.Embed_FOUND)
  57. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
  58. endif()
  59. if (NOT Python3_Development.Module_FOUND)
  60. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' not found")
  61. endif()
  62. if (CMake_TEST_FindPython3_SABIModule AND NOT Python3_Development.SABIModule_FOUND)
  63. message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' not found")
  64. endif()
  65. unset(_Python3_LIBRARY_RELEASE CACHE)
  66. unset(_Python3_SABI_LIBRARY_RELEASE CACHE)
  67. endblock()
  68. set(components Interpreter Development)
  69. if (CMake_TEST_FindPython3_SABIModule)
  70. list (APPEND components Development.SABIModule)
  71. endif()
  72. find_package(Python3 REQUIRED COMPONENTS ${components})
  73. if (NOT Python3_FOUND)
  74. message (FATAL_ERROR "Failed to find Python 3")
  75. endif()
  76. configure_file("${CMAKE_SOURCE_DIR}/PythonArtifacts.cmake.in"
  77. "${CMAKE_BINARY_DIR}/PythonArtifacts.cmake" @ONLY)