JDevlieghere created this revision. JDevlieghere added reviewers: sgraenitz, labath, xiaobai, amccarth, stella.stamenova, compnerd. JDevlieghere added a project: LLDB. Herald added subscribers: abidh, mgorny.
CMake has a much improved way to find the Python interpreter and libraries which guarantees that the interpreter and libraries are the same. However, this functionality is only available in CMake 3.12 and later. This patch changes the CMake logic to use that without bumping the minimum CMake version. Question for people familiar with CMake on Windows: do you think that FindPython could replace the current logic in find_python_libs_windows? So we could do something like: if(NOT CMAKE_VERSION VERSION_LESS "3.12") # Use FindPython else() if (Windows) # use find_python_libs_windows else() # use PythonInterp / PythonLibs endif() endif() Repository: rLLDB LLDB https://reviews.llvm.org/D64881 Files: lldb/cmake/modules/LLDBConfig.cmake Index: lldb/cmake/modules/LLDBConfig.cmake =================================================================== --- lldb/cmake/modules/LLDBConfig.cmake +++ lldb/cmake/modules/LLDBConfig.cmake @@ -185,6 +185,28 @@ message(STATUS "LLDB Found PythonIncludeDirs: ${PYTHON_INCLUDE_DIR}") endfunction(find_python_libs_windows) +function(find_python_libs) + if(NOT CMAKE_VERSION VERSION_LESS "3.12") + find_package(Python COMPONENTS Interpreter Development) + if(Python_FOUND) + set(PYTHON_EXECUTABLE ${Python_EXECUTABLE}) + set(PYTHON_LIBRARY ${Python_LIBRARIES}) + set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS}) + set(PYTHON_VERSION_STRING ${Python_VERSION}) + set(PYTHONLIBS_VERSION_STRING ${Python_VERSION}) + + set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} PARENT_SCOPE) + set(PYTHON_LIBRARY ${PYTHON_LIBRARY} PARENT_SCOPE) + set(PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIR} PARENT_SCOPE) + set(PYTHON_VERSION_STRING ${PYTHON_VERSION_STRING} PARENT_SCOPE) + set(PYTHONLIBS_VERSION_STRING ${PYTHONLIBS_VERSION_STRING} PARENT_SCOPE) + endif() + else() + find_package(PythonInterp REQUIRED) + find_package(PythonLibs REQUIRED) + endif() +endfunction(find_python_libs) + if (NOT LLDB_DISABLE_PYTHON) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") find_python_libs_windows() @@ -194,8 +216,7 @@ add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" ) endif() else() - find_package(PythonInterp REQUIRED) - find_package(PythonLibs REQUIRED) + find_python_libs() endif() if (NOT PYTHON_VERSION_STRING VERSION_EQUAL PYTHONLIBS_VERSION_STRING AND
Index: lldb/cmake/modules/LLDBConfig.cmake =================================================================== --- lldb/cmake/modules/LLDBConfig.cmake +++ lldb/cmake/modules/LLDBConfig.cmake @@ -185,6 +185,28 @@ message(STATUS "LLDB Found PythonIncludeDirs: ${PYTHON_INCLUDE_DIR}") endfunction(find_python_libs_windows) +function(find_python_libs) + if(NOT CMAKE_VERSION VERSION_LESS "3.12") + find_package(Python COMPONENTS Interpreter Development) + if(Python_FOUND) + set(PYTHON_EXECUTABLE ${Python_EXECUTABLE}) + set(PYTHON_LIBRARY ${Python_LIBRARIES}) + set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIRS}) + set(PYTHON_VERSION_STRING ${Python_VERSION}) + set(PYTHONLIBS_VERSION_STRING ${Python_VERSION}) + + set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} PARENT_SCOPE) + set(PYTHON_LIBRARY ${PYTHON_LIBRARY} PARENT_SCOPE) + set(PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIR} PARENT_SCOPE) + set(PYTHON_VERSION_STRING ${PYTHON_VERSION_STRING} PARENT_SCOPE) + set(PYTHONLIBS_VERSION_STRING ${PYTHONLIBS_VERSION_STRING} PARENT_SCOPE) + endif() + else() + find_package(PythonInterp REQUIRED) + find_package(PythonLibs REQUIRED) + endif() +endfunction(find_python_libs) + if (NOT LLDB_DISABLE_PYTHON) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") find_python_libs_windows() @@ -194,8 +216,7 @@ add_definitions( -DLLDB_PYTHON_HOME="${LLDB_PYTHON_HOME}" ) endif() else() - find_package(PythonInterp REQUIRED) - find_package(PythonLibs REQUIRED) + find_python_libs() endif() if (NOT PYTHON_VERSION_STRING VERSION_EQUAL PYTHONLIBS_VERSION_STRING AND
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits