CMakeLists.txt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. cmake_minimum_required(VERSION 3.1)
  2. project(TestPython3 C)
  3. include(CTest)
  4. find_package(Python3 2 QUIET)
  5. if (Python3_FOUND)
  6. message (FATAL_ERROR "Wrong python version found: ${Python3_VERSION}")
  7. endif()
  8. find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
  9. if (NOT Python3_FOUND)
  10. message (FATAL_ERROR "Fail to found Python 3")
  11. endif()
  12. if(NOT TARGET Python3::Interpreter)
  13. message(SEND_ERROR "Python2::Interpreter not found")
  14. endif()
  15. if(NOT TARGET Python3::Python)
  16. message(SEND_ERROR "Python2::Python not found")
  17. endif()
  18. if(NOT TARGET Python3::Module)
  19. message(SEND_ERROR "Python2::Module not found")
  20. endif()
  21. Python3_add_library (spam3 MODULE ../spam.c)
  22. target_compile_definitions (spam3 PRIVATE PYTHON3)
  23. add_test (NAME python3_spam3
  24. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam3>"
  25. "${Python3_EXECUTABLE}" -c "import spam3; spam3.system(\"cd\")")
  26. add_test(NAME findpython3_script
  27. COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python3
  28. -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake")