2018-07-15 00:01:37 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
KLayout standalone Python module setup script
|
|
|
|
|
|
|
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
Copyright (C) 2006-2018 Matthias Koefferlein
|
2018-07-15 12:12:05 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
2018-07-15 12:12:05 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
2018-07-15 12:12:05 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2018-07-15 12:12:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
This script provides distutils-based deployment for KLayout's
|
|
|
|
|
standalone Python modules.
|
|
|
|
|
|
|
|
|
|
The standalone libraries are basically extension modules.
|
|
|
|
|
Build requirements are:
|
|
|
|
|
* curl library
|
|
|
|
|
* expat library
|
|
|
|
|
|
|
|
|
|
The main challenge is to map KLayout's shared object architecture.
|
|
|
|
|
The structure consists of the Python extension libraries and a bunch
|
2018-07-16 07:12:11 +02:00
|
|
|
of libraries providing the actual implementation part.
|
2018-07-15 12:12:05 +02:00
|
|
|
The Python extension libraries reference the implementation libraries.
|
|
|
|
|
The extension libraries are prefixed with an underscore.
|
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
tl (Python) -> _tl, _gsi
|
2018-07-15 12:12:05 +02:00
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
There is a specific issue with the building of the extension
|
2018-07-15 12:12:05 +02:00
|
|
|
libraries: distutils only allows building of shared objects
|
|
|
|
|
as extension libraries and does not provide a intrinsic feature
|
2018-07-16 07:12:11 +02:00
|
|
|
for linking other libraries into the extension library.
|
2018-07-15 12:12:05 +02:00
|
|
|
|
|
|
|
|
Hence we need to add the dependencies through "extra_objects".
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
On Linux there is a specific issue: The shared objects produced
|
2018-07-15 12:12:05 +02:00
|
|
|
for extension libraries are not matching the Linux name conventions.
|
2018-07-16 07:12:11 +02:00
|
|
|
So we have to add them as .so link objects including the path.
|
|
|
|
|
If we do so, the runtime loading will look them up by their path
|
|
|
|
|
and won't find them. So we need to take away the path with
|
2018-07-15 12:12:05 +02:00
|
|
|
"-Wl,-soname" on Linux (see Config.link_args).
|
|
|
|
|
"""
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
from setuptools import setup, Extension, Distribution
|
2018-07-15 00:01:37 +02:00
|
|
|
import glob
|
2018-07-15 00:30:12 +02:00
|
|
|
import os
|
2018-07-15 16:42:01 +02:00
|
|
|
import platform
|
2018-07-20 00:34:28 +02:00
|
|
|
import distutils.sysconfig as sysconfig
|
2018-07-15 00:01:37 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
# ----------------------------------------------------------------------------------------
|
|
|
|
|
|
2018-07-15 00:42:18 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
class Config(object):
|
2018-07-15 00:30:12 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
"""
|
2018-07-16 07:16:36 +02:00
|
|
|
Provides some configuration-specific methods
|
2018-07-15 12:12:05 +02:00
|
|
|
"""
|
2018-07-15 00:30:12 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
|
|
# TODO: is this really how we get the build paths?
|
|
|
|
|
|
|
|
|
|
build_cmd = Distribution().get_command_obj('build')
|
|
|
|
|
build_cmd.finalize_options()
|
|
|
|
|
self.build_platlib = build_cmd.build_platlib
|
|
|
|
|
|
|
|
|
|
self.ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
|
2018-07-20 00:43:58 +02:00
|
|
|
if self.ext_suffix is None:
|
|
|
|
|
self.ext_suffix = ""
|
|
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
self.root = "klayout"
|
|
|
|
|
|
|
|
|
|
def libname_of(self, mod):
|
|
|
|
|
"""
|
|
|
|
|
Returns the library name for a given module
|
|
|
|
|
The library name is usually decorated (i.e. "tl" -> "tl.cpython-35m-x86_64-linux-gnu.so").
|
|
|
|
|
"""
|
|
|
|
|
return mod + self.ext_suffix
|
|
|
|
|
|
|
|
|
|
def path_of(self, mod):
|
|
|
|
|
"""
|
|
|
|
|
Returns the build path of the library for a given module
|
|
|
|
|
"""
|
|
|
|
|
return os.path.join(self.build_platlib, self.root, self.libname_of(mod))
|
|
|
|
|
|
|
|
|
|
def compile_args(self, mod):
|
|
|
|
|
"""
|
|
|
|
|
Gets additional compiler arguments
|
|
|
|
|
"""
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
|
return []
|
|
|
|
|
elif platform.system() == "Darwin":
|
|
|
|
|
return []
|
|
|
|
|
else:
|
|
|
|
|
# Avoids many "type-punned pointer" warnings
|
|
|
|
|
return ["-Wno-strict-aliasing"]
|
|
|
|
|
|
|
|
|
|
def link_args(self, mod):
|
|
|
|
|
"""
|
|
|
|
|
Gets additional linker arguments
|
|
|
|
|
"""
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
|
return []
|
|
|
|
|
elif platform.system() == "Darwin":
|
|
|
|
|
# For the dependency modules, make sure we produce a dylib.
|
|
|
|
|
# We can only link against such, but the bundles produced otherwise.
|
|
|
|
|
args = []
|
|
|
|
|
if mod[0] == "_":
|
|
|
|
|
args += ["-Wl,-dylib", '-Wl,-install_name,@rpath/%s' % self.libname_of(mod)]
|
2018-07-16 07:52:51 +02:00
|
|
|
args += ['-Wl,-rpath,@loader_path/']
|
2018-07-16 07:16:36 +02:00
|
|
|
return args
|
|
|
|
|
else:
|
|
|
|
|
# this makes the libraries suitable for linking with a path -
|
|
|
|
|
# i.e. from path_of('_tl'). Without this option, the path
|
|
|
|
|
# will be included in the reference and at runtime the loaded
|
|
|
|
|
# will look for the path-qualified library. But that's the
|
|
|
|
|
# build path and the loader will fail.
|
2018-07-17 01:44:30 +02:00
|
|
|
args = []
|
|
|
|
|
args += ['-Wl,-soname,' + self.libname_of(mod)]
|
2018-07-18 21:11:36 +02:00
|
|
|
if not '_dbpi' in mod:
|
|
|
|
|
loader_path = '$ORIGIN'
|
|
|
|
|
else:
|
|
|
|
|
loader_path = '$ORIGIN/..'
|
|
|
|
|
args += ['-Wl,-rpath,' + loader_path]
|
2018-07-17 01:44:30 +02:00
|
|
|
return args
|
2018-07-16 07:16:36 +02:00
|
|
|
|
|
|
|
|
def macros(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns the macros to use for building
|
|
|
|
|
"""
|
|
|
|
|
return [('HAVE_CURL', 1), ('HAVE_EXPAT', 1)]
|
|
|
|
|
|
|
|
|
|
def version(self):
|
|
|
|
|
"""
|
|
|
|
|
Gets the version string
|
|
|
|
|
"""
|
|
|
|
|
return "0.26"
|
2018-07-15 12:12:05 +02:00
|
|
|
|
2018-07-15 00:30:12 +02:00
|
|
|
config = Config()
|
2018-07-15 00:01:37 +02:00
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
2018-07-15 12:12:05 +02:00
|
|
|
# _tl dependency library
|
2018-07-15 00:01:37 +02:00
|
|
|
|
|
|
|
|
_tl_sources = glob.glob("src/tl/tl/*.cc")
|
|
|
|
|
|
|
|
|
|
# Exclude sources which are compatible with Qt only
|
|
|
|
|
_tl_sources.remove("src/tl/tl/tlHttpStreamQt.cc")
|
2018-07-15 20:05:10 +02:00
|
|
|
_tl_sources.remove("src/tl/tl/tlHttpStreamNoQt.cc")
|
2018-07-15 00:01:37 +02:00
|
|
|
_tl_sources.remove("src/tl/tl/tlFileSystemWatcher.cc")
|
|
|
|
|
_tl_sources.remove("src/tl/tl/tlDeferredExecutionQt.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
_tl = Extension(config.root + '._tl',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros() + [('MAKE_TL_LIBRARY', 1)],
|
|
|
|
|
language='c++',
|
|
|
|
|
libraries=['curl', 'expat'],
|
|
|
|
|
extra_link_args=config.link_args('_tl'),
|
|
|
|
|
extra_compile_args=config.compile_args('_tl'),
|
|
|
|
|
sources=_tl_sources)
|
2018-07-15 00:01:37 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# _gsi dependency library
|
|
|
|
|
|
2018-07-15 00:01:37 +02:00
|
|
|
_gsi_sources = glob.glob("src/gsi/gsi/*.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
_gsi = Extension(config.root + '._gsi',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros() + [('MAKE_GSI_LIBRARY', 1)],
|
|
|
|
|
include_dirs=['src/tl/tl'],
|
|
|
|
|
extra_objects=[config.path_of('_tl')],
|
|
|
|
|
language='c++',
|
|
|
|
|
extra_link_args=config.link_args('_gsi'),
|
|
|
|
|
extra_compile_args=config.compile_args('_gsi'),
|
|
|
|
|
sources=_gsi_sources)
|
2018-07-15 00:01:37 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# _pya dependency library
|
|
|
|
|
|
2018-07-15 00:01:37 +02:00
|
|
|
_pya_sources = glob.glob("src/pya/pya/*.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
_pya = Extension(config.root + '._pya',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros() + [('MAKE_PYA_LIBRARY', 1)],
|
|
|
|
|
include_dirs=['src/tl/tl', 'src/gsi/gsi'],
|
|
|
|
|
extra_objects=[config.path_of('_tl'), config.path_of('_gsi')],
|
|
|
|
|
language='c++',
|
|
|
|
|
extra_link_args=config.link_args('_pya'),
|
|
|
|
|
extra_compile_args=config.compile_args('_pya'),
|
|
|
|
|
sources=_pya_sources)
|
2018-07-15 00:01:37 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# _db dependency library
|
|
|
|
|
|
|
|
|
|
_db_sources = glob.glob("src/db/db/*.cc")
|
|
|
|
|
|
|
|
|
|
# Not a real source:
|
|
|
|
|
_db_sources.remove("src/db/db/fonts.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
_db = Extension(config.root + '._db',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros() + [('MAKE_DB_LIBRARY', 1)],
|
|
|
|
|
include_dirs=['src/tl/tl', 'src/gsi/gsi', 'src/db/db'],
|
|
|
|
|
extra_objects=[config.path_of('_tl'), config.path_of('_gsi')],
|
|
|
|
|
language='c++',
|
|
|
|
|
extra_link_args=config.link_args('_db'),
|
|
|
|
|
extra_compile_args=config.compile_args('_db'),
|
|
|
|
|
sources=_db_sources)
|
2018-07-15 12:12:05 +02:00
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# _rdb dependency library
|
|
|
|
|
|
|
|
|
|
_rdb_sources = glob.glob("src/rdb/rdb/*.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
_rdb = Extension(config.root + '._rdb',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros() + [('MAKE_RDB_LIBRARY', 1)],
|
|
|
|
|
include_dirs=['src/db/db', 'src/tl/tl', 'src/gsi/gsi'],
|
|
|
|
|
extra_objects=[config.path_of('_tl'), config.path_of(
|
|
|
|
|
'_gsi'), config.path_of('_db')],
|
|
|
|
|
language='c++',
|
|
|
|
|
extra_link_args=config.link_args('_rdb'),
|
|
|
|
|
extra_compile_args=config.compile_args('_rdb'),
|
|
|
|
|
sources=_rdb_sources)
|
2018-07-15 12:12:05 +02:00
|
|
|
|
2018-07-15 12:52:59 +02:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# dependency libraries from db_plugins
|
|
|
|
|
|
|
|
|
|
db_plugins = []
|
|
|
|
|
|
|
|
|
|
for pi in glob.glob("src/plugins/*/db_plugin") + glob.glob("src/plugins/*/*/db_plugin"):
|
|
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
mod_name = "_" + os.path.split(os.path.split(pi)[-2])[-1] + "_dbpi"
|
2018-07-15 12:52:59 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
pi_sources = glob.glob(pi + "/*.cc")
|
2018-07-15 12:52:59 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
pi_ext = Extension(config.root + '.db_plugins.' + mod_name,
|
|
|
|
|
define_macros=config.macros() + [('MAKE_DB_PLUGIN_LIBRARY', 1)],
|
|
|
|
|
include_dirs=['src/plugins/common',
|
|
|
|
|
'src/db/db', 'src/tl/tl', 'src/gsi/gsi'],
|
|
|
|
|
extra_objects=[config.path_of('_tl'), config.path_of(
|
|
|
|
|
'_gsi'), config.path_of('_db')],
|
|
|
|
|
language='c++',
|
|
|
|
|
extra_link_args=config.link_args(mod_name),
|
|
|
|
|
extra_compile_args=config.compile_args(mod_name),
|
|
|
|
|
sources=pi_sources)
|
2018-07-16 07:12:11 +02:00
|
|
|
|
2018-07-16 07:16:36 +02:00
|
|
|
db_plugins.append(pi_ext)
|
2018-07-16 07:12:11 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# tl extension library
|
|
|
|
|
|
2018-07-15 00:01:37 +02:00
|
|
|
tl_sources = glob.glob("src/pymod/tl/*.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
tl = Extension(config.root + '.tl',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros(),
|
|
|
|
|
include_dirs=['src/tl/tl', 'src/gsi/gsi', 'src/pya/pya'],
|
|
|
|
|
extra_objects=[config.path_of('_tl'), config.path_of(
|
|
|
|
|
'_gsi'), config.path_of('_pya')],
|
|
|
|
|
extra_link_args=config.link_args('tl'),
|
|
|
|
|
sources=tl_sources)
|
2018-07-15 00:01:37 +02:00
|
|
|
|
2018-07-15 12:12:05 +02:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# db extension library
|
|
|
|
|
|
|
|
|
|
db_sources = glob.glob("src/pymod/db/*.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
db = Extension(config.root + '.db',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros(),
|
|
|
|
|
include_dirs=['src/db/db', 'src/tl/tl', 'src/gsi/gsi', 'src/pya/pya'],
|
|
|
|
|
extra_objects=[config.path_of('_db'), config.path_of(
|
|
|
|
|
'_tl'), config.path_of('_gsi'), config.path_of('_pya')],
|
|
|
|
|
extra_link_args=config.link_args('db'),
|
|
|
|
|
sources=db_sources)
|
2018-07-15 12:12:05 +02:00
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# rdb extension library
|
|
|
|
|
|
|
|
|
|
rdb_sources = glob.glob("src/pymod/rdb/*.cc")
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
rdb = Extension(config.root + '.rdb',
|
2018-07-16 07:16:36 +02:00
|
|
|
define_macros=config.macros(),
|
|
|
|
|
include_dirs=['src/rdb/rdb', 'src/db/db',
|
|
|
|
|
'src/tl/tl', 'src/gsi/gsi', 'src/pya/pya'],
|
|
|
|
|
extra_objects=[config.path_of('_rdb'), config.path_of(
|
|
|
|
|
'_gsi'), config.path_of('_pya')],
|
|
|
|
|
extra_link_args=config.link_args('rdb'),
|
|
|
|
|
sources=rdb_sources)
|
2018-07-15 12:12:05 +02:00
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
|
# Core setup function
|
|
|
|
|
|
2018-07-16 07:12:11 +02:00
|
|
|
if __name__ == '__main__':
|
2018-07-16 07:16:36 +02:00
|
|
|
setup(name=config.root,
|
|
|
|
|
version=config.version(),
|
|
|
|
|
description='KLayout standalone Python package',
|
|
|
|
|
author='Matthias Koefferlein',
|
|
|
|
|
author_email='matthias@klayout.de',
|
|
|
|
|
packages=[config.root],
|
|
|
|
|
package_dir={config.root: 'src/pymod/distutils_src'},
|
|
|
|
|
ext_modules=[_tl, _gsi, _pya, _db, _rdb] + db_plugins + [tl, db, rdb])
|