Index: cmake/modules/LLDBConfig.cmake =================================================================== --- cmake/modules/LLDBConfig.cmake +++ cmake/modules/LLDBConfig.cmake @@ -37,6 +37,87 @@ add_definitions( -DLLDB_DISABLE_CURSES ) endif() +# On Windows, we can't use the normal FindPythonLibs module that comes with CMake, +# for a number of reasons. +# 1) Prior to MSVC 2015, it is only possible to embed Python if python itself was +# compiled with an identical version (and build configuration) of MSVC as LLDB. +# The standard algorithm does not take into account the differences between +# a binary release distribution of python and a custom built distribution. +# 2) From MSVC 2015 and onwards, it is only possible to use Python 3.5 or later. +# 3) FindPythonLibs queries the registry to locate Python, and when looking for a +# 64-bit version of Python, since cmake.exe is a 32-bit executable, it will see +# a 32-bit view of the registry. As such, it is impossible for FindPythonLibs to +# locate 64-bit Python libraries. +# This function is designed to address those limitations. Currently it only partially +# addresses them, but it can be improved and extended on an as-needed basis. +function(find_python_libs_windows) + if ("${PYTHON_HOME}" STREQUAL "") + message("LLDB embedded Python on Windows requires specifying a value for PYTHON_HOME. Python support disabled.") + set(LLDB_DISABLE_PYTHON 1) + return() + endif() + + file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIR) + + if(EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h") + file(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" python_version_str + REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"") + string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1" + PYTHONLIBS_VERSION_STRING "${python_version_str}") + message("-- Found Python version ${PYTHONLIBS_VERSION_STRING}") + string(REGEX REPLACE "([0-9]+)[.]([0-9]+)[.][0-9]+" "python\\1\\2" PYTHONLIBS_BASE_NAME "${PYTHONLIBS_VERSION_STRING}") + unset(python_version_str) + else() + message("Unable to find ${PYTHON_INCLUDE_DIR}/patchlevel.h, Python installation is corrupt.") + message("Python support will be disabled for this build.") + set(LLDB_DISABLE_PYTHON 1) + return() + endif() + + file(TO_CMAKE_PATH "${PYTHON_HOME}" PYTHON_HOME) + file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_DEBUG_EXE) + file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}_d.lib" PYTHON_DEBUG_LIB) + file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}_d.dll" PYTHON_DEBUG_DLL) + + file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_RELEASE_EXE) + file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}.lib" PYTHON_RELEASE_LIB) + file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}.dll" PYTHON_RELEASE_DLL) + + # Generator expressions are evaluated in the context of each build configuration generated + # by CMake. Here we use the $:VALUE logical generator expression to ensure + # that the debug Python library, DLL, and executable are used in the Debug build configuration. + # + # Generator expressions can be difficult to grok at first so here's a breakdown of the one + # used for PYTHON_LIBRARY: + # + # 1. $ evaluates to 1 when the Debug configuration is being generated, + # or 0 in all other cases. + # 2. $<$:${PYTHON_DEBUG_LIB}> expands to ${PYTHON_DEBUG_LIB} when the Debug + # configuration is being generated, or nothing (literally) in all other cases. + # 3. $<$>:${PYTHON_RELEASE_LIB}> expands to ${PYTHON_RELEASE_LIB} when + # any configuration other than Debug is being generated, or nothing in all other cases. + # 4. The conditionals in 2 & 3 are mutually exclusive. + # 5. A logical expression with a conditional that evaluates to 0 yields no value at all. + # + # Due to 4 & 5 it's possible to concatenate 2 & 3 to obtain a single value specific to each + # build configuration. In this example the value will be ${PYTHON_DEBUG_LIB} when generating the + # Debug configuration, or ${PYTHON_RELEASE_LIB} when generating any other configuration. + # Note that it's imperative that there is no whitespace between the two expressions, otherwise + # CMake will insert a semicolon between the two. + + set (PYTHON_EXECUTABLE $<$:${PYTHON_DEBUG_EXE}>$<$>:${PYTHON_RELEASE_EXE}> PARENT_SCOPE) + set (PYTHON_LIBRARY $<$:${PYTHON_DEBUG_LIB}>$<$>:${PYTHON_RELEASE_LIB}> PARENT_SCOPE) + set (PYTHON_DLL $<$:${PYTHON_DEBUG_DLL}>$<$>:${PYTHON_RELEASE_DLL}> PARENT_SCOPE) + + if (NOT LLDB_RELOCATABLE_PYTHON) + add_definitions( -DLLDB_PYTHON_HOME="${PYTHON_HOME}" ) + endif() + + if (PYTHON_LIBRARY) + include_directories(${PYTHON_INCLUDE_DIR}) + endif() +endfunction(find_python_libs_windows) + if (NOT LLDB_DISABLE_PYTHON) if(UNIX) # This is necessary for crosscompile on Ubuntu 14.04 64bit. Need a proper fix. @@ -46,61 +127,10 @@ endif() if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") - if (NOT "${PYTHON_HOME}" STREQUAL "") - file(TO_CMAKE_PATH "${PYTHON_HOME}" PYTHON_HOME) - file(TO_CMAKE_PATH "${PYTHON_HOME}/python_d.exe" PYTHON_DEBUG_EXE) - file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/python27_d.lib" PYTHON_DEBUG_LIB) - file(TO_CMAKE_PATH "${PYTHON_HOME}/python27_d.dll" PYTHON_DEBUG_DLL) - - file(TO_CMAKE_PATH "${PYTHON_HOME}/python.exe" PYTHON_RELEASE_EXE) - file(TO_CMAKE_PATH "${PYTHON_HOME}/libs/python27.lib" PYTHON_RELEASE_LIB) - file(TO_CMAKE_PATH "${PYTHON_HOME}/python27.dll" PYTHON_RELEASE_DLL) - - # Generator expressions are evaluated in the context of each build configuration generated - # by CMake. Here we use the $:VALUE logical generator expression to ensure - # that the debug Python library, DLL, and executable are used in the Debug build configuration. - # - # Generator expressions can be difficult to grok at first so here's a breakdown of the one - # used for PYTHON_LIBRARY: - # - # 1. $ evaluates to 1 when the Debug configuration is being generated, - # or 0 in all other cases. - # 2. $<$:${PYTHON_DEBUG_LIB}> expands to ${PYTHON_DEBUG_LIB} when the Debug - # configuration is being generated, or nothing (literally) in all other cases. - # 3. $<$>:${PYTHON_RELEASE_LIB}> expands to ${PYTHON_RELEASE_LIB} when - # any configuration other than Debug is being generated, or nothing in all other cases. - # 4. The conditionals in 2 & 3 are mutually exclusive. - # 5. A logical expression with a conditional that evaluates to 0 yields no value at all. - # - # Due to 4 & 5 it's possible to concatenate 2 & 3 to obtain a single value specific to each - # build configuration. In this example the value will be ${PYTHON_DEBUG_LIB} when generating the - # Debug configuration, or ${PYTHON_RELEASE_LIB} when generating any other configuration. - # Note that it's imperative that there is no whitespace between the two expressions, otherwise - # CMake will insert a semicolon between the two. - - set (PYTHON_EXECUTABLE $<$:${PYTHON_DEBUG_EXE}>$<$>:${PYTHON_RELEASE_EXE}>) - set (PYTHON_LIBRARY $<$:${PYTHON_DEBUG_LIB}>$<$>:${PYTHON_RELEASE_LIB}>) - set (PYTHON_DLL $<$:${PYTHON_DEBUG_DLL}>$<$>:${PYTHON_RELEASE_DLL}>) - - file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIR) - if (NOT LLDB_RELOCATABLE_PYTHON) - add_definitions( -DLLDB_PYTHON_HOME="${PYTHON_HOME}" ) - endif() - else() - message("Embedding Python on Windows without specifying a value for PYTHON_HOME is deprecated. Support for this will be dropped soon.") - - if ("${PYTHON_INCLUDE_DIR}" STREQUAL "" OR "${PYTHON_LIBRARY}" STREQUAL "") - message("-- LLDB Embedded python disabled. Embedding python on Windows requires " - "manually specifying PYTHON_INCLUDE_DIR *and* PYTHON_LIBRARY") - set(LLDB_DISABLE_PYTHON 1) - endif() - endif() - - if (PYTHON_LIBRARY) - message("-- Found PythonLibs: ${PYTHON_LIBRARY}") - include_directories(${PYTHON_INCLUDE_DIR}) - endif() - + find_python_libs_windows() + message("-- Found PythonExecutable: ${PYTHON_EXECUTABLE}") + message("-- Found PythonLibs: ${PYTHON_LIBRARY}") + message("-- Found PythonDLL: ${PYTHON_DLL}") else() find_package(PythonLibs REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) Index: cmake/modules/LLDBStandalone.cmake =================================================================== --- cmake/modules/LLDBStandalone.cmake +++ cmake/modules/LLDBStandalone.cmake @@ -50,7 +50,7 @@ # Verify that we can find a Python 2 interpreter. Python 3 is unsupported. if (PYTHON_EXECUTABLE STREQUAL "") - set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5) + set(Python_ADDITIONAL_VERSIONS 3.5 3.4 3.3 3.2 3.1 3.0 2.7 2.6 2.5) include(FindPythonInterp) if( NOT PYTHONINTERP_FOUND ) message(FATAL_ERROR