CMakeLists.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. cmake_minimum_required(VERSION 3.7)
  2. project(TestPython3SABIModule LANGUAGES C)
  3. include(CTest)
  4. find_package(Python3 REQUIRED COMPONENTS Interpreter Development.SABIModule)
  5. if (NOT Python3_FOUND)
  6. message (FATAL_ERROR "Failed to find Python 3")
  7. endif()
  8. if (Python3_Development_FOUND)
  9. message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
  10. endif()
  11. if (Python3_Development.Embed_FOUND)
  12. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
  13. endif()
  14. if (Python3_Development.Module_FOUND)
  15. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' unexpectedly found")
  16. endif()
  17. if (NOT Python3_Development.SABIModule_FOUND)
  18. message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' not found")
  19. endif()
  20. if(NOT TARGET Python3::Interpreter)
  21. message(SEND_ERROR "Python3::Interpreter not found")
  22. endif()
  23. if(TARGET Python3::Python)
  24. message(SEND_ERROR "Python3::Python unexpectedly found")
  25. endif()
  26. if(TARGET Python3::Module)
  27. message(SEND_ERROR "Python3::Module unexpectedly found")
  28. endif()
  29. if(NOT TARGET Python3::SABIModule)
  30. message(SEND_ERROR "Python3::SABIModule not found")
  31. endif()
  32. if (Python3_VERSION VERSION_GREATER_EQUAL "3.2" AND NOT Python3_SOSABI)
  33. message(FATAL_ERROR "Python3_SOSABI unexpectedly not defined")
  34. endif()
  35. Python3_add_library (spam3 MODULE USE_SABI 3 WITH_SOABI ../spam.c)
  36. target_compile_definitions (spam3 PRIVATE PYTHON3)
  37. if (Python3_SOSABI)
  38. get_property (suffix TARGET spam3 PROPERTY SUFFIX)
  39. if (NOT suffix MATCHES "^\\.${Python3_SOSABI}")
  40. message(FATAL_ERROR "Module suffix do not include Python3_SOSABI")
  41. endif()
  42. endif()
  43. add_test (NAME python3_spam3
  44. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>"
  45. "${Python3_EXECUTABLE}" -c "import spam3; spam3.system(\"cd\")")