From 7bbff520a047170bd9fadae0304ce3e8c07f984b Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Thu, 4 Mar 2021 14:44:44 -0600 Subject: [PATCH] Modify Python checks when cMake >= 3.12 --- cMake/FreeCAD_Helpers/SetupPython.cmake | 32 +++++++++++-------- .../SetupShibokenAndPyside.cmake | 2 +- src/Mod/Measure/App/CMakeLists.txt | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cMake/FreeCAD_Helpers/SetupPython.cmake b/cMake/FreeCAD_Helpers/SetupPython.cmake index fdf9952490..59882b1ef3 100644 --- a/cMake/FreeCAD_Helpers/SetupPython.cmake +++ b/cMake/FreeCAD_Helpers/SetupPython.cmake @@ -123,21 +123,27 @@ macro(SetupPython) else (NOT DEFINED PYTHON_VERSION_STRING) find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT) endif(NOT DEFINED PYTHON_VERSION_STRING) + if(NOT PYTHONLIBS_FOUND) + message(FATAL_ERROR "=================================\n" + "Python not found, install Python!\n" + "=================================\n") + endif() else() - find_package(Python3 COMPONENTS Interpreter Development) + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + + # For compatibility with old CMake scripts + set(PYTHON_LIBRARIES ${Python3_LIBRARIES}) + set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS}) + set(PYTHON_LIBRARY_DIRS ${Python3_LIBRARY_DIRS}) + set(PYTHON_VERSION_STRING ${Python3_VERSION}) + set(PYTHON_VERSION_MAJOR ${Python3_VERSION_MAJOR}) + set(PYTHON_VERSION_MINOR ${Python3_VERSION_MINOR}) + set(PYTHON_VERSION_PATCH ${Python3_VERSION_PATCH}) endif() - if(NOT PYTHONLIBS_FOUND) - message(FATAL_ERROR "=================================\n" - "Python not found, install Python!\n" - "=================================\n") - else(NOT PYTHONLIBS_FOUND) - # prevent python3 lower than 3.6 (not enough utf8<->unicode tools) - if(PYTHON_VERSION_MAJOR EQUAL 3) - if(PYTHON_VERSION_MINOR LESS 6) - message(FATAL_ERROR "To build FreeCAD you need at least Python 3.6\n") - endif(PYTHON_VERSION_MINOR LESS 6) - endif(PYTHON_VERSION_MAJOR EQUAL 3) - endif(NOT PYTHONLIBS_FOUND) + # prevent python3 lower than 3.6 + if (${PYTHON_VERSION_STRING} VERSION_LESS "3.6") + message(FATAL_ERROR "To build FreeCAD you need at least Python 3.6\n") + endif() endmacro(SetupPython) diff --git a/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake b/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake index 00890e14f7..2824af9c81 100644 --- a/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake +++ b/cMake/FreeCAD_Helpers/SetupShibokenAndPyside.cmake @@ -15,7 +15,7 @@ macro(SetupShibokenAndPyside) if (Shiboken2_FOUND) # Shiboken2 config file was found but it may use the wrong Python version # Try to get the matching config suffix and repeat finding the package - set(SHIBOKEN_PATTERN .cpython-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) + set(SHIBOKEN_PATTERN .cpython-${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) file(GLOB SHIBOKEN_CONFIG "${Shiboken2_DIR}/Shiboken2Config${SHIBOKEN_PATTERN}*.cmake") if (SHIBOKEN_CONFIG) diff --git a/src/Mod/Measure/App/CMakeLists.txt b/src/Mod/Measure/App/CMakeLists.txt index 43ba5f8fa3..1640f52682 100644 --- a/src/Mod/Measure/App/CMakeLists.txt +++ b/src/Mod/Measure/App/CMakeLists.txt @@ -12,7 +12,7 @@ include_directories( ${Boost_INCLUDE_DIRS} ${OCC_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} - ${PYTHON_INCLUDE_PATH} + ${Python3_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIR} ) link_directories(${OCC_LIBRARY_DIR})