build pip package for linux

This commit is contained in:
Naoto Kondo
2022-03-21 16:53:26 +09:00
parent 3f7098c03b
commit b82b43cb7e
2 changed files with 45 additions and 32 deletions

View File

@@ -30,7 +30,6 @@ set_target_properties(NDIlib PROPERTIES INSTALL_RPATH_USE_LINK_PATH FALSE)
set_target_properties(NDIlib PROPERTIES INSTALL_RPATH "$ORIGIN")
# install
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
install(
TARGETS NDIlib
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}
@@ -43,4 +42,13 @@ install(
"${NDI_DIR}/Bin/x64/Processing.NDI.Lib.Licenses.txt"
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
elseif(UNIX)
file(GLOB DLL "${NDI_LIBRARY_DIR}/libndi.so*")
file(GLOB LICENSE "${NDI_LICENSE_DIR}/*.txt")
install(
FILES
${DLL}
${LICENSE}
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endif()

View File

@@ -1,49 +1,54 @@
import os
import pathlib
import shutil
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.build_ext import build_ext
class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])
class build_ext(_build_ext):
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
build_dir = pathlib.Path('build').absolute()
build_dir.mkdir(exist_ok=True)
class CMakeBuild(build_ext):
def run(self):
# build and install
cwd = os.getcwd()
build_dir = os.path.join(cwd, 'build')
os.makedirs(build_dir, exist_ok=True)
os.chdir(build_dir)
install_dir = os.path.join(build_dir, 'install')
if not self.dry_run:
self.spawn(['cmake', '..'])
self.spawn(
['cmake', '..', '-DCMAKE_INSTALL_PREFIX=%s' % install_dir])
if self.debug:
self.spawn(['cmake', '--build', '.', '--config', 'Debug', '--target', 'install'])
self.spawn(['cmake', '--build', '.', '--config',
'Debug', '--target', 'install'])
else:
self.spawn(['cmake', '--build', '.', '--config', 'Release', '--target', 'install'])
self.spawn(['cmake', '--build', '.', '--config',
'Release', '--target', 'install'])
os.chdir(cwd)
# move
for ext in self.extensions:
dst_dir = os.path.dirname(self.get_ext_fullpath(ext.name))
lib_dir = os.path.join(dst_dir, 'NDIlib')
os.makedirs(lib_dir, exist_ok=True)
files = os.listdir(install_dir)
for filename in files:
filepath = os.path.join(install_dir, filename)
if os.path.isfile(filepath):
shutil.copy(filepath, lib_dir)
class build_py(_build_py):
def run(self):
self.run_command('build_ext')
return super().run()
setup(
name="ndi-python",
version="5.1.1",
description="Wrapper package for NDI SDK python bindings.",
author="Naoto Kondo <cgigcp3yqt@gmail.com>",
name='ndi-python',
version='5.1.1',
description='Wrapper package for NDI SDK python bindings.',
author='Naoto Kondo <cgigcp3yqt@gmail.com>',
url='https://github.com/buresu/ndi-python',
license="MIT",
ext_modules=[CMakeExtension('')],
cmdclass={
'build_py': build_py,
'build_ext': build_ext},
packages=[''],
package_data={'':['*.so', '*.pyd', '*.dll', '*.dylib', '*.txt']},
include_package_data=False,
python_requires='>=3.4',
ext_modules=[CMakeExtension('NDIlib')],
cmdclass={'build_ext': CMakeBuild},
packages=['NDIlib'],
package_data={'NDIlib': ['*.so*', '*.pyd', '*.dll', '*.dylib', '*.txt']},
zip_safe=False
)