2021-10-27 19:50:07 +05:00
|
|
|
import glob
|
2023-10-03 16:05:22 +05:00
|
|
|
import os.path
|
2024-06-16 02:41:11 +05:00
|
|
|
import os
|
2021-10-27 19:50:07 +05:00
|
|
|
import sys
|
2023-05-12 14:26:38 +05:00
|
|
|
import pathlib
|
2023-10-03 16:05:22 +05:00
|
|
|
import sysconfig
|
2024-06-14 13:50:42 +05:00
|
|
|
import importlib.metadata
|
2021-10-27 19:50:07 +05:00
|
|
|
|
|
|
|
from skbuild import setup
|
|
|
|
import skbuild.cmaker
|
|
|
|
from subprocess import check_output
|
|
|
|
|
2024-06-14 13:50:42 +05:00
|
|
|
setup_requires = ['pybind11-stubgen>=2.5', 'netgen-occt-devel']
|
2021-10-27 19:50:07 +05:00
|
|
|
|
2024-05-13 16:43:53 +05:00
|
|
|
pyprefix = pathlib.Path(sys.prefix).as_posix()
|
|
|
|
|
2024-06-14 13:50:42 +05:00
|
|
|
def find_occt_dir():
|
|
|
|
for f in importlib.metadata.files("netgen-occt-devel"):
|
|
|
|
if f.match("OpenCASCADEConfig.cmake"):
|
|
|
|
return f.locate().parent.resolve().absolute().as_posix()
|
|
|
|
|
2021-10-27 19:50:07 +05:00
|
|
|
def install_filter(cmake_manifest):
|
|
|
|
print(cmake_manifest)
|
|
|
|
return cmake_manifest
|
|
|
|
|
|
|
|
def _patched_parse_manifests(self):
|
|
|
|
paths = \
|
|
|
|
glob.glob(os.path.join(skbuild.cmaker.CMAKE_BUILD_DIR(), "netgen", "install_manifest*.txt"))
|
|
|
|
try:
|
|
|
|
return [self._parse_manifest(path) for path in paths][0]
|
|
|
|
except IndexError:
|
|
|
|
return []
|
|
|
|
|
|
|
|
# we are using the netgen superbuild (to download and build some dependencies)
|
|
|
|
# patch the parse_manifests function to point to the actual netgen cmake project within the superbuild
|
|
|
|
skbuild.cmaker.CMaker._parse_manifests = _patched_parse_manifests
|
|
|
|
|
2024-07-02 15:53:03 +05:00
|
|
|
def is_dev_build():
|
|
|
|
if 'NG_NO_DEV_PIP_VERSION' in os.environ:
|
|
|
|
return False
|
|
|
|
if 'CI_COMMIT_REF_NAME' in os.environ and os.environ['CI_COMMIT_REF_NAME'] == 'release':
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2024-08-28 21:04:16 +05:00
|
|
|
git_version = check_output([sys.executable, os.path.join('tests', 'utils.py'), '--get-git-version']).decode('utf-8').strip()
|
|
|
|
version = check_output([sys.executable, os.path.join('tests', 'utils.py'), '--get-version']).decode('utf-8').strip()
|
2021-10-27 19:50:07 +05:00
|
|
|
|
2023-10-03 16:05:22 +05:00
|
|
|
py_install_dir = os.path.relpath(sysconfig.get_path('platlib'), sysconfig.get_path('data')).replace('\\','/')
|
2021-10-27 19:50:07 +05:00
|
|
|
|
|
|
|
name = "netgen-mesher"
|
|
|
|
arch = None
|
|
|
|
cmake_args = [
|
2021-10-28 16:57:24 +05:00
|
|
|
f'-DNETGEN_VERSION_GIT={git_version}',
|
|
|
|
f'-DNETGEN_VERSION_PYTHON={version}',
|
2024-06-14 13:50:42 +05:00
|
|
|
f'-DOpenCascade_DIR={find_occt_dir()}',
|
2021-10-27 19:50:07 +05:00
|
|
|
]
|
|
|
|
|
2022-09-16 18:47:14 +05:00
|
|
|
if 'NETGEN_ARCH' in os.environ and os.environ['NETGEN_ARCH'] == 'avx2':
|
|
|
|
# build for avx2 architecture
|
|
|
|
if 'darwin' in sys.platform:
|
|
|
|
flag = "'-Xarch_x86_64;-march=core-avx2'"
|
|
|
|
elif 'win' in sys.platform:
|
2024-03-20 00:07:06 +05:00
|
|
|
flag = '/arch:AVX2'
|
2022-09-16 18:47:14 +05:00
|
|
|
else:
|
|
|
|
flag = '-march=core-avx2'
|
|
|
|
cmake_args += [f'-DNG_COMPILE_FLAGS={flag}']
|
2021-10-27 19:50:07 +05:00
|
|
|
|
|
|
|
if 'NETGEN_CCACHE' in os.environ:
|
|
|
|
cmake_args += [f'-DUSE_CCACHE=ON']
|
|
|
|
|
2022-02-16 14:03:42 +05:00
|
|
|
packages = ['netgen', 'pyngcore']
|
|
|
|
|
2024-05-13 16:43:53 +05:00
|
|
|
have_mpi = False
|
2021-10-27 19:50:07 +05:00
|
|
|
if 'darwin' in sys.platform:
|
|
|
|
cmake_args += [
|
2022-02-23 14:49:27 +05:00
|
|
|
'-DNG_INSTALL_DIR_LIB=netgen',
|
|
|
|
'-DNG_INSTALL_DIR_PYTHON=.',
|
|
|
|
'-DNG_INSTALL_DIR_BIN=bin',
|
|
|
|
'-DNG_INSTALL_DIR_CMAKE=netgen/cmake',
|
|
|
|
'-DNG_INSTALL_DIR_INCLUDE=netgen/include',
|
2022-03-11 16:48:52 +05:00
|
|
|
'-DNG_INSTALL_DIR_RES=share',
|
2021-10-27 19:50:07 +05:00
|
|
|
]
|
2024-05-13 16:43:53 +05:00
|
|
|
if os.path.exists('/usr/local/include/mpi.h'):
|
|
|
|
have_mpi = True
|
|
|
|
cmake_args += [
|
|
|
|
'-DOPENMPI_INCLUDE_DIR=/usr/local/include',
|
|
|
|
]
|
2021-10-27 19:50:07 +05:00
|
|
|
elif 'win' in sys.platform:
|
|
|
|
cmake_args += [
|
|
|
|
'-A Win64',
|
2022-02-23 14:49:27 +05:00
|
|
|
'-DNG_INSTALL_DIR_BIN=netgen',
|
|
|
|
'-DNG_INSTALL_DIR_PYTHON=.',
|
|
|
|
'-DNG_INSTALL_DIR_LIB=netgen/lib',
|
|
|
|
'-DNG_INSTALL_DIR_CMAKE=netgen/cmake',
|
|
|
|
'-DNG_INSTALL_DIR_INCLUDE=netgen/include',
|
2021-10-27 19:50:07 +05:00
|
|
|
]
|
2024-05-13 16:43:53 +05:00
|
|
|
py_libdir = pathlib.Path(sys.prefix) / 'Library'
|
|
|
|
lib_file = py_libdir / 'lib' / 'impi.lib'
|
|
|
|
include_dir = py_libdir / 'include'
|
|
|
|
if lib_file.exists():
|
|
|
|
have_mpi = True
|
|
|
|
cmake_args += [
|
|
|
|
f'-DINTEL_MPI_INCLUDE_DIR={include_dir.as_posix()}',
|
|
|
|
f'-DINTEL_MPI_LIBRARY={lib_file.as_posix()}',
|
|
|
|
]
|
2021-10-27 19:50:07 +05:00
|
|
|
elif 'linux' in sys.platform:
|
|
|
|
name_dir = name.replace('-','_')
|
|
|
|
cmake_args += [
|
|
|
|
f'-DNG_INSTALL_DIR_LIB={py_install_dir}/{name_dir}.libs',
|
2022-02-23 14:49:27 +05:00
|
|
|
'-DNG_INSTALL_DIR_BIN=bin',
|
|
|
|
'-DNG_INSTALL_DIR_INCLUDE=include/netgen',
|
2022-09-15 13:46:19 +05:00
|
|
|
'-DTCL_INCLUDE_PATH=/usr/include',
|
|
|
|
'-DTK_INCLUDE_PATH=/usr/include',
|
2021-10-27 19:50:07 +05:00
|
|
|
]
|
2024-05-13 16:43:53 +05:00
|
|
|
mpich_include = '/opt/mpich/include'
|
|
|
|
openmpi_include = '/opt/openmpi/include'
|
|
|
|
if os.path.exists(mpich_include+'/mpi.h'):
|
|
|
|
have_mpi = True
|
|
|
|
cmake_args += [
|
|
|
|
f'-DMPICH_INCLUDE_DIR={mpich_include}',
|
|
|
|
]
|
|
|
|
if os.path.exists(openmpi_include+'/mpi.h'):
|
|
|
|
have_mpi = True
|
|
|
|
cmake_args += [
|
|
|
|
f'-DOPENMPI_INCLUDE_DIR={openmpi_include}',
|
|
|
|
]
|
2022-02-05 02:06:19 +05:00
|
|
|
packages = []
|
2021-10-27 19:50:07 +05:00
|
|
|
|
2024-05-13 16:43:53 +05:00
|
|
|
if have_mpi:
|
|
|
|
cmake_args += [
|
|
|
|
'-DUSE_MPI=ON',
|
2024-05-29 13:51:45 +05:00
|
|
|
'-DUSE_MPI_WRAPPER=ON',
|
2024-05-13 16:43:53 +05:00
|
|
|
]
|
|
|
|
|
2021-10-27 19:50:07 +05:00
|
|
|
cmake_args += [
|
|
|
|
'-DUSE_SUPERBUILD:BOOL=ON',
|
|
|
|
'-DUSE_CCACHE:BOOL=ON',
|
|
|
|
'-DUSE_GUI=ON',
|
|
|
|
'-DUSE_NATIVE_ARCH=OFF',
|
|
|
|
'-DBUILD_ZLIB=ON',
|
2024-06-14 13:50:42 +05:00
|
|
|
'-DBUILD_OCC=OFF',
|
2021-10-27 19:50:07 +05:00
|
|
|
'-DUSE_OCC=ON',
|
|
|
|
'-DBUILD_FOR_CONDA=ON',
|
2021-10-28 16:59:38 +05:00
|
|
|
f'-DNETGEN_PYTHON_PACKAGE_NAME={name}',
|
2024-03-26 23:22:16 +05:00
|
|
|
'-DBUILD_STUB_FILES=ON',
|
2021-10-27 19:50:07 +05:00
|
|
|
]
|
|
|
|
|
2023-08-30 19:04:22 +05:00
|
|
|
cmake_args += [f'-DCMAKE_PREFIX_PATH={pyprefix}', f'-DPython3_ROOT_DIR={pyprefix}']
|
2021-10-27 19:50:07 +05:00
|
|
|
|
|
|
|
setup(
|
|
|
|
name=name,
|
|
|
|
version=version,
|
|
|
|
description="Netgen",
|
|
|
|
author='The Netgen team',
|
|
|
|
license="LGPL2.1",
|
2022-02-05 02:06:19 +05:00
|
|
|
packages=packages,
|
2022-02-04 19:05:19 +05:00
|
|
|
#package_dir={'netgen': 'python'},
|
2024-06-14 13:50:42 +05:00
|
|
|
install_requires=[f"netgen-occt=={importlib.metadata.version('netgen-occt-devel')}"],
|
2021-10-27 19:50:07 +05:00
|
|
|
tests_require=['pytest'],
|
2022-02-04 20:44:22 +05:00
|
|
|
#include_package_data=True,
|
2021-10-27 19:50:07 +05:00
|
|
|
cmake_process_manifest_hook=install_filter,
|
|
|
|
cmake_args = cmake_args,
|
|
|
|
setup_requires=setup_requires,
|
|
|
|
entry_points={
|
|
|
|
'console_scripts': [
|
|
|
|
'netgen = netgen.__main__:main',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
)
|