Python3Embedded.cmake 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. enable_language(C)
  2. include(CTest)
  3. find_package(Python3 REQUIRED COMPONENTS Development.Embed)
  4. if (NOT Python3_FOUND)
  5. message (FATAL_ERROR "Failed to find Python 3")
  6. endif()
  7. if (Python3_Development_FOUND)
  8. message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
  9. endif()
  10. if (Python3_Development.Module_FOUND)
  11. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' unexpectedly found")
  12. endif()
  13. if (NOT Python3_Development.Embed_FOUND)
  14. message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' not found")
  15. endif()
  16. if(TARGET Python3::Module)
  17. message(SEND_ERROR "Python3::Module unexpectedly found")
  18. endif()
  19. if(NOT TARGET Python3::Python)
  20. message(SEND_ERROR "Python3::Python not found")
  21. endif()
  22. Python3_add_library (display_time3 SHARED display_time.c)
  23. set_property (TARGET display_time3 PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
  24. target_compile_definitions (display_time3 PRIVATE PYTHON3)
  25. add_executable (main3 main.c)
  26. target_link_libraries (main3 PRIVATE display_time3)
  27. if (WIN32 OR CYGWIN OR MSYS OR MINGW)
  28. list (JOIN Python3_RUNTIME_LIBRARY_DIRS "$<SEMICOLON>" RUNTIME_DIRS)
  29. add_test (NAME Python3.Embedded COMMAND "${CMAKE_COMMAND}" -E env "PATH=${RUNTIME_DIRS}" $<TARGET_FILE:main3>)
  30. else()
  31. add_test (NAME Python3.Embedded COMMAND main3)
  32. endif()
  33. set_property (TEST Python3.Embedded PROPERTY PASS_REGULAR_EXPRESSION "Today is")