CMakeLists.txt 941 B

1234567891011121314151617181920212223242526272829303132
  1. cmake_minimum_required(VERSION 3.1)
  2. project(TestPython C)
  3. include(CTest)
  4. find_package(Python 3 REQUIRED COMPONENTS Interpreter Development)
  5. if (NOT Python_FOUND)
  6. message (FATAL_ERROR "Fail to found Python 3")
  7. endif()
  8. if(NOT TARGET Python::Interpreter)
  9. message(SEND_ERROR "Python::Interpreter not found")
  10. endif()
  11. if(NOT TARGET Python::Python)
  12. message(SEND_ERROR "Python::Python not found")
  13. endif()
  14. if(NOT TARGET Python::Module)
  15. message(SEND_ERROR "Python::Module not found")
  16. endif()
  17. Python_add_library (spam3 MODULE ../spam.c)
  18. target_compile_definitions (spam3 PRIVATE PYTHON3)
  19. add_test (NAME python_spam3
  20. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>"
  21. "${Python_EXECUTABLE}" -c "import spam3; spam3.system(\"cd\")")
  22. add_test(NAME findpython_script
  23. COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python
  24. -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake")