Python3Module.cmake 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. enable_language(C)
  2. include(CTest)
  3. find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
  4. if (NOT Python3_FOUND)
  5. message (FATAL_ERROR "Failed to find Python 3")
  6. endif()
  7. if (Python3_Development_FOUND)
  8. message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
  9. endif()
  10. if (Python3_Development.SABIModule_FOUND)
  11. message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' unexpectedly found")
  12. endif()
  13. if (Python3_Development.Embed_FOUND)
  14. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
  15. endif()
  16. if (NOT Python3_Development.Module_FOUND)
  17. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' not found")
  18. endif()
  19. if(NOT TARGET Python3::Interpreter)
  20. message(SEND_ERROR "Python3::Interpreter not found")
  21. endif()
  22. if(TARGET Python3::Python)
  23. message(SEND_ERROR "Python3::Python unexpectedly found")
  24. endif()
  25. if(TARGET Python3::SABIMOdule)
  26. message(SEND_ERROR "Python3::SABIModule unexpectedly found")
  27. endif()
  28. if(TARGET Python3::Embed)
  29. message(SEND_ERROR "Python3::Embed unexpectedly found")
  30. endif()
  31. if(NOT TARGET Python3::Module)
  32. message(SEND_ERROR "Python3::Module not found")
  33. endif()
  34. Python3_add_library (spam3 MODULE spam.c)
  35. target_compile_definitions (spam3 PRIVATE PYTHON3)
  36. add_test (NAME python3_spam3
  37. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>"
  38. "${Python3_INTERPRETER}" -c "import spam3; spam3.system(\"cd\")")