IfcWrap CMake - migrate to FindPython

Previously it was giving deprecation warnings:

CMake Warning (dev) at /IfcOpenShell/src/ifcwrap/CMakeLists.txt:38 (FIND_PACKAGE):
  Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

  CMake Warning (dev) at /IfcOpenShell/src/ifcwrap/CMakeLists.txt:73 (FIND_PACKAGE):
  Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
  are removed.  Run "cmake --help-policy CMP0148" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.
This commit is contained in:
Andrej730
2024-07-03 17:09:03 +05:00
parent 33785620d5
commit 4211e7a936
+17 -13
View File
@@ -33,23 +33,27 @@ IF(NOT "$ENV{PYTHON_LIBRARY}" STREQUAL "")
MESSAGE(STATUS "Looking for Python library file in: ${PYTHON_LIBRARY}") MESSAGE(STATUS "Looking for Python library file in: ${PYTHON_LIBRARY}")
ENDIF() ENDIF()
# NOTE PYTHONLIBS_FOUND and PYTHONINTERP_FOUND cannot seem to be trusted so # TODO: Is still a problem after we moved to FIND_PACKAGE(Python)?
# NOTE Python_Development_FOUND and Python_Interpreter_FOUND cannot seem to be trusted so
# we need further checks to see whether the packages were actually found or not. # we need further checks to see whether the packages were actually found or not.
FIND_PACKAGE(PythonLibs) FIND_PACKAGE(Python COMPONENTS Development)
IF(NOT PYTHONLIBS_FOUND OR "$PYTHON_INCLUDE_DIRS}" STREQUAL "") IF(NOT Python_Development_FOUND OR "${Python_INCLUDE_DIRS}" STREQUAL "")
MESSAGE(FATAL_ERROR "BUILD_IFCPYTHON enabled, but unable to find Python lib or header. Disable BUILD_IFCPYTHON or fix Python paths to proceed.") MESSAGE(FATAL_ERROR "BUILD_IFCPYTHON enabled, but unable to find Python lib or header. Disable BUILD_IFCPYTHON or fix Python paths to proceed.")
ENDIF() ENDIF()
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${Python_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SWIG_FLAGS ${SWIG_DEFINES}) SET(CMAKE_SWIG_FLAGS ${SWIG_DEFINES})
# NOTE Workaround for most likely missing debug Python libraries on Windows (requires Python built from the source). # NOTE Workaround for most likely missing debug Python libraries on Windows (requires Python built from the source).
# Python 3.5 intaller and onwards will have an option to install the debug libraries too. # Python 3.5 intaller and onwards will have an option to install the debug libraries too.
# NOTE PYTHON_DEBUG_LIBRARIES appears to be a deprecated variable IF(WIN32)
IF (WIN32 AND NOT PYTHON_DEBUG_LIBRARIES) STRING(REPLACE ";" ";" Python_LIBRARIES_LIST "${Python_LIBRARIES}")
MESSAGE(STATUS "PYTHON_DEBUG_LIBRARIES not found, defining SWIG_PYTHON_INTERPRETER_NO_DEBUG workaround for IfcWrap.") LIST(FIND Python_LIBRARIES_LIST "debug" debug_index)
ADD_DEFINITIONS(-DSWIG_PYTHON_INTERPRETER_NO_DEBUG) IF(debug_index EQUAL -1)
MESSAGE(STATUS "Python debug libraries are not found, defining SWIG_PYTHON_INTERPRETER_NO_DEBUG workaround for IfcWrap.")
ADD_DEFINITIONS(-DSWIG_PYTHON_INTERPRETER_NO_DEBUG)
ENDIF()
ENDIF() ENDIF()
if (WITH_CGAL) if (WITH_CGAL)
@@ -59,10 +63,10 @@ endif()
SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON) SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON)
swig_add_library(ifcopenshell_wrapper LANGUAGE python SOURCES IfcPython.i) swig_add_library(ifcopenshell_wrapper LANGUAGE python SOURCES IfcPython.i)
if("$ENV{LDFLAGS}" MATCHES ".undefined.suppress") if("$ENV{LDFLAGS}" MATCHES ".undefined.suppress")
# On osx there is some state in the python dylib. With `-Wl,undefined,suppress` we can ignore the missing symbols at compile time. # On osx there is some state in the python dylib. With `-Wl,undefined,suppress` we can ignore the missing symbols at compile time.
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${LIBSVGFILL}) SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${LIBSVGFILL})
else() else()
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${PYTHON_LIBRARIES} ${LIBSVGFILL}) SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${IFCOPENSHELL_LIBRARIES} ${Python_LIBRARIES} ${LIBSVGFILL})
endif() endif()
if ((NOT WIN32) AND BUILD_SHARED_LIBS) if ((NOT WIN32) AND BUILD_SHARED_LIBS)
SET_INSTALL_RPATHS(${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} "${IFCDIRS};${OCC_LIBRARY_DIR}") SET_INSTALL_RPATHS(${SWIG_MODULE_ifcopenshell_wrapper_REAL_NAME} "${IFCDIRS};${OCC_LIBRARY_DIR}")
@@ -70,8 +74,8 @@ endif()
# Try to find the Python interpreter to get the site-packages # Try to find the Python interpreter to get the site-packages
# directory in which the wrapper can be installed. # directory in which the wrapper can be installed.
FIND_PACKAGE(PythonInterp) FIND_PACKAGE(Python COMPONENTS Interpreter)
IF((PYTHONINTERP_FOUND AND NOT "${PYTHON_EXECUTABLE}" STREQUAL "") OR PYTHON_MODULE_INSTALL_DIR) IF((Python_Interpreter_FOUND AND NOT "${PYTHON_EXECUTABLE}" STREQUAL "") OR PYTHON_MODULE_INSTALL_DIR)
if (PYTHON_MODULE_INSTALL_DIR) if (PYTHON_MODULE_INSTALL_DIR)
set(python_package_dir "${PYTHON_MODULE_INSTALL_DIR}") set(python_package_dir "${PYTHON_MODULE_INSTALL_DIR}")
else() else()