klayout/setup.py

255 lines
8.9 KiB
Python
Raw Normal View History

2018-07-15 00:01:37 +02:00
2018-07-15 12:12:05 +02:00
"""
KLayout standalone Python module setup script
Copyright (C) 2006-2018 Matthias Koefferlein
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.
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.
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
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
of libraries providing the actual implementation part.
The Python extension libraries reference the implementation libraries.
The extension libraries are prefixed with an underscore.
For example:
tl (Python) -> _tl, _gsi
There is a specific issue with the building of the extension
libraries: distutils only allows building of shared objects
as extension libraries and does not provide a intrinsic feature
for linking other libraries into the extension library.
Hence we need to add the dependencies through "extra_objects".
On Linux there is a specific issue: The shared objects produced
for extension libraries are not matching the Linux name conventions.
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
"-Wl,-soname" on Linux (see Config.link_args).
"""
2018-07-15 00:01:37 +02:00
from distutils.core import setup, Extension, Distribution
import glob
2018-07-15 00:30:12 +02:00
import os
import sysconfig
2018-07-15 00:01:37 +02:00
2018-07-15 12:12:05 +02:00
# ----------------------------------------------------------------------------------------
2018-07-15 00:30:12 +02:00
class Config(object):
2018-07-15 00:01:37 +02:00
2018-07-15 12:12:05 +02:00
"""
Provides some configuration-specific methods
"""
2018-07-15 00:30:12 +02:00
def __init__(self):
2018-07-15 00:01:37 +02:00
2018-07-15 00:42:18 +02:00
# TODO: is this really how we get the build paths?
2018-07-15 00:30:12 +02:00
build_cmd = Distribution().get_command_obj('build')
build_cmd.finalize_options()
self.build_platlib = build_cmd.build_platlib
2018-07-15 00:01:37 +02:00
2018-07-15 00:42:18 +02:00
install_cmd = Distribution().get_command_obj('install')
install_cmd.finalize_options()
self.install_platlib = install_cmd.install_platlib
2018-07-15 00:30:12 +02:00
self.ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
2018-07-15 12:12:05 +02:00
self.root = "klayout"
2018-07-15 00:30:12 +02:00
def libname_of(self, mod):
2018-07-15 12:12:05 +02:00
"""
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").
"""
2018-07-15 00:30:12 +02:00
return mod + self.ext_suffix
def path_of(self, mod):
2018-07-15 12:12:05 +02:00
"""
Returns the build path of the library for a given module
"""
return os.path.join(self.build_platlib, self.root, self.libname_of(mod))
2018-07-15 00:30:12 +02:00
def rpath(self):
2018-07-15 12:12:05 +02:00
"""
Returns the runtime_library_dir to use when linking the modules
This path will ensure the auxiliary modules are found at runtime.
"""
return [ os.path.join(self.install_platlib, self.root) ]
2018-07-15 00:30:12 +02:00
def link_args(self, mod):
2018-07-15 12:12:05 +02:00
"""
Gets additional linker arguments
"""
2018-07-15 00:42:18 +02:00
if os.name == "nt":
return [ ]
else:
# this makes the libraries suitable for linking with a path -
2018-07-15 12:12:05 +02:00
# 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-15 00:42:18 +02:00
return ['-Wl,-soname,' + self.libname_of(mod)]
2018-07-15 00:30:12 +02:00
2018-07-15 12:12:05 +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 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")
_tl_sources.remove("src/tl/tl/tlFileSystemWatcher.cc")
_tl_sources.remove("src/tl/tl/tlDeferredExecutionQt.cc")
_tl = Extension('klayout._tl',
2018-07-15 12:12:05 +02:00
define_macros = config.macros() + [ ('MAKE_TL_LIBRARY', 1) ],
2018-07-15 00:01:37 +02:00
language = 'c++',
2018-07-15 12:12:05 +02:00
libraries = [ 'curl', 'expat' ],
2018-07-15 00:30:12 +02:00
extra_link_args = config.link_args('_tl'),
2018-07-15 00:01:37 +02:00
sources = _tl_sources)
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")
_gsi = Extension('klayout._gsi',
2018-07-15 12:12:05 +02:00
define_macros = config.macros() + [ ('MAKE_GSI_LIBRARY', 1) ],
2018-07-15 00:01:37 +02:00
include_dirs = [ 'src/tl/tl' ],
2018-07-15 00:30:12 +02:00
extra_objects = [ config.path_of('_tl') ],
runtime_library_dirs = config.rpath(),
2018-07-15 00:01:37 +02:00
language = 'c++',
2018-07-15 00:30:12 +02:00
extra_link_args = config.link_args('_gsi'),
2018-07-15 00:01:37 +02:00
sources = _gsi_sources)
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")
_pya = Extension('klayout._pya',
2018-07-15 12:12:05 +02:00
define_macros = config.macros() + [ ('MAKE_PYA_LIBRARY', 1) ],
2018-07-15 00:01:37 +02:00
include_dirs = [ 'src/tl/tl', 'src/gsi/gsi' ],
2018-07-15 00:30:12 +02:00
extra_objects = [ config.path_of('_tl'), config.path_of('_gsi') ],
runtime_library_dirs = config.rpath(),
2018-07-15 00:01:37 +02:00
language = 'c++',
2018-07-15 00:30:12 +02:00
extra_link_args = config.link_args('_pya'),
2018-07-15 00:01:37 +02:00
sources = _pya_sources)
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")
_db = Extension('klayout._db',
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') ],
runtime_library_dirs = config.rpath(),
language = 'c++',
extra_link_args = config.link_args('_db'),
sources = _db_sources)
# ------------------------------------------------------------------
# _rdb dependency library
_rdb_sources = glob.glob("src/rdb/rdb/*.cc")
_rdb = Extension('klayout._rdb',
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') ],
runtime_library_dirs = config.rpath(),
language = 'c++',
extra_link_args = config.link_args('_rdb'),
sources = _rdb_sources)
# ------------------------------------------------------------------
# tl extension library
2018-07-15 00:01:37 +02:00
tl_sources = glob.glob("src/pymod/tl/*.cc")
tl = Extension('klayout.tl',
2018-07-15 12:12:05 +02:00
define_macros = config.macros(),
2018-07-15 00:01:37 +02:00
include_dirs = [ 'src/tl/tl', 'src/gsi/gsi', 'src/pya/pya' ],
2018-07-15 00:30:12 +02:00
extra_objects = [ config.path_of('_tl'), config.path_of('_gsi'), config.path_of('_pya') ],
runtime_library_dirs = config.rpath(),
2018-07-15 00:01:37 +02:00
sources = tl_sources)
2018-07-15 12:12:05 +02:00
# ------------------------------------------------------------------
# db extension library
db_sources = glob.glob("src/pymod/db/*.cc")
db = Extension('klayout.db',
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') ],
runtime_library_dirs = config.rpath(),
sources = db_sources)
# ------------------------------------------------------------------
# rdb extension library
rdb_sources = glob.glob("src/pymod/rdb/*.cc")
rdb = Extension('klayout.rdb',
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') ],
runtime_library_dirs = config.rpath(),
sources = rdb_sources)
# ------------------------------------------------------------------
# Core setup function
2018-07-15 00:42:18 +02:00
setup (name = 'klayout',
2018-07-15 12:12:05 +02:00
version = config.version(),
2018-07-15 00:01:37 +02:00
description = 'KLayout standalone Python package',
author = 'Matthias Koefferlein',
author_email = 'matthias@klayout.de',
2018-07-15 12:12:05 +02:00
ext_modules = [ _tl, _gsi, _pya, _db, _rdb, tl, db, rdb ])