There is a seemingly undocumented feature of setup that can do this, for example:
import os
from setuptools import setup
from Cython.Build import cythonize
ext_lib_path = 'rectangle'
include_dir = os.path.join(ext_lib_path, 'include')
sources = ['Rectangle.cpp']
# Use as macros = [('<DEFINITION>', '<VALUE>')]
# where value can be None
macros = None
ext_libraries = [['rectangle', {
'sources': [os.path.join(ext_lib_path, src) for src in sources],
'include_dirs': [include_dir],
'macros': macros,
}
]]
extensions = [Extension("rect",
sources=["rect.pyx"],
language="c++",
include_dirs=[include_dir],
libraries=['rectangle'],
)]
setup(ext_modules=cythonize(extensions),
libraries=ext_libraries)
The libraries argument builds the external library found in directory rectangle, with include directory rectangle/include common between it and the extension.
Have also switched the import to setuptools from distutils which is deprecated, now part of setuptools.
Have not seen any documentation on this argument but seen it used in other projects.
This is untested, please provide sample files for testing if it does not work.