Merge branch 'pip' into develop

This commit is contained in:
Naoto Kondo
2022-03-21 18:03:10 +09:00
4 changed files with 64 additions and 35 deletions

View File

@@ -27,20 +27,34 @@ set_target_properties(NDIlib PROPERTIES BUILD_RPATH_USE_ORIGIN TRUE)
set_target_properties(NDIlib PROPERTIES SKIP_BUILD_RPATH FALSE) set_target_properties(NDIlib PROPERTIES SKIP_BUILD_RPATH FALSE)
set_target_properties(NDIlib PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) set_target_properties(NDIlib PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
set_target_properties(NDIlib PROPERTIES INSTALL_RPATH_USE_LINK_PATH FALSE) set_target_properties(NDIlib PROPERTIES INSTALL_RPATH_USE_LINK_PATH FALSE)
set_target_properties(NDIlib PROPERTIES INSTALL_RPATH "$ORIGIN") set_target_properties(NDIlib PROPERTIES INSTALL_RPATH "@loader_path")
# install # install
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
install( install(
TARGETS NDIlib TARGETS NDIlib
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
) )
if(WIN32) if(WIN32)
install( install(
FILES FILES
"${NDI_DIR}/Bin/x64/Processing.NDI.Lib.x64.dll" "${NDI_DIR}/Bin/x64/Processing.NDI.Lib.x64.dll"
"${NDI_DIR}/Bin/x64/Processing.NDI.Lib.Licenses.txt" "${NDI_DIR}/Bin/x64/Processing.NDI.Lib.Licenses.txt"
DESTINATION ${CMAKE_INSTALL_PREFIX} DESTINATION ${CMAKE_INSTALL_PREFIX}
)
elseif(APPLE)
install(
FILES
"${NDI_LIBRARY_DIR}/libndi.dylib"
"${NDI_LICENSE_DIR}/libndi_licenses.txt"
DESTINATION ${CMAKE_INSTALL_PREFIX}
) )
elseif(UNIX)
file(GLOB DLL "${NDI_LIBRARY_DIR}/libndi.so*")
install(
FILES
${DLL}
"${NDI_LICENSE_DIR}/libndi_licenses.txt"
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endif() endif()

6
NDIlib/__init__.py Normal file
View File

@@ -0,0 +1,6 @@
import os
if os.name == 'nt':
os.add_dll_directory(os.path.dirname(__file__))
from .NDIlib import *

View File

@@ -5,6 +5,7 @@ if(WIN32)
string(REPLACE "\\" "/" NDI_DIR "${NDI_DIR}") string(REPLACE "\\" "/" NDI_DIR "${NDI_DIR}")
set(NDI_INCLUDE_DIR "${NDI_DIR}/Include") set(NDI_INCLUDE_DIR "${NDI_DIR}/Include")
set(NDI_LIBRARY_DIR "${NDI_DIR}/Lib/x64") set(NDI_LIBRARY_DIR "${NDI_DIR}/Lib/x64")
set(NDI_LICENSE_DIR "${NDI_DIR}/Lib/x64")
set(NDI_LIBS "Processing.NDI.Lib.x64") set(NDI_LIBS "Processing.NDI.Lib.x64")
else() else()
set(NDI_FOUND FALSE) set(NDI_FOUND FALSE)
@@ -15,6 +16,7 @@ elseif(APPLE)
set(NDI_DIR "/Library/NDI SDK for Apple") set(NDI_DIR "/Library/NDI SDK for Apple")
set(NDI_INCLUDE_DIR "${NDI_DIR}/include") set(NDI_INCLUDE_DIR "${NDI_DIR}/include")
set(NDI_LIBRARY_DIR "${NDI_DIR}/lib/macOS") set(NDI_LIBRARY_DIR "${NDI_DIR}/lib/macOS")
set(NDI_LICENSE_DIR "${NDI_DIR}/licenses")
file(GLOB NDI_LIBS "${NDI_LIBRARY_DIR}/*.dylib") file(GLOB NDI_LIBS "${NDI_LIBRARY_DIR}/*.dylib")
else() else()
set(NDI_FOUND FALSE) set(NDI_FOUND FALSE)
@@ -25,12 +27,14 @@ elseif(UNIX)
set(NDI_DIR ${NDI_SDK_DIR}) set(NDI_DIR ${NDI_SDK_DIR})
set(NDI_INCLUDE_DIR "${NDI_DIR}/include") set(NDI_INCLUDE_DIR "${NDI_DIR}/include")
set(NDI_LIBRARY_DIR "${NDI_DIR}/lib/x86_64-linux-gnu") set(NDI_LIBRARY_DIR "${NDI_DIR}/lib/x86_64-linux-gnu")
set(NDI_LICENSE_DIR "${NDI_DIR}/licenses")
set(NDI_LIBS "ndi") set(NDI_LIBS "ndi")
elseif(EXISTS "/usr/include/Processing.NDI.Lib.h") elseif(EXISTS "/usr/include/Processing.NDI.Lib.h")
set(NDI_FOUND TRUE) set(NDI_FOUND TRUE)
set(NDI_DIR "/usr") set(NDI_DIR "/usr")
set(NDI_INCLUDE_DIR "${NDI_DIR}/include") set(NDI_INCLUDE_DIR "${NDI_DIR}/include")
set(NDI_LIBRARY_DIR "${NDI_DIR}/lib") set(NDI_LIBRARY_DIR "${NDI_DIR}/lib")
set(NDI_LICENSE_DIR "${NDI_DIR}/share/licenses/ndi-sdk")
set(NDI_LIBS "ndi") set(NDI_LIBS "ndi")
else() else()
set(NDI_FOUND FALSE) set(NDI_FOUND FALSE)

View File

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