Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Compute Python library suffix in CMakeLists.txt
Browse files Browse the repository at this point in the history
Introduce LLDB_PY_LIB_SUFFIX and use it in various places in the
build.  This lets the x.py-based build work properly without having to
set LLVM_LIBDIR_SUFFIX.

See https://bugs.llvm.org/show_bug.cgi?id=18957 for some discussion.
  • Loading branch information
tromey committed Nov 27, 2018
1 parent a0fc10c commit 8e114ff
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ if(LLDB_BUILD_FRAMEWORK)
include(LLDBFramework)
endif()

if (NOT LLDB_DISABLE_PYTHON)
execute_process(
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/get_libdir_suffix.py
OUTPUT_VARIABLE LLDB_PY_LIB_SUFFIX)
endif ()

add_subdirectory(docs)
if (NOT LLDB_DISABLE_PYTHON)
if(LLDB_USE_SYSTEM_SIX)
Expand Down Expand Up @@ -181,7 +188,7 @@ if (NOT LLDB_DISABLE_PYTHON)
--cfgBldDir=${LLDB_PYTHON_TARGET_DIR}
--prefix=${CMAKE_BINARY_DIR}
--cmakeBuildConfiguration=${CMAKE_CFG_INTDIR}
--lldbLibDir=lib${LLVM_LIBDIR_SUFFIX}
--lldbLibDir=lib${LLDB_PY_LIB_SUFFIX}
${SIX_EXTRA_ARGS}
${FINISH_EXTRA_ARGS}
VERBATIM
Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(EPYDOC_EXECUTABLE)
--url "http://lldb.llvm.org"
${EPYDOC_OPTIONS}
DEPENDS swig_wrapper liblldb
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../../lib${LLVM_LIBDIR_SUFFIX}/python2.7/site-packages
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../../lib${LLDB_PY_LIB_SUFFIX}/python2.7/site-packages
COMMENT "Generating LLDB Python API reference with epydoc" VERBATIM
)
endif(EPYDOC_EXECUTABLE)
6 changes: 3 additions & 3 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ include(FindPythonInterp)

if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
set(SWIG_PYTHON_DIR
${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
${CMAKE_BINARY_DIR}/lib${LLDB_PY_LIB_SUFFIX}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
else()
set(SWIG_PYTHON_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/site-packages)
set(SWIG_PYTHON_DIR ${CMAKE_BINARY_DIR}/lib${LLDB_PY_LIB_SUFFIX}/site-packages)
endif()

set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
set(SWIG_INSTALL_DIR lib${LLDB_PY_LIB_SUFFIX})

# Generating the LLDB framework correctly is a bit complicated because the
# framework depends on the swig output.
Expand Down
2 changes: 1 addition & 1 deletion scripts/Python/modules/readline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ set_target_properties(readline PROPERTIES
LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/${PYTHON_DIRECTORY})

# Install the readline module.
install(TARGETS readline LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}/${PYTHON_DIRECTORY})
install(TARGETS readline LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LLDB_PY_LIB_SUFFIX}/${PYTHON_DIRECTORY})
33 changes: 33 additions & 0 deletions scripts/get_libdir_suffix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import distutils.sysconfig
import os
import platform
import re
import sys


def get_python_libdir_suffix():
"""Returns the appropropriate python libdir suffix.
@return the python libdir suffix, normally either "" or "64".
"""
if platform.system() != 'Linux':
return ""

# We currently have a bug in lldb -P that does not account for
# architecture variants in python paths for
# architecture-specific modules. Handle the lookup here.
# When that bug is fixed, we should just ask lldb for the
# right answer always.
arch_specific_libdir = distutils.sysconfig.get_python_lib(True, False)
split_libdir = arch_specific_libdir.split(os.sep)
lib_re = re.compile(r"^lib.+$")

for i in range(len(split_libdir)):
match = lib_re.match(split_libdir[i])
if match is not None:
return split_libdir[i][3:]
return ""

if __name__ == '__main__':
sys.stdout.write(get_python_libdir_suffix())
sys.exit(0)

0 comments on commit 8e114ff

Please sign in to comment.