astitcher commented on a change in pull request #294: URL: https://github.com/apache/qpid-proton/pull/294#discussion_r573058292
########## File path: tools/cmake/Modules/FindPython.cmake ########## @@ -0,0 +1,49 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# This is a wrapper hack purely so that we can use FindPython +# with cmake 2.8.12 and its supplied older modules + +# FindPython was added in CMake 3.12, but there it always returned +# newest Python on the entire PATH. We want to use the first one. +if (CMAKE_VERSION VERSION_LESS "3.15.0") + find_package (PythonInterp REQUIRED) + # forward compatibility with FindPython + set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") + set(Python_LIBRARIES "${PYTHON_LIBRARIES}") + set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}") + set(Python_VERSION_STRING "${PYTHON_VERSION_STRING}") + # for completeness, these are not actually used now + set(Python_VERSION_MAJOR "${PYTHON_VERSION_MAJOR}") + set(Python_VERSION_MINOR "${PYTHON_VERSION_MINOR}") + set(Python_VERSION_PATCH "${PYTHON_VERSION_PATCH}") + + find_package (PythonLibs ${PYTHON_VERSION_STRING} EXACT) + set(Python_Development_FOUND "${PYTHONLIBS_FOUND}") +else () + if (POLICY CMP0094) # https://cmake.org/cmake/help/latest/policy/CMP0094.html + cmake_policy(SET CMP0094 NEW) # FindPython should return the first matching Python on PATH + endif () + + if (DEFINED PYTHON_EXECUTABLE) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif () Review comment: What if both PYTHON_EXECUTABLE and Python_EXECUTABLE are set? I know it seems unlikely, but if it happens I think what this does might be surprising - I'd expect Python_EXECUTABLE not to be overridden. ########## File path: tools/cmake/Modules/FindPython.cmake ########## @@ -0,0 +1,49 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# This is a wrapper hack purely so that we can use FindPython +# with cmake 2.8.12 and its supplied older modules + +# FindPython was added in CMake 3.12, but there it always returned +# newest Python on the entire PATH. We want to use the first one. +if (CMAKE_VERSION VERSION_LESS "3.15.0") + find_package (PythonInterp REQUIRED) + # forward compatibility with FindPython + set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") + set(Python_LIBRARIES "${PYTHON_LIBRARIES}") + set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}") + set(Python_VERSION_STRING "${PYTHON_VERSION_STRING}") + # for completeness, these are not actually used now + set(Python_VERSION_MAJOR "${PYTHON_VERSION_MAJOR}") + set(Python_VERSION_MINOR "${PYTHON_VERSION_MINOR}") + set(Python_VERSION_PATCH "${PYTHON_VERSION_PATCH}") + + find_package (PythonLibs ${PYTHON_VERSION_STRING} EXACT) + set(Python_Development_FOUND "${PYTHONLIBS_FOUND}") +else () + if (POLICY CMP0094) # https://cmake.org/cmake/help/latest/policy/CMP0094.html + cmake_policy(SET CMP0094 NEW) # FindPython should return the first matching Python on PATH + endif () Review comment: Given this checks if the policy exists I think you could hoist this out of the if block checking the cmake version - I think this would be a little tidier. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
