Merge branch 'find_python' into 'master'

find_package(PythonInterp... deprecated, change to python with comp

See merge request ngsolve/netgen!595
This commit is contained in:
Hochsteger, Matthias 2023-08-30 21:57:52 +02:00
commit 0043eee0e0
11 changed files with 40 additions and 36 deletions

View File

@ -241,6 +241,7 @@ build_mac:
-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
-DUSE_CGNS=ON
-DUSE_OCC=ON
-DPython3_ROOT_DIR=/Library/Frameworks/Python.framework/Versions/3.8/
- make -j5 install
test_mac:

View File

@ -2,8 +2,8 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING INTERNAL)
endif(NOT CMAKE_BUILD_TYPE)
cmake_minimum_required(VERSION 3.13)
cmake_policy(VERSION 3.13)
cmake_minimum_required(VERSION 3.16)
cmake_policy(VERSION 3.16)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
@ -85,12 +85,14 @@ endif()
set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)")
if(USE_PYTHON)
find_package(PythonInterp 3 REQUIRED)
if(NOT BUILD_FOR_CONDA)
find_package(PythonLibs 3 REQUIRED)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
find_package(Python3 COMPONENTS Interpreter Development.Embed)
else()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
endif()
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
file(TO_CMAKE_PATH ${PYTHON_PACKAGES_INSTALL_DIR} PYTHON_PACKAGES_INSTALL_DIR)
endif(USE_PYTHON)
@ -315,11 +317,10 @@ if (USE_PYTHON)
add_subdirectory(external_dependencies/pybind11)
endif()
target_include_directories(netgen_python INTERFACE ${pybind11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
target_include_directories(nglib PRIVATE ${pybind11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
if(NOT ${BUILD_FOR_CONDA} OR WIN32)
# Don't link python libraries in conda environments
target_link_libraries(netgen_python INTERFACE ${PYTHON_LIBRARIES})
target_include_directories(netgen_python INTERFACE ${pybind11_INCLUDE_DIR} ${Python3_INCLUDE_DIRS})
target_include_directories(nglib PRIVATE ${pybind11_INCLUDE_DIR} ${Python3_INCLUDE_DIRS})
if(Python3_LIBRARIES)
target_link_libraries(netgen_python INTERFACE ${Python3_LIBRARIES})
endif()
if(NG_INSTALL_PYBIND)
@ -343,7 +344,7 @@ if (USE_MPI)
target_compile_definitions(netgen_metis INTERFACE METIS )
if(USE_MPI4PY AND USE_PYTHON)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import mpi4py;print(mpi4py.get_include())" OUTPUT_VARIABLE mpi4py_path OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import mpi4py;print(mpi4py.get_include())" OUTPUT_VARIABLE mpi4py_path OUTPUT_STRIP_TRAILING_WHITESPACE)
find_path(MPI4PY_INCLUDE_DIR mpi4py.h HINTS ${mpi4py_path}/mpi4py NO_DEFAULT_PATH REQUIRED)
target_include_directories(netgen_metis INTERFACE ${MPI4PY_INCLUDE_DIR})
target_compile_definitions(netgen_metis INTERFACE NG_MPI4PY )

View File

@ -38,9 +38,9 @@ set(NETGEN_OCC_LIBRARIES_BIN "@OpenCASCADE_BINARY_DIR@")
set(NETGEN_OCC_LIBRARIES "@OCC_LIBRARIES@")
set(NETGEN_OCC_LIBRARY_DIR "@OpenCASCADE_LIBRARY_DIR@")
set(NETGEN_OPENGL_LIBRARIES "@OPENGL_LIBRARIES@")
set(NETGEN_PYTHON_EXECUTABLE "@PYTHON_EXECUTABLE@")
set(NETGEN_PYTHON_INCLUDE_DIRS "@PYTHON_INCLUDE_DIRS@")
set(NETGEN_PYTHON_LIBRARIES "@PYTHON_LIBRARIES@")
set(NETGEN_PYTHON_EXECUTABLE "@Python3_EXECUTABLE@")
set(NETGEN_PYTHON_INCLUDE_DIRS "@Python3_INCLUDE_DIRS@")
set(NETGEN_PYTHON_LIBRARIES "@Python3_LIBRARIES@")
set(NETGEN_TCL_INCLUDE_PATH "@TCL_INCLUDE_PATH@")
set(NETGEN_TCL_LIBRARY "@TCL_STUB_LIBRARY@")
set(NETGEN_TK_DND_LIBRARY "@TK_DND_LIBRARY@")

View File

@ -181,16 +181,18 @@ if (USE_PYTHON)
else( PYBIND_INCLUDE_DIR )
message(FATAL_ERROR "Could NOT find pybind11!")
endif( PYBIND_INCLUDE_DIR )
find_package(PythonInterp 3 REQUIRED)
if(NOT BUILD_FOR_CONDA)
find_package(PythonLibs 3 REQUIRED)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
find_package(Python3 COMPONENTS Interpreter Development.Embed)
else()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
endif()
set_vars(NETGEN_CMAKE_ARGS
PYTHON_INCLUDE_DIRS
PYTHON_LIBRARIES
PYTHON_EXECUTABLE
PYTHON_VERSION
Python3_INCLUDE_DIRS
Python3_LIBRARIES
Python3_EXECUTABLE
Python3_VERSION
PYBIND_INCLUDE_DIR
NG_INSTALL_PYBIND
)

View File

@ -7,7 +7,7 @@ else(LINUX)
if(SKBUILD)
# we are building a pip package - download the tcl/tk sources matching the tkinter version (for private headers not shipped with python)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
execute_process(COMMAND ${Python3_EXECUTABLE} -c
"import tkinter;print(tkinter.Tcl().eval('info patchlevel').replace('.','-'))"
OUTPUT_VARIABLE PYTHON_TCL_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
@ -39,7 +39,7 @@ set(TK_INCLUDE_PATH ${TK_DIR}/generic)
list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk)
if(APPLE OR WIN32)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; print(sys.prefix)" OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import sys; print(sys.prefix)" OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
file(TO_CMAKE_PATH ${PYTHON_PREFIX} PYTHON_PREFIX)
set(tcl_find_args

View File

@ -78,7 +78,7 @@ endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)
add_dependencies(ngcore ng_generate_version_file)
if(USE_PYTHON)
pybind11_add_module(pyngcore SHARED python_ngcore_export.cpp)
pybind11_add_module(pyngcore MODULE python_ngcore_export.cpp)
target_link_libraries(pyngcore PUBLIC ngcore netgen_python)
set_target_properties(pyngcore PROPERTIES INSTALL_RPATH "${NG_RPATH_TOKEN}/../${NETGEN_PYTHON_RPATH}")
install(TARGETS pyngcore DESTINATION ${NG_INSTALL_DIR_PYTHON}/pyngcore COMPONENT netgen)

View File

@ -28,7 +28,7 @@ if(USE_GUI)
if(APPLE)
set_target_properties(netgen PROPERTIES OUTPUT_NAME netgen)
endif(APPLE)
target_link_libraries( netgen ${PYTHON_LIBRARIES} ${TCL_LIBRARY} ${TK_LIBRARY})
target_link_libraries( netgen ${Python3_LIBRARIES} ${TCL_LIBRARY} ${TK_LIBRARY})
endif(NOT BUILD_FOR_CONDA)
install(TARGETS nggui ${NG_INSTALL_DIR})

View File

@ -26,13 +26,13 @@ install(FILES
# build stub files for pybind11 packages
if(BUILD_STUB_FILES)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import pybind11_stubgen; print(pybind11_stubgen.__file__)" OUTPUT_VARIABLE stubgen_path RESULT_VARIABLE pybind11_stubgen)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import pybind11_stubgen; print(pybind11_stubgen.__file__)" OUTPUT_VARIABLE stubgen_path RESULT_VARIABLE pybind11_stubgen)
if(pybind11_stubgen AND NOT ${pybind11_stubgen} EQUAL 0)
message(WARNING "pybind11-stubgen not found, if you want to create stub files
for better autocompletion support install it with pip.")
else()
message("-- Found pybind11-stubgen: ${stubgen_path}")
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11_stubgen --no-setup-py --ignore-invalid=all netgen)")
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} -m pybind11_stubgen --no-setup-py --ignore-invalid=all netgen)")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../stubs/netgen-stubs/ DESTINATION ${NG_INSTALL_DIR_PYTHON}/netgen/ COMPONENT netgen)
endif()
endif(BUILD_STUB_FILES)

View File

@ -52,8 +52,8 @@ NETGEN_VERSION_TWEAK = "@NETGEN_VERSION_TWEAK@"
NETGEN_VERSION_PATCH = "@NETGEN_VERSION_PATCH@"
NETGEN_VERSION_HASH = "@NETGEN_VERSION_HASH@"
PYTHON_VERSION = "@PYTHON_VERSION@"
PYTHON_VERSION_MAJOR = "@PYTHON_VERSION_MAJOR@"
PYTHON_VERSION_MINOR = "@PYTHON_VERSION_MINOR@"
PYTHON_VERSION = "@Python3_VERSION@"
PYTHON_VERSION_MAJOR = "@Python3_VERSION_MAJOR@"
PYTHON_VERSION_MINOR = "@Python3_VERSION_MINOR@"
version = NETGEN_VERSION_GIT

View File

@ -102,7 +102,7 @@ cmake_args += [
]
pyprefix = pathlib.Path(sys.prefix).as_posix()
cmake_args += [f'-DCMAKE_PREFIX_PATH={pyprefix}']
cmake_args += [f'-DCMAKE_PREFIX_PATH={pyprefix}', f'-DPython3_ROOT_DIR={pyprefix}']
setup(
name=name,

View File

@ -1,8 +1,8 @@
if(USE_PYTHON)
add_test(NAME pytest COMMAND ${PYTHON_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(pytest ${PYTHON_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME pytest COMMAND ${Python3_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(pytest ${Python3_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_tests_properties ( pytest PROPERTIES TIMEOUT 1800 )
if(USE_MPI AND USE_MPI4PY)
add_test(NAME pytest-mpi COMMAND ${MPIEXEC_EXECUTABLE} --allow-run-as-root -np 4 ${PYTHON_EXECUTABLE} -m pytest --with-mpi test_mpi4py.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME pytest-mpi COMMAND ${MPIEXEC_EXECUTABLE} --allow-run-as-root -np 4 ${Python3_EXECUTABLE} -m pytest --with-mpi test_mpi4py.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif(USE_MPI AND USE_MPI4PY)
endif(USE_PYTHON)