CMakeLists.txt 1.4 KB

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