cython.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function(target_cython_include_directories Tgt)
  2. set_property(TARGET ${Tgt} APPEND PROPERTY
  3. CYTHON_INCLUDE_DIRS ${ARGN}
  4. )
  5. endfunction()
  6. function(target_cython_options Tgt)
  7. set_property(TARGET ${Tgt} APPEND PROPERTY
  8. CYTHON_OPTIONS ${ARGN}
  9. )
  10. endfunction()
  11. macro(set_python_type_for_cython Tgt Type)
  12. if (${Type} STREQUAL PY3)
  13. find_package(Python3 REQUIRED COMPONENTS Interpreter)
  14. set_property(TARGET ${Tgt} APPEND PROPERTY
  15. CYTHON_PYTHON_INTERPRETER ${Python3_EXECUTABLE}
  16. )
  17. else()
  18. find_package(Python2 REQUIRED COMPONENTS Interpreter)
  19. set_property(TARGET ${Tgt} APPEND PROPERTY
  20. CYTHON_PYTHON_INTERPRETER ${Python2_EXECUTABLE}
  21. )
  22. endif()
  23. endmacro()
  24. function(target_cython_sources Tgt Scope)
  25. foreach(Input ${ARGN})
  26. get_filename_component(OutputBase ${Input} NAME)
  27. set(CppCythonOutput ${CMAKE_CURRENT_BINARY_DIR}/${OutputBase}.cpp)
  28. add_custom_command(
  29. OUTPUT ${CppCythonOutput}
  30. COMMAND $<TARGET_GENEX_EVAL:${Tgt},$<TARGET_PROPERTY:${Tgt},CYTHON_PYTHON_INTERPRETER>> ${CMAKE_SOURCE_DIR}/contrib/tools/cython/cython.py ${Input} -o ${CppCythonOutput}
  31. "$<JOIN:$<TARGET_GENEX_EVAL:${Tgt},$<TARGET_PROPERTY:${Tgt},CYTHON_OPTIONS>>,$<SEMICOLON>>"
  32. "-I$<JOIN:$<TARGET_GENEX_EVAL:${Tgt},$<TARGET_PROPERTY:${Tgt},CYTHON_INCLUDE_DIRS>>,$<SEMICOLON>-I>"
  33. COMMAND_EXPAND_LISTS
  34. DEPENDS ${OUTPUT_INCLUDES}
  35. MAIN_DEPENDENCY ${Input}
  36. )
  37. target_sources(${Tgt} ${Scope} ${CppCythonOutput})
  38. endforeach()
  39. endfunction()