CMakeLists.txt 995 B

12345678910111213141516171819202122232425262728293031323334
  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. Python2_add_library (spam2 MODULE ../spam.c)
  19. target_compile_definitions (spam2 PRIVATE PYTHON2)
  20. add_test (NAME python2_spam2
  21. COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam2>"
  22. "${Python2_EXECUTABLE}" -c "import spam2; spam2.system(\"cd\")")
  23. add_test(NAME findpython2_script
  24. COMMAND "${CMAKE_COMMAND}" -DPYTHON_PACKAGE_NAME=Python2
  25. -P "${CMAKE_CURRENT_LIST_DIR}/../FindPythonScript.cmake")