Python2Module.cmake 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. enable_language(C)
  2. include(CTest)
  3. find_package(Python2 REQUIRED COMPONENTS Interpreter Development.Module)
  4. if (NOT Python2_FOUND)
  5. message (FATAL_ERROR "Failed to find Python 2")
  6. endif()
  7. if (Python2_Development_FOUND)
  8. message (FATAL_ERROR "Python 2, COMPONENT 'Development' unexpectedly found")
  9. endif()
  10. if (Python2_Development.Embed_FOUND)
  11. message (FATAL_ERROR "Python 2, COMPONENT 'Development.Embed' unexpectedly found")
  12. endif()
  13. if (NOT Python2_Development.Module_FOUND)
  14. message (FATAL_ERROR "Python 2, COMPONENT 'Development.Module' not found")
  15. endif()
  16. if(NOT TARGET Python2::Interpreter)
  17. message(SEND_ERROR "Python2::Interpreter not found")
  18. endif()
  19. if(TARGET Python2::Python)
  20. message(SEND_ERROR "Python2::Python unexpectedly found")
  21. endif()
  22. if(NOT TARGET Python2::Module)
  23. message(SEND_ERROR "Python2::Module not found")
  24. endif()
  25. Python2_add_library (spam2 MODULE spam.c)
  26. target_compile_definitions (spam2 PRIVATE PYTHON2)
  27. add_test (NAME python2_spam2
  28. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam2>"
  29. "${Python2_INTERPRETER}" -c "import spam2; spam2.system(\"cd\")")