SOABI.cmake 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. enable_language(C)
  2. if(CMake_TEST_FindPython3)
  3. find_package(Python3 COMPONENTS ${CMake_TEST_FindPython_COMPONENT})
  4. if (NOT Python3_FOUND)
  5. message (FATAL_ERROR "Failed to find Python 3")
  6. endif()
  7. if(NOT DEFINED Python3_SOABI)
  8. message(FATAL_ERROR "Python3_SOABI for ${CMake_TEST_FindPython_COMPONENT} not found")
  9. endif()
  10. if (Python3_Development_FOUND AND Python3_SOABI)
  11. Python3_add_library (spam3 MODULE WITH_SOABI spam.c)
  12. target_compile_definitions (spam3 PRIVATE PYTHON3)
  13. get_property (suffix TARGET spam3 PROPERTY SUFFIX)
  14. if (NOT suffix MATCHES "^.${Python3_SOABI}")
  15. message(FATAL_ERROR "Module suffix do not include Python3_SOABI")
  16. endif()
  17. endif()
  18. endif()
  19. if(CMake_TEST_FindPython2)
  20. find_package(Python2 COMPONENTS ${CMake_TEST_FindPython_COMPONENT})
  21. if(NOT DEFINED Python2_SOABI)
  22. message(FATAL_ERROR "Python2_SOABI for ${CMake_TEST_FindPython_COMPONENT} not found")
  23. endif()
  24. if (Python2_Development_FOUND AND Python2_SOABI)
  25. Python2_add_library (spam2 MODULE WITH_SOABI spam.c)
  26. target_compile_definitions (spam2 PRIVATE PYTHON2)
  27. get_property (suffix TARGET spam2 PROPERTY SUFFIX)
  28. if (NOT suffix MATCHES "^.${Python2_SOABI}")
  29. message(FATAL_ERROR "Module suffix do not include Python2_SOABI")
  30. endif()
  31. endif()
  32. endif()