-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
80 lines (63 loc) · 2.5 KB
/
Copy pathsetup.py
File metadata and controls
80 lines (63 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Copyright (c) <2024>, <Tobias Karusseit>
This file is part of the PySplineNetLib project, which is licensed under the
Mozilla Public License, Version 2.0 (MPL-2.0).
SPDX-License-Identifier: MPL-2.0
This file also includes contributions from the pybind11 library, which is licensed
under the MIT License.
SPDX-License-Identifier: MIT
For the full text of the licenses, see:
- Mozilla Public License 2.0: https://opensource.org/licenses/MPL-2.0
- MIT License: https://opensource.org/licenses/MIT
"""
from setuptools import setup, Extension
import os
import subprocess
import pybind11
import sys
def build_cpp_library():
#make sure cmake is installed
try:
subprocess.check_call(['cmake', '--version'])
except FileNotFoundError:
print("CMake not found, installing...")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'cmake'])
# Run CMake to build the C++ library
if not os.path.exists('build'):
os.makedirs('build')
# Call cmake to configure the project
subprocess.check_call(['cmake', '..'], cwd='build')
# Build the C++ library
subprocess.check_call(['cmake', '--build', '.'], cwd='build')
def get_library_path():
# Returns the path to the compiled library
return os.path.join(os.path.abspath('build'))
def get_include_path():
# Returns the path to the include directory (if needed)
return os.path.abspath('include')
def build_python_extension():
# Build the Python extension using setuptools
setup(
name="PySplineNetLib", # Name of the generated Python extension module
version="0.2",
ext_modules=[
Extension(
"PySplineNetLib", # Name of the generated Python extension module
["src/SplineNetLib_py.cpp"], # Path to your pybind C++ file
include_dirs=[pybind11.get_include(), get_include_path()], # Path to pybind11 and your library's headers
libraries=["SplineNetLib"], # Link with your precompiled library
library_dirs=[get_library_path()], # Directory containing the precompiled library
language="c++", # Ensure it's compiled as C++
extra_compile_args=["-std=c++20"],
)
],
install_requires=[
"pybind11>=2.6.0", # Ensure pybind11 is installed
],
)
def main():
# Build the C++ library and then the Python bindings
build_cpp_library()
build_python_extension()
if __name__ == "__main__":
main()