version handling, generate python configuration file

This commit is contained in:
mhochsteger@cerbsim.com 2021-10-28 13:57:24 +02:00
parent f0e7f843c3
commit 1cf9e3ff02
6 changed files with 80 additions and 25 deletions

View File

@ -480,9 +480,6 @@ add_subdirectory(tutorials)
add_subdirectory(py_tutorials)
add_subdirectory(doc)
add_subdirectory(nglib)
if (USE_PYTHON)
add_subdirectory(python)
endif (USE_PYTHON)
add_subdirectory(tests)
#######################################################################
@ -540,6 +537,9 @@ if(USE_NATIVE_ARCH)
endif(APPLE)
endif(USE_NATIVE_ARCH)
if (USE_PYTHON)
add_subdirectory(python)
endif (USE_PYTHON)
#######################################################################
# Debian packager

View File

@ -2,12 +2,17 @@ if(NOT BDIR)
set(BDIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(SKBUILD)
set(git_version_string ${GIT_NETGEN_VERSION})
else(SKBUILD)
if(NETGEN_VERSION_GIT)
set(git_version_string ${NETGEN_VERSION_GIT})
else()
find_package(Git REQUIRED)
execute_process(COMMAND git describe --tags --match "v[0-9]*" --long --dirty WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE git_version_string RESULT_VARIABLE status ERROR_QUIET)
endif(SKBUILD)
execute_process(COMMAND git describe --tags --match "v[0-9]*" --long --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE git_version_string
RESULT_VARIABLE status
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(status AND NOT status EQUAL 0)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../version.txt)
@ -65,15 +70,6 @@ else()
file(WRITE ${BDIR}/netgen_version.hpp ${new_version_file_string})
endif()
set(py_version "${NETGEN_VERSION_MAJOR}.${NETGEN_VERSION_MINOR}.${NETGEN_VERSION_PATCH}")
if(${NETGEN_VERSION_TWEAK} GREATER 0)
set(py_version "${py_version}.dev${NETGEN_VERSION_TWEAK}")
endif()
if(NOT SKBUILD)
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/python/version.py "__version__ = \"${py_version}\"\n")
endif()
file(GENERATE OUTPUT netgen_config.hpp CONTENT
"\
#ifndef NETGEN_CONFIG_HPP_INCLUDED___

View File

@ -1,10 +1,15 @@
configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY)
get_target_property(ngcore_compile_definitions ngcore INTERFACE_COMPILE_DEFINITIONS)
get_property(have_options TARGET ngcore PROPERTY INTERFACE_COMPILE_OPTIONS SET)
if(have_options)
get_target_property(ngcore_compile_options ngcore INTERFACE_COMPILE_OPTIONS)
endif(have_options)
configure_file(config.py ${CMAKE_CURRENT_BINARY_DIR}/config.py @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/__init__.py __main__.py
${CMAKE_CURRENT_BINARY_DIR}/config.py __main__.py __init__.py
meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py occ.py read_gmsh.py
webgui.py
version.py # generated by either cmake or setup.py
DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX}
COMPONENT netgen
)

View File

@ -1,8 +1,9 @@
import os
import sys
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..','@NETGEN_PYTHON_RPATH_BIN@'))
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..','@NETGEN_PYTHON_RPATH@'))
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))
if sys.platform.startswith('win'):
if sys.version >= '3.8':
@ -13,8 +14,6 @@ if sys.platform.startswith('win'):
del sys
del os
from .version import __version__
from . import libngpy
def Redraw(*args, **kwargs):

54
python/config.py Normal file
View File

@ -0,0 +1,54 @@
def _cmake_to_bool(s):
return s.upper() not in ['', '0','FALSE','OFF','N','NO','IGNORE','NOTFOUND']
is_python_package = _cmake_to_bool("@SKBUILD@")
BUILD_FOR_CONDA = _cmake_to_bool("@BUILD_FOR_CONDA@")
BUILD_STUB_FILES = _cmake_to_bool("@BUILD_STUB_FILES@")
CHECK_RANGE = _cmake_to_bool("@CHECK_RANGE@")
DEBUG_LOG = _cmake_to_bool("@DEBUG_LOG@")
ENABLE_CPP_CORE_GUIDELINES_CHECK = _cmake_to_bool("@ENABLE_CPP_CORE_GUIDELINES_CHECK@")
ENABLE_UNIT_TESTS = _cmake_to_bool("@ENABLE_UNIT_TESTS@")
INSTALL_PROFILES = _cmake_to_bool("@INSTALL_PROFILES@")
INTEL_MIC = _cmake_to_bool("@INTEL_MIC@")
TRACE_MEMORY = _cmake_to_bool("@TRACE_MEMORY@")
USE_CCACHE = _cmake_to_bool("@USE_CCACHE@")
USE_CGNS = _cmake_to_bool("@USE_CGNS@")
USE_GUI = _cmake_to_bool("@USE_GUI@")
USE_INTERNAL_TCL = _cmake_to_bool("@USE_INTERNAL_TCL@")
USE_JPEG = _cmake_to_bool("@USE_JPEG@")
USE_MPEG = _cmake_to_bool("@USE_MPEG@")
USE_MPI = _cmake_to_bool("@USE_MPI@")
USE_MPI4PY = _cmake_to_bool("@USE_MPI4PY@")
USE_NATIVE_ARCH = _cmake_to_bool("@USE_NATIVE_ARCH@")
USE_NUMA = _cmake_to_bool("@USE_NUMA@")
USE_OCC = _cmake_to_bool("@USE_OCC@")
USE_PYTHON = _cmake_to_bool("@USE_PYTHON@")
USE_SPDLOG = _cmake_to_bool("@USE_SPDLOG@")
CMAKE_INSTALL_PREFIX = "@CMAKE_INSTALL_PREFIX@"
NG_INSTALL_DIR_PYTHON = "@NG_INSTALL_DIR_PYTHON_DEFAULT@"
NG_INSTALL_DIR_BIN = "@NG_INSTALL_DIR_BIN_DEFAULT@"
NG_INSTALL_DIR_LIB = "@NG_INSTALL_DIR_LIB_DEFAULT@"
NG_INSTALL_DIR_INCLUDE = "@NG_INSTALL_DIR_INCLUDE_DEFAULT@"
NG_INSTALL_DIR_CMAKE = "@NG_INSTALL_DIR_CMAKE_DEFAULT@"
NG_INSTALL_DIR_RES = "@NG_INSTALL_DIR_RES_DEFAULT@"
NETGEN_PYTHON_RPATH_BIN = "@NETGEN_PYTHON_RPATH_BIN@"
NETGEN_PYTHON_RPATH = "@NETGEN_PYTHON_RPATH@"
NG_COMPILE_FLAGS = "@NG_COMPILE_FLAGS@"
ngcore_compile_options = "@ngcore_compile_options@"
ngcore_compile_definitions = "@ngcore_compile_definitions@"
NETGEN_VERSION = "@NETGEN_VERSION@"
NETGEN_VERSION_GIT = "@git_version_string@"
NETGEN_VERSION_PYTHON = "@NETGEN_VERSION_PYTHON@"
NETGEN_VERSION_MAJOR = "@NETGEN_VERSION_MAJOR@"
NETGEN_VERSION_MINOR = "@NETGEN_VERSION_MINOR@"
NETGEN_VERSION_TWEAK = "@NETGEN_VERSION_TWEAK@"
NETGEN_VERSION_PATCH = "@NETGEN_VERSION_PATCH@"
NETGEN_VERSION_HASH = "@NETGEN_VERSION_HASH@"
version = NETGEN_VERSION_GIT

View File

@ -38,7 +38,8 @@ py_install_dir = get_python_lib(1,0,'').replace('\\','/')
name = "netgen-mesher"
arch = None
cmake_args = [
f'-DGIT_NETGEN_VERSION={git_version}',
f'-DNETGEN_VERSION_GIT={git_version}',
f'-DNETGEN_VERSION_PYTHON={version}',
]
if 'NETGEN_ARCH' in os.environ: