Use netgen-occt to build netgen

This commit is contained in:
Matthias Hochsteger 2024-06-14 10:50:42 +02:00
parent f9d7d3a4fd
commit e7e945a84c
11 changed files with 114 additions and 35 deletions

View File

@ -32,13 +32,23 @@ push_github:
- "echo off"
- call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64"
- set CI_DIR=C:\ci\%CI_PIPELINE_ID%
- set CLCACHE_BASEDIR=C:\ci\%CI_PIPELINE_ID%
- set CCACHE_BASEDIR=C:\ci\%CI_PIPELINE_ID%
- set NETGEN_BUILD_DIR=%CI_DIR%\build
- set INSTALL_DIR=%CI_DIR%\install
- set SRC_DIR=%CI_DIR%\src
- set NETGENDIR=%INSTALL_DIR%\bin
- set PYTHONPATH=%INSTALL_DIR%\lib\site-packages
- set PATH=%NETGENDIR%;%PATH%
- echo %PATH%
- set PATH=%INSTALL_DIR%\bin;C:\python312;C:\python312\bin;C:\python312\Scripts;C:\tools\;%PATH%
- echo %PATH%
- set CCACHE_HARDLINK=1
- set CCACHE_NOHASHDIR=1
- C:\tools\ccache -s
- C:\tools\ccache -M 20G
- dir C:\python312
- python.exe --version
- python.exe -m pip install -U netgen-occt netgen-occt-devel
- cmake --version
build_win:
<<: *win
@ -54,12 +64,14 @@ build_win:
- >-
cmake %SRC_DIR%
-G Ninja
-DCMAKE_PREFIX=C:/python312
-DPython3_ROOT_DIR=C:/python312
-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%
-DCHECK_RANGE=ON
-DUSE_CGNS=ON
-DUSE_OCC=ON
-DUSE_CCACHE=ON
-DENABLE_UNIT_TESTS=ON
-DENABLE_UNIT_TESTS=OFF
-DCMAKE_BUILD_TYPE=Release
- cmake --build . --target install --config Release
@ -69,7 +81,7 @@ test_win:
script:
- pip install pytest-check
- cd tests\pytest
- python test_tutorials.py new_results.json
- REM python test_tutorials.py new_results.json
- cd %NETGEN_BUILD_DIR%\netgen
- ctest -C Release -V --output-on-failure
- cd ..

View File

@ -164,6 +164,7 @@ if(USE_CCACHE)
find_program(CCACHE_FOUND NAMES ccache ccache.bat)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND})
message(STATUS "Using ccache ${CCACHE_FOUND}")
endif(CCACHE_FOUND)
endif(USE_CCACHE)
@ -398,7 +399,12 @@ if (USE_OCC)
endif()
target_link_libraries(occ_libs INTERFACE ${OCC_LIBRARIES})
include_directories(${OpenCASCADE_INCLUDE_DIR})
get_target_property(occ_include_dir TKernel INTERFACE_INCLUDE_DIRECTORIES)
if(NOT occ_include_dir)
set(occ_include_dir ${OpenCASCADE_INCLUDE_DIR})
endif()
target_include_directories(occ_libs INTERFACE ${occ_include_dir})
message(STATUS "OpenCasCade include dirs: ${occ_include_dir}")
if(NOT OpenCASCADE_BUILD_SHARED_LIBS)
if(OpenCASCADE_WITH_FREETYPE)
find_library( FREETYPE NAMES freetype HINTS ${OpenCASCADE_LIBRARY_DIR})
@ -413,10 +419,12 @@ if (USE_OCC)
find_package(Threads REQUIRED)
target_link_libraries(occ_libs INTERFACE Threads::Threads)
endif()
message(STATUS "OCC DIRS ${OpenCASCADE_INCLUDE_DIR}")
if(WIN32 AND USE_GUI)
target_link_libraries(nggui PRIVATE occ_libs Ws2_32.lib)
target_link_libraries(nggui PRIVATE Ws2_32.lib)
endif(WIN32 AND USE_GUI)
if(USE_GUI)
target_link_libraries(nggui PRIVATE occ_libs)
endif(USE_GUI)
endif (USE_OCC)
#######################################################################

View File

@ -120,27 +120,14 @@ if(BUILD_OCC)
list(APPEND NETGEN_DEPENDENCIES project_occ)
set(OpenCascade_ROOT ${OCC_DIR})
else(BUILD_OCC)
if(WIN32 AND NOT OCC_INCLUDE_DIR AND NOT OpenCASCADE_DIR)
# we can download prebuilt occ binaries for windows
ExternalProject_Add(win_download_occ
${SUBPROJECT_ARGS}
URL ${OCC_DOWNLOAD_URL_WIN}
UPDATE_COMMAND "" # Disable update
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}
)
list(APPEND NETGEN_DEPENDENCIES win_download_occ)
else()
find_package(OpenCascade NAMES OpenCasCade OpenCASCADE opencascade)
if(NOT OpenCascade_FOUND)
message(FATAL_ERROR "Opencascade not found, either\n\
- set OpenCascade_DIR to a directory containting opencascadeConfig.cmake\n\
- build OpenCascade automatically by passing -DBUILD_OCC=ON\n\
- disable OpenCascade by passing -DUSE_OCC=OFF\n\
")
endif()
find_package(OpenCascade NAMES OpenCasCade OpenCASCADE opencascade)
if(NOT OpenCascade_FOUND)
message(FATAL_ERROR "Opencascade not found, either\n\
- install pip packages netgen-occt-devel netgen-occ\n\
- set OpenCascade_DIR to a directory containting opencascadeConfig.cmake\n\
- build OpenCascade automatically by passing -DBUILD_OCC=ON\n\
- disable OpenCascade by passing -DUSE_OCC=OFF\n\
")
endif()
endif(BUILD_OCC)
endif(USE_OCC)

View File

@ -1,10 +1,65 @@
import os
import sys
from pathlib import Path
from . import config
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH_BIN))
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH))
def load_occ_libs():
try:
try:
import importlib.metadata as metadata
except ImportError:
import importlib_metadata as metadata
import ctypes
metadata.metadata('netgen-occt')
lib_names = [
"TKOffset",
"TKFillet",
"TKDEIGES",
"TKBool",
"TKDESTEP",
"TKXSBase",
"TKDESTL",
"TKXCAF",
"TKVCAF",
"TKCAF",
"TKBO",
"TKPrim",
"TKLCAF",
"TKCDF",
"TKV3d",
"TKHLR",
"TKMesh",
"TKService",
"TKShHealing",
"TKTopAlgo",
"TKGeomAlgo",
"TKBRep",
"TKGeomBase",
"TKG3d",
"TKG2d",
"TKMath",
"TKDE",
"TKernel",
]
lib_names.reverse()
lib_paths = {}
for f in metadata.files('netgen-occt'):
if f.match('*libTK*') or f.match("*.dll"):
p = f.locate()
name = p.name.split('.')[0].lower().replace("lib","")
lib_paths[name] = str(p)
for lib_name in lib_names:
p = lib_paths[lib_name.lower()]
ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL)
except metadata.PackageNotFoundError:
pass
load_occ_libs()
__diagnostics_template = """
Netgen diagnostics:
sys.platform: {sys.platform}

View File

@ -8,6 +8,9 @@ if(EMSCRIPTEN)
set(rules_command ${CMAKE_BINARY_DIR}/makerls)
else(EMSCRIPTEN)
add_executable(makerls rules/makerlsfile.cpp)
if(USE_CCACHE)
set_target_properties(makerls PROPERTIES RULE_LAUNCH_COMPILE "")
endif(USE_CCACHE)
set(rules_command makerls)
endif()

View File

@ -4,15 +4,21 @@ import os
import sys
import pathlib
import sysconfig
import importlib.metadata
from skbuild import setup
import skbuild.cmaker
from subprocess import check_output
setup_requires = ['pybind11-stubgen==2.5']
setup_requires = ['pybind11-stubgen>=2.5', 'netgen-occt-devel']
pyprefix = pathlib.Path(sys.prefix).as_posix()
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()
def install_filter(cmake_manifest):
print(cmake_manifest)
return cmake_manifest
@ -36,7 +42,7 @@ if len(version)>2:
if len(version)>1:
version = '.post'.join(version)
if not 'NG_NO_DEV_PIP_VERSION' in os.environ:
version += '.dev'
version += '.dev0'
else:
version = version[0]
@ -47,6 +53,7 @@ arch = None
cmake_args = [
f'-DNETGEN_VERSION_GIT={git_version}',
f'-DNETGEN_VERSION_PYTHON={version}',
f'-DOpenCascade_DIR={find_occt_dir()}',
]
if 'NETGEN_ARCH' in os.environ and os.environ['NETGEN_ARCH'] == 'avx2':
@ -132,7 +139,7 @@ cmake_args += [
'-DUSE_GUI=ON',
'-DUSE_NATIVE_ARCH=OFF',
'-DBUILD_ZLIB=ON',
'-DBUILD_OCC=ON',
'-DBUILD_OCC=OFF',
'-DUSE_OCC=ON',
'-DBUILD_FOR_CONDA=ON',
f'-DNETGEN_PYTHON_PACKAGE_NAME={name}',
@ -149,6 +156,7 @@ setup(
license="LGPL2.1",
packages=packages,
#package_dir={'netgen': 'python'},
install_requires=[f"netgen-occt=={importlib.metadata.version('netgen-occt-devel')}"],
tests_require=['pytest'],
#include_package_data=True,
cmake_process_manifest_hook=install_filter,

View File

@ -11,5 +11,6 @@ $env:NETGEN_ARCH = 'avx2'
$pydir=$args[0]
& $pydir\python.exe --version
& $pydir\python.exe -m pip install scikit-build wheel numpy twine pybind11-stubgen
& $pydir\python.exe -m pip install --upgrade netgen-occt==7.8.1 netgen-occt-devel==7.8.1
& $pydir\python setup.py bdist_wheel -G"Visual Studio 16 2019"
& $pydir\python -m twine upload dist\*.whl

View File

@ -23,13 +23,15 @@ for pyversion in 312 311 310 39 38
do
export PYDIR="/opt/python/cp${pyversion}-cp${pyversion}/bin"
echo $PYDIR
$PYDIR/pip install -U pytest-check numpy wheel scikit-build pybind11-stubgen
$PYDIR/pip install -U pytest-check numpy wheel scikit-build pybind11-stubgen netgen-occt==7.8.1 netgen-occt-devel==7.8.1
$PYDIR/pip install -i https://pypi.anaconda.org/mpi4py/simple/ --pre mpi4py
rm -rf _skbuild
NETGEN_ARCH=avx2 $PYDIR/pip wheel .
auditwheel repair netgen_mesher*-cp${pyversion}-*.whl
rm netgen_mesher-*.whl
mkdir -p wheelhouse
#auditwheel repair netgen_mesher*-cp${pyversion}-*.whl
rename linux_x86_64 manylinux_2_17_x86_64.manylinux2014_x86_64 netgen_mesher*-cp${pyversion}-*.whl
mv netgen_mesher*-cp${pyversion}-*.whl wheelhouse/
$PYDIR/pip install wheelhouse/netgen_mesher*-cp${pyversion}-*.whl
$PYDIR/python3 -c 'import netgen'

View File

@ -7,7 +7,8 @@ export PATH=$PYDIR:/Applications/CMake.app/Contents/bin:$PATH
export NETGEN_CCACHE=1
$PYDIR/python3 --version
$PYDIR/pip3 install --user numpy twine scikit-build wheel pybind11-stubgen
$PYDIR/python3 -m pip install --user numpy twine scikit-build wheel pybind11-stubgen
$PYDIR/python3 -m pip install --user -U netgen-occt==7.8.1 netgen-occt-devel==7.8.1
export CMAKE_OSX_ARCHITECTURES='arm64;x86_64'
export NETGEN_ARCH='avx2'

View File

@ -1,3 +1,4 @@
import netgen
from pyngcore import *
from numpy import sort, array

View File

@ -1,3 +1,4 @@
import netgen
from pyngcore import BitArray
def test_bitarray():