1
0

CMakeLists.txt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. cmake_minimum_required(VERSION 3.1)
  2. project(TestPython2 C)
  3. include(CTest)
  4. find_package(Python2 3 QUIET)
  5. if (Python2_FOUND)
  6. message (FATAL_ERROR "Wrong python version found: ${Python2_VERSION}")
  7. endif()
  8. find_package(Python2 REQUIRED COMPONENTS Interpreter Development)
  9. if (NOT Python2_FOUND)
  10. message (FATAL_ERROR "Fail to found Python 2")
  11. endif()
  12. if (NOT Python2_Development_FOUND)
  13. message (FATAL_ERROR "Fail to found Python 2 'Development' component")
  14. endif()
  15. if (NOT Python2_Development.Module_FOUND)
  16. message (FATAL_ERROR "Fail to found Python 2 'Development.Module' component")
  17. endif()
  18. if (NOT Python2_Development.Embed_FOUND)
  19. message (FATAL_ERROR "Fail to found Python 2 'Development.Embed' component")
  20. endif()
  21. if(NOT TARGET Python2::Interpreter)
  22. message(SEND_ERROR "Python2::Interpreter not found")
  23. endif()
  24. if(NOT TARGET Python2::Python)
  25. message(SEND_ERROR "Python2::Python not found")
  26. endif()
  27. if(NOT TARGET Python2::Module)
  28. message(SEND_ERROR "Python2::Module not found")
  29. endif()
  30. Python2_add_library (spam2 MODULE ../spam.c)
  31. target_compile_definitions (spam2 PRIVATE PYTHON2)
  32. add_test (NAME python2_spam2
  33. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam2>"
  34. "${Python2_EXECUTABLE}" -c "import spam2; spam2.system(\"cd\")")
  35. add_test(NAME findpython2_script
  36. COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python2
  37. -DPython2_FIND_STRATEGY=${Python2_FIND_STRATEGY}
  38. -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake")