Skip to content

Commit

Permalink
Update basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
pfernique committed Aug 30, 2016
1 parent 85ce9b1 commit ba9f709
Show file tree
Hide file tree
Showing 13 changed files with 899 additions and 38 deletions.
771 changes: 759 additions & 12 deletions doc/examples/basic.ipynb

Large diffs are not rendered by default.

27 changes: 4 additions & 23 deletions doc/examples/basic/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,11 @@ env.AppendUnique(CPPDEFINES = ['BOOST_PYTHON_DYNAMIC_LIB'])
env.Prepend(CPPPATH='$PREFIX/include')
env.Prepend(LIBPATH='$PREFIX/lib')


env.AppendUnique(CXXFLAGS = ['-x', 'c++',
'-std=c++0x',
'-Wwrite-strings'])

cppenv = env.Clone()
headers = ['overload.h', 'binomial.h']
includes = cppenv.Install(os.path.join(cppenv['PREFIX'], "include", "basic"), headers)
Alias("cpp", includes)
Alias("build", includes)
sources = ['overload.cpp', 'binomial.cpp']
lib = cppenv.SharedLibrary(os.path.join(cppenv['PREFIX'], "lib", "basic"), sources)
Alias("cpp", lib)
Alias("build", lib)

wigenv = env.Clone()

pyenv = env.Clone()
pyenv.AppendUnique(LIBS = ['basic'])
pyenv.AppendUnique(CXXFLAGS = ['-ftemplate-depth-100'])

wrap = pyenv.LoadableModule('_module', pyenv.Glob('wrapper_*.cpp') + ['_module.cpp'],
LDMODULESUFFIX = '.so',
FRAMEWORKSFLAGS = '-flat_namespace -undefined suppress')
Alias("py", wrap)
Alias("build", wrap)

Default("wig")
VariantDir('build', 'src')
SConscript(os.path.join('build', 'cpp', 'SConscript'), exports="env")
SConscript(os.path.join('build', 'py', 'SConscript'), exports="env")
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package:
name: basic
name: libbasic
version: "1.0.0"

source:
path: .
path: ../..

build:
number: 0
script: scons --prefix={{ PREFIX }}
script: scons cpp --prefix={{ PREFIX }} -j{{ CPU_COUNT }}

about:
home: http://autowig.readthedocs.io/
Expand Down
25 changes: 25 additions & 0 deletions doc/examples/basic/conda/python-basic/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package:
name: python-basic
version: "1.0.0"

source:
path: ../..

build:
number: 0
script:
- scons py --prefix={{ PREFIX }} -j{{ CPU_COUNT }}
- python setup.py install

about:
home: http://autowig.readthedocs.io/
license: CeCILL-C

requirements:
build:
- scons
- libboost
- libbasic
run:
- libboost
- libbasic
20 changes: 20 additions & 0 deletions doc/examples/basic/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
from setuptools import setup, find_packages

packages = {"" : "src" + os.sep + "py"}
for package in find_packages("src" + os.sep + "py"):
packages[package] = "src" + os.sep + "py"

setup(packages = packages.keys(),
package_dir = {"" : "src" + os.sep + "py"},
name = 'basic',
version = '1.0.0',
author = 'Pierre Fernique',
author_email = 'pfernique@gmail.com',
description = 'A basic library',
long_description = 'This library is designed to be an example for AutoWIG',
license = 'none',
package_data = {package: [ "*.so", "*.dll"] for package in packages},
zip_safe = False)


29 changes: 29 additions & 0 deletions doc/examples/basic/src/cpp/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*-python-*-


import SCons.Action
import SCons.Builder
import SCons.Scanner.C
import SCons.Util
import SCons.Script

import os
bn = os.path.basename

Import("env")

cppenv = env.Clone()

headers = cppenv.Glob('*.h*')
includes = cppenv.Install(os.path.join(cppenv['PREFIX'], "include", "basic"), headers)

Alias("cpp", includes)
Alias("build", includes)

sources = cppenv.Glob('*.cpp')
if cppenv.get("static"):
lib = cppenv.StaticLibrary(os.path.join(cppenv['PREFIX'], "lib", "basic"), sources)
else:
lib = cppenv.SharedLibrary(os.path.join(cppenv['PREFIX'], "lib", "basic"), sources)
Alias("cpp", lib)
Alias("build", lib)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions doc/examples/basic/src/py/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*-python-*-

import os
import sys
import itertools
from distutils import sysconfig

operating_system = os.name.lower()
platform = sys.platform.lower()

Import("env")

pyenv = env.Clone()

header = pyenv.Glob('*.h')
if len(header) == 1:
cmd = pyenv.Command(header[0].target_from_source('', '.h.gch'), header, '$CXX -o $TARGET -x c++-header -c -fPIC $SHCXXFLAGS $_CCCOMCOM $SOURCE')

targets = list(itertools.chain(*[pyenv.SharedObject(None, source) for source in pyenv.Glob('*.cpp')]))
if len(header) == 1:
pyenv.Depends(targets, cmd)

source = pyenv.File('response_file.rsp')
with open(source.abspath, 'w') as filehandler:
filehandler.write(' '.join(target.abspath.replace('\\','/') + ' ' for target in targets))

pyenv.AppendUnique(LINKFLAGS = ['@' + source.abspath])
target = str(pyenv.File("basic/__module").srcnode())

pyenv.AppendUnique(LIBS = ['basic'])

kwargs = dict()

if operating_system == 'nt':
kwargs['SHLIBSUFFIX'] = '.pyd'
else:
kwargs['SHLIBSUFFIX'] = '.so'

kwargs['SHLIBPREFIX'] = ''

if operating_system == "posix":
pyenv.AppendUnique(CXXFLAGS = ['-ftemplate-depth-100'])



wrap = pyenv.LoadableModule(target, [], LDMODULESUFFIX='.so',
FRAMEWORKSFLAGS = '-flat_namespace -undefined suppress', **kwargs)
pyenv.Depends(wrap, targets)

Alias("py", wrap)
Alias("build", wrap)
Empty file.
8 changes: 8 additions & 0 deletions doc/examples/basic/src/py/basic/_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__all__ = []


# Import Boost.Python module
import basic.__module



0 comments on commit ba9f709

Please sign in to comment.