CMakeLists.txt 1.2 KB

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