Guest User

Untitled

a guest
Dec 14th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. # Build a Python extension module using pybind11
  2. # pybindings_add_module(<module>)
  3. # Here <module> should be the fully qualified name for the module,
  4. # e.g. pybindings_add_module(foo.bar._baz)
  5. # <module> becomes the target name in case you wish to do something to it later
  6. # The source for the binding *must* be placed in src/pybindings/{relpath}/py{name}.cc
  7. # E.g. for module=foo.bar._baz -> src/pybindings/bar/py_baz.cc
  8. function(pybindings_add_module module)
  9. set(target_name ${module})
  10. string(REPLACE "." "/" modpath ${module})
  11. string(REPLACE "." ";" modlist ${module})
  12.  
  13. # The module name is the last entry
  14. list(GET modlist -1 modname)
  15.  
  16. # Remove everything that is not the root or the module name
  17. #list(REMOVE_AT modlist 0)
  18. list(REMOVE_AT modlist -1)
  19.  
  20. # Get the relative path
  21. if(modlist)
  22. string(REPLACE ";" "/" relpath "${modlist}")
  23. else()
  24. set(relpath "")
  25. endif()
  26.  
  27. # Define the binding source file
  28. set(sources src/pybindings/${relpath}/py${modname}.cc)
  29.  
  30. # Invoke pybind11 and set where the library should go, and what it is called
  31. pybind11_add_module(${target_name} ${sources})
  32. set(outdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${relpath})
  33. set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${outdir})
  34. set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${modname})
  35. endfunction()
Add Comment
Please, Sign In to add comment