1
0

CMakeLists.txt 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. cmake_minimum_required(VERSION 3.1)
  2. project(TestPython C)
  3. include(CTest)
  4. find_package(Python ${Python_REQUESTED_VERSION} REQUIRED COMPONENTS Interpreter Development)
  5. if (NOT Python_FOUND)
  6. message (FATAL_ERROR "Fail to found Python ${Python_REQUESTED_VERSION}")
  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. if (Python_REQUESTED_VERSION)
  18. Python_add_library (spam${Python_REQUESTED_VERSION} MODULE ../spam.c)
  19. target_compile_definitions (spam${Python_REQUESTED_VERSION} PRIVATE PYTHON${Python_REQUESTED_VERSION})
  20. add_test (NAME python_spam${Python_REQUESTED_VERSION}
  21. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam${Python_REQUESTED_VERSION}>"
  22. "${Python_EXECUTABLE}" -c "import spam${Python_REQUESTED_VERSION}; spam${Python_REQUESTED_VERSION}.system(\"cd\")")
  23. else()
  24. add_test(NAME findpython_script
  25. COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python
  26. -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake")
  27. endif()