Just a collection of Boost Python examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.8KB

  1. #!/usr/bin/env python3
  2. from os import environ
  3. from os.path import join
  4. from setuptools import setup, Extension, find_packages
  5. from setuptools.command.build_ext import build_ext
  6. def pEpLog(*msg):
  7. import inspect
  8. msgstr = ''
  9. separator = ' '
  10. for m in msg:
  11. msgstr += str(m)
  12. msgstr += separator
  13. func = inspect.currentframe().f_back.f_code
  14. print(func.co_filename + " : " + func.co_name + " : " + msgstr)
  15. class CustomBuildExt(build_ext):
  16. user_options = build_ext.user_options + [
  17. ('prefix=', None, 'additional dir for libs/includes')
  18. ]
  19. def initialize_options(self):
  20. build_ext.initialize_options(self)
  21. self.prefix = getattr(self, "prefix=", None)
  22. def get_build_info_linux(self):
  23. home = environ.get('HOME')
  24. sys_includes = [
  25. '/usr/local/include',
  26. ]
  27. sys_libdirs = []
  28. libs = [
  29. 'boost_python37',
  30. 'boost_locale'
  31. ]
  32. return (home, sys_includes, sys_libdirs, libs)
  33. def finalize_options(self):
  34. build_ext.finalize_options(self)
  35. pEpLog("debug: ", self.debug)
  36. pEpLog("prefix: ", self.prefix)
  37. build_info = self.get_build_info_linux()
  38. (home, sys_includes, sys_libdirs, libs) = build_info
  39. # Build the Includes -I and Library paths -L
  40. # Start empty
  41. includes = []
  42. libdirs = []
  43. # Append prefix-dir
  44. if self.prefix:
  45. pEpLog("using prefix=",self.prefix)
  46. prefix_include=[ join(self.prefix, 'include') ]
  47. prefix_libdirs=[ join(self.prefix, 'lib') ]
  48. includes += prefix_include
  49. libdirs += prefix_libdirs
  50. # Append default system dirs
  51. includes += sys_includes
  52. libdirs += sys_libdirs
  53. # Compile flags
  54. compile_flags = ['-std=c++14']
  55. if self.debug:
  56. pEpLog("debug build mode")
  57. compile_flags += ['-O0', '-g', '-UNDEBUG']
  58. # Apply the build information
  59. global hello_world
  60. hello_world.include_dirs = includes
  61. hello_world.library_dirs = libdirs
  62. hello_world.libraries = libs
  63. hello_world.extra_compile_args = compile_flags
  64. pEpLog("Include Dirs:", hello_world.include_dirs)
  65. pEpLog("Libs Dirs:", hello_world.library_dirs)
  66. pEpLog("Libraries:", hello_world.libraries)
  67. pEpLog("Compile flags:", hello_world.extra_compile_args)
  68. def run(self):
  69. build_ext.run(self)
  70. hello_world = Extension(
  71. name = '_hello_world',
  72. sources = ['src/hello_world/_hello_world/_hello_world.cc']
  73. )
  74. # "MAIN" Function
  75. setup(
  76. name='hello_world',
  77. version='0.1',
  78. package_dir={'':'src'},
  79. packages=['hello_world'],
  80. ext_modules=[hello_world],
  81. cmdclass={
  82. 'build_ext': CustomBuildExt,
  83. }
  84. )