Python3SABIModule.cmake 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. enable_language(C)
  2. include(CTest)
  3. find_package(Python3 REQUIRED COMPONENTS Interpreter Development.SABIModule)
  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.Embed_FOUND)
  11. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
  12. endif()
  13. if (Python3_Development.Module_FOUND)
  14. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' unexpectedly found")
  15. endif()
  16. if (NOT Python3_Development.SABIModule_FOUND)
  17. message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' 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::Module)
  26. message(SEND_ERROR "Python3::Module unexpectedly found")
  27. endif()
  28. if(NOT TARGET Python3::SABIModule)
  29. message(SEND_ERROR "Python3::SABIModule not found")
  30. endif()
  31. if (Python3_VERSION VERSION_GREATER_EQUAL "3.2" AND NOT DEFINED Python3_SOSABI)
  32. message(FATAL_ERROR "Python3_SOSABI unexpectedly not defined")
  33. endif()
  34. Python3_add_library (spam3 MODULE USE_SABI 3 WITH_SOABI spam.c)
  35. target_compile_definitions (spam3 PRIVATE PYTHON3)
  36. if (Python3_SOSABI)
  37. get_property (suffix TARGET spam3 PROPERTY SUFFIX)
  38. if (NOT suffix MATCHES "^\\.${Python3_SOSABI}")
  39. message(FATAL_ERROR "Module suffix do not include Python3_SOSABI")
  40. endif()
  41. endif()
  42. add_test (NAME python3_spam3
  43. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>"
  44. "${Python3_INTERPRETER}" -c "import spam3; spam3.system(\"cd\")")