CMakeLists.txt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 TARGET Python2::Interpreter)
  13. message(SEND_ERROR "Python2::Interpreter not found")
  14. endif()
  15. if(NOT TARGET Python2::Python)
  16. message(SEND_ERROR "Python2::Python not found")
  17. endif()
  18. if(NOT TARGET Python2::Module)
  19. message(SEND_ERROR "Python2::Module not found")
  20. endif()
  21. Python2_add_library (spam2 MODULE ../spam.c)
  22. target_compile_definitions (spam2 PRIVATE PYTHON2)
  23. add_test (NAME python2_spam2
  24. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam2>"
  25. "${Python2_EXECUTABLE}" -c "import spam2; spam2.system(\"cd\")")
  26. add_test(NAME findpython2_script
  27. COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python2
  28. -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake")