[Lldb-commits] [lldb] c135744 - [lldb/CMake] Separate CMake code for Lua and Python (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 11 09:04:26 PDT 2020
Author: Jonas Devlieghere
Date: 2020-08-11T09:04:18-07:00
New Revision: c135744b1df394f51b6a08bc562f99a1236e772c
URL: https://github.com/llvm/llvm-project/commit/c135744b1df394f51b6a08bc562f99a1236e772c
DIFF: https://github.com/llvm/llvm-project/commit/c135744b1df394f51b6a08bc562f99a1236e772c.diff
LOG: [lldb/CMake] Separate CMake code for Lua and Python (NFC)
Separate the CMake logic for Lua and Python to clearly distinguish
between code specific to either scripting language and the code shared
by both.
What this patch does is:
- Move Python specific code into the bindings/python subdirectory.
- Move the Lua specific code into the bindings/lua subdirectory.
- Add the _python suffix to Python specific functions/targets.
- Fix a dependency issue that would check the binding instead of
whether the scripting language is enabled.
Note that this patch also changes where the bindings are generated,
which might affect downstream projects that check them in.
Differential revision: https://reviews.llvm.org/D85708
Added:
lldb/bindings/lua/CMakeLists.txt
lldb/bindings/lua/lua.swig
lldb/bindings/python/CMakeLists.txt
lldb/bindings/python/python.swig
Modified:
lldb/CMakeLists.txt
lldb/bindings/CMakeLists.txt
lldb/docs/CMakeLists.txt
lldb/source/API/CMakeLists.txt
Removed:
lldb/bindings/lua.swig
lldb/bindings/python.swig
################################################################################
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 8a0c4524182e..cd3d3c8d7e01 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -79,14 +79,14 @@ add_subdirectory(source)
add_subdirectory(tools)
add_subdirectory(docs)
-if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA)
+if (LLDB_ENABLE_PYTHON)
if(LLDB_BUILD_FRAMEWORK)
set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb")
else()
set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb")
endif()
- get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR)
- finish_swig("finish_swig" "${lldb_bindings_dir}" "${lldb_python_target_dir}")
+ get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR)
+ finish_swig_python("finish_swig_python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}")
endif()
option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS})
diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
index 3440f605bca5..9759b069fdc4 100644
--- a/lldb/bindings/CMakeLists.txt
+++ b/lldb/bindings/CMakeLists.txt
@@ -29,217 +29,12 @@ set(SWIG_COMMON_FLAGS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
${DARWIN_EXTRAS}
- -outdir ${CMAKE_CURRENT_BINARY_DIR}
)
if (LLDB_ENABLE_PYTHON)
- add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
- DEPENDS ${SWIG_SOURCES}
- DEPENDS ${SWIG_INTERFACES}
- DEPENDS ${SWIG_HEADERS}
- COMMAND ${SWIG_EXECUTABLE}
- ${SWIG_COMMON_FLAGS}
- -c++
- -shadow
- -python
- -threads
- -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
- ${LLDB_SOURCE_DIR}/bindings/python.swig
- VERBATIM
- COMMENT "Building LLDB Python wrapper")
-
- add_custom_target(swig_wrapper ALL DEPENDS
- ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
- )
+ add_subdirectory(python)
endif()
if (LLDB_ENABLE_LUA)
- add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
- DEPENDS ${SWIG_SOURCES}
- DEPENDS ${SWIG_INTERFACES}
- DEPENDS ${SWIG_HEADERS}
- COMMAND ${SWIG_EXECUTABLE}
- ${SWIG_COMMON_FLAGS}
- -lua
- -w503
- -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
- ${LLDB_SOURCE_DIR}/bindings/lua.swig
- VERBATIM
- COMMENT "Building LLDB Lua wrapper")
-
- add_custom_target(swig_wrapper_lua ALL DEPENDS
- ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
- )
+ add_subdirectory(lua)
endif()
-
-function(create_python_package swig_target working_dir pkg_dir)
- cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
- if(ARG_FILES)
- set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir})
- endif()
- if(NOT ARG_NOINIT)
- set(init_cmd COMMAND ${PYTHON_EXECUTABLE}
- "${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py"
- "${pkg_dir}" ${ARG_FILES})
- endif()
- add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
- COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir}
- ${copy_cmd}
- ${init_cmd}
- WORKING_DIRECTORY ${working_dir})
-endfunction()
-
-function(create_relative_symlink swig_target dest_file output_dir output_name)
- get_filename_component(dest_file ${dest_file} ABSOLUTE)
- get_filename_component(output_dir ${output_dir} ABSOLUTE)
- file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
- if(CMAKE_HOST_UNIX)
- set(LLVM_LINK_OR_COPY create_symlink)
- else()
- set(LLVM_LINK_OR_COPY copy)
- endif()
- add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
- COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
- WORKING_DIRECTORY ${output_dir})
-endfunction()
-
-function(finish_swig swig_target lldb_bindings_dir lldb_python_target_dir)
- # Add a Post-Build Event to copy over Python files and create the symlink to
- # liblldb.so for the Python API(hardlink on Windows).
- add_custom_target(${swig_target} ALL VERBATIM
- COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}
- DEPENDS ${lldb_bindings_dir}/lldb.py
- COMMENT "Python script sym-linking LLDB Python API")
-
- if(NOT LLDB_USE_SYSTEM_SIX)
- add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
- COMMAND ${CMAKE_COMMAND} -E copy
- "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py"
- "${lldb_python_target_dir}/../six.py")
- endif()
-
- add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
- COMMAND ${CMAKE_COMMAND} -E copy
- "${lldb_bindings_dir}/lldb.py"
- "${lldb_python_target_dir}/__init__.py")
-
- add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
- COMMAND ${CMAKE_COMMAND} -E copy
- "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py"
- "${lldb_python_target_dir}")
-
- # Distribute the examples as python packages.
- create_python_package(
- ${swig_target}
- ${lldb_python_target_dir}
- "formatters/cpp"
- FILES "${LLDB_SOURCE_DIR}/examples/synthetic/gnu_libstdcpp.py"
- "${LLDB_SOURCE_DIR}/examples/synthetic/libcxx.py")
-
- create_python_package(
- ${swig_target}
- ${lldb_python_target_dir}
- "formatters"
- FILES "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/cache.py"
- "${LLDB_SOURCE_DIR}/examples/summaries/synth.py"
- "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/metrics.py"
- "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/attrib_fromdict.py"
- "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/Logger.py")
-
- create_python_package(
- ${swig_target}
- ${lldb_python_target_dir}
- "utils"
- FILES "${LLDB_SOURCE_DIR}/examples/python/in_call_stack.py"
- "${LLDB_SOURCE_DIR}/examples/python/symbolication.py")
-
- if(APPLE)
- create_python_package(
- ${swig_target}
- ${lldb_python_target_dir} "macosx"
- FILES "${LLDB_SOURCE_DIR}/examples/python/crashlog.py"
- "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap.py")
-
- create_python_package(
- ${swig_target}
- ${lldb_python_target_dir} "macosx/heap"
- FILES "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp"
- "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile"
- NOINIT)
-
- create_python_package(
- ${swig_target}
- ${lldb_python_target_dir} "diagnose"
- FILES "${LLDB_SOURCE_DIR}/examples/python/diagnose_unwind.py"
- "${LLDB_SOURCE_DIR}/examples/python/diagnose_nsstring.py")
- endif()
-
- if(LLDB_BUILD_FRAMEWORK)
- set(LIBLLDB_SYMLINK_DEST "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB")
- else()
- set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
- endif()
- if(WIN32)
- if(CMAKE_BUILD_TYPE STREQUAL Debug)
- set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
- else()
- set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
- endif()
- else()
- set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
- endif()
- create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
- ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
-
- if(NOT LLDB_BUILD_FRAMEWORK)
- set(LLDB_ARGDUMPER_FILENAME "lldb-argdumper${CMAKE_EXECUTABLE_SUFFIX}")
- create_relative_symlink(${swig_target} "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}"
- ${lldb_python_target_dir} ${LLDB_ARGDUMPER_FILENAME})
- endif()
-
- add_dependencies(${swig_target} swig_wrapper liblldb lldb-argdumper)
- set_target_properties(${swig_target} swig_wrapper PROPERTIES FOLDER "lldb misc")
-
- # Ensure we do the python post-build step when building lldb.
- add_dependencies(lldb ${swig_target})
-
- # Install the LLDB python module
- if(LLDB_BUILD_FRAMEWORK)
- set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
- else()
- set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH})
- endif()
- if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
- string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
- string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
- endif()
- set(swig_scripts_target "${swig_target}_scripts")
- set(swig_scripts_install_target "${swig_target}_scripts_install")
- add_custom_target(${swig_scripts_target})
- add_dependencies(${swig_scripts_target} ${swig_target})
- install(DIRECTORY ${lldb_python_target_dir}/../
- DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
- COMPONENT ${swig_scripts_target})
- if (NOT LLVM_ENABLE_IDE)
- add_llvm_install_targets(${swig_scripts_install_target}
- COMPONENT ${swig_scripts_target}
- DEPENDS ${swig_scripts_target})
- endif()
-
- # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
- # lldb.exe or any other executables that were linked with liblldb.
- if (WIN32 AND NOT "${PYTHON_DLL}" STREQUAL "")
- # When using the Visual Studio CMake generator the lldb binaries end up in Release/bin, Debug/bin etc.
- file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin" LLDB_BIN_DIR)
- file(TO_NATIVE_PATH "${PYTHON_DLL}" PYTHON_DLL_NATIVE_PATH)
- add_custom_command(
- TARGET ${swig_target}
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM
- COMMENT "Copying Python DLL to LLDB binaries directory.")
- endif()
-endfunction()
diff --git a/lldb/bindings/lua/CMakeLists.txt b/lldb/bindings/lua/CMakeLists.txt
new file mode 100644
index 000000000000..84ff918d9376
--- /dev/null
+++ b/lldb/bindings/lua/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
+ DEPENDS ${SWIG_SOURCES}
+ DEPENDS ${SWIG_INTERFACES}
+ DEPENDS ${SWIG_HEADERS}
+ COMMAND ${SWIG_EXECUTABLE}
+ ${SWIG_COMMON_FLAGS}
+ -lua
+ -w503
+ -outdir ${CMAKE_CURRENT_BINARY_DIR}
+ -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/lua.swig
+ VERBATIM
+ COMMENT "Building LLDB Lua wrapper")
+
+add_custom_target(swig_wrapper_lua ALL DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp
+)
diff --git a/lldb/bindings/lua.swig b/lldb/bindings/lua/lua.swig
similarity index 100%
rename from lldb/bindings/lua.swig
rename to lldb/bindings/lua/lua.swig
diff --git a/lldb/bindings/python/CMakeLists.txt b/lldb/bindings/python/CMakeLists.txt
new file mode 100644
index 000000000000..b8ed1fa8dc8a
--- /dev/null
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -0,0 +1,190 @@
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
+ DEPENDS ${SWIG_SOURCES}
+ DEPENDS ${SWIG_INTERFACES}
+ DEPENDS ${SWIG_HEADERS}
+ COMMAND ${SWIG_EXECUTABLE}
+ ${SWIG_COMMON_FLAGS}
+ -c++
+ -shadow
+ -python
+ -threads
+ -outdir ${CMAKE_CURRENT_BINARY_DIR}
+ -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/python.swig
+ VERBATIM
+ COMMENT "Building LLDB Python wrapper")
+
+add_custom_target(swig_wrapper_python ALL DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
+)
+
+function(create_python_package swig_target working_dir pkg_dir)
+ cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
+ if(ARG_FILES)
+ set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir})
+ endif()
+ if(NOT ARG_NOINIT)
+ set(init_cmd COMMAND ${PYTHON_EXECUTABLE}
+ "${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py"
+ "${pkg_dir}" ${ARG_FILES})
+ endif()
+ add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir}
+ ${copy_cmd}
+ ${init_cmd}
+ WORKING_DIRECTORY ${working_dir})
+endfunction()
+
+function(create_relative_symlink swig_target dest_file output_dir output_name)
+ get_filename_component(dest_file ${dest_file} ABSOLUTE)
+ get_filename_component(output_dir ${output_dir} ABSOLUTE)
+ file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file})
+ if(CMAKE_HOST_UNIX)
+ set(LLVM_LINK_OR_COPY create_symlink)
+ else()
+ set(LLVM_LINK_OR_COPY copy)
+ endif()
+ add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name}
+ WORKING_DIRECTORY ${output_dir})
+endfunction()
+
+function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir)
+ # Add a Post-Build Event to copy over Python files and create the symlink to
+ # liblldb.so for the Python API(hardlink on Windows).
+ add_custom_target(${swig_target} ALL VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}
+ DEPENDS ${lldb_python_bindings_dir}/lldb.py
+ COMMENT "Python script sym-linking LLDB Python API")
+
+ if(NOT LLDB_USE_SYSTEM_SIX)
+ add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E copy
+ "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py"
+ "${lldb_python_target_dir}/../six.py")
+ endif()
+
+ add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E copy
+ "${lldb_python_bindings_dir}/lldb.py"
+ "${lldb_python_target_dir}/__init__.py")
+
+ add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E copy
+ "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py"
+ "${lldb_python_target_dir}")
+
+ # Distribute the examples as python packages.
+ create_python_package(
+ ${swig_target}
+ ${lldb_python_target_dir}
+ "formatters/cpp"
+ FILES "${LLDB_SOURCE_DIR}/examples/synthetic/gnu_libstdcpp.py"
+ "${LLDB_SOURCE_DIR}/examples/synthetic/libcxx.py")
+
+ create_python_package(
+ ${swig_target}
+ ${lldb_python_target_dir}
+ "formatters"
+ FILES "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/cache.py"
+ "${LLDB_SOURCE_DIR}/examples/summaries/synth.py"
+ "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/metrics.py"
+ "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/attrib_fromdict.py"
+ "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/Logger.py")
+
+ create_python_package(
+ ${swig_target}
+ ${lldb_python_target_dir}
+ "utils"
+ FILES "${LLDB_SOURCE_DIR}/examples/python/in_call_stack.py"
+ "${LLDB_SOURCE_DIR}/examples/python/symbolication.py")
+
+ if(APPLE)
+ create_python_package(
+ ${swig_target}
+ ${lldb_python_target_dir} "macosx"
+ FILES "${LLDB_SOURCE_DIR}/examples/python/crashlog.py"
+ "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap.py")
+
+ create_python_package(
+ ${swig_target}
+ ${lldb_python_target_dir} "macosx/heap"
+ FILES "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp"
+ "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile"
+ NOINIT)
+
+ create_python_package(
+ ${swig_target}
+ ${lldb_python_target_dir} "diagnose"
+ FILES "${LLDB_SOURCE_DIR}/examples/python/diagnose_unwind.py"
+ "${LLDB_SOURCE_DIR}/examples/python/diagnose_nsstring.py")
+ endif()
+
+ if(LLDB_BUILD_FRAMEWORK)
+ set(LIBLLDB_SYMLINK_DEST "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB")
+ else()
+ set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ endif()
+ if(WIN32)
+ if(CMAKE_BUILD_TYPE STREQUAL Debug)
+ set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd")
+ else()
+ set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd")
+ endif()
+ else()
+ set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so")
+ endif()
+ create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
+ ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
+
+ if(NOT LLDB_BUILD_FRAMEWORK)
+ set(LLDB_ARGDUMPER_FILENAME "lldb-argdumper${CMAKE_EXECUTABLE_SUFFIX}")
+ create_relative_symlink(${swig_target} "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}"
+ ${lldb_python_target_dir} ${LLDB_ARGDUMPER_FILENAME})
+ endif()
+
+ add_dependencies(${swig_target} swig_wrapper_python liblldb lldb-argdumper)
+ set_target_properties(${swig_target} swig_wrapper_python PROPERTIES FOLDER "lldb misc")
+
+ # Ensure we do the python post-build step when building lldb.
+ add_dependencies(lldb ${swig_target})
+
+ # Install the LLDB python module
+ if(LLDB_BUILD_FRAMEWORK)
+ set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
+ else()
+ set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH})
+ endif()
+ if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
+ string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
+ string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
+ endif()
+ set(swig_scripts_target "${swig_target}_scripts")
+ set(swig_scripts_install_target "${swig_target}_scripts_install")
+ add_custom_target(${swig_scripts_target})
+ add_dependencies(${swig_scripts_target} ${swig_target})
+ install(DIRECTORY ${lldb_python_target_dir}/../
+ DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
+ COMPONENT ${swig_scripts_target})
+ if (NOT LLVM_ENABLE_IDE)
+ add_llvm_install_targets(${swig_scripts_install_target}
+ COMPONENT ${swig_scripts_target}
+ DEPENDS ${swig_scripts_target})
+ endif()
+
+ # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
+ # lldb.exe or any other executables that were linked with liblldb.
+ if (WIN32 AND NOT "${PYTHON_DLL}" STREQUAL "")
+ # When using the Visual Studio CMake generator the lldb binaries end up in Release/bin, Debug/bin etc.
+ file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin" LLDB_BIN_DIR)
+ file(TO_NATIVE_PATH "${PYTHON_DLL}" PYTHON_DLL_NATIVE_PATH)
+ add_custom_command(
+ TARGET ${swig_target}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM
+ COMMENT "Copying Python DLL to LLDB binaries directory.")
+ endif()
+endfunction()
diff --git a/lldb/bindings/python.swig b/lldb/bindings/python/python.swig
similarity index 100%
rename from lldb/bindings/python.swig
rename to lldb/bindings/python/python.swig
diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index 8fa46860e5ce..b633a4abf054 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -30,11 +30,11 @@ if (LLDB_ENABLE_PYTHON)
# Because we don't build liblldb, epydoc will complain that the import of
# _lldb.so failed, but that doesn't prevent it from generating the docs.
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lldb)
- get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR)
+ get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR)
add_custom_target(lldb-python-doc-package
COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py"
COMMENT "Copying lldb.py to pretend package.")
- add_dependencies(lldb-python-doc-package swig_wrapper)
+ add_dependencies(lldb-python-doc-package swig_wrapper_python)
set(DOC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/doc")
file(MAKE_DIRECTORY "${DOC_DIR}")
@@ -49,7 +49,7 @@ if (LLDB_ENABLE_PYTHON)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating LLDB Python API reference with epydoc" VERBATIM
)
- add_dependencies(lldb-python-doc swig_wrapper lldb-python-doc-package)
+ add_dependencies(lldb-python-doc swig_wrapper_python lldb-python-doc-package)
else()
message(STATUS "Could NOT find epydoc")
endif()
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 34f03e11c007..86eb9e484713 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -4,19 +4,19 @@ endif()
get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
-if(LLDB_ENABLE_PYTHON)
- get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR)
- set(lldb_python_wrapper ${lldb_bindings_dir}/LLDBWrapPython.cpp)
+if(LLDB_BUILD_FRAMEWORK)
+ set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR})
+ set(option_framework FRAMEWORK)
endif()
-if(LLDB_ENABLE_LUA)
- get_target_property(lldb_bindings_dir swig_wrapper_lua BINARY_DIR)
- set(lldb_lua_wrapper ${lldb_bindings_dir}/LLDBWrapLua.cpp)
+if(LLDB_ENABLE_PYTHON)
+ get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR)
+ set(lldb_python_wrapper ${python_bindings_dir}/LLDBWrapPython.cpp)
endif()
-if(LLDB_BUILD_FRAMEWORK)
- set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR})
- set(option_framework FRAMEWORK)
+if(LLDB_ENABLE_LUA)
+ get_target_property(lua_bindings_dir swig_wrapper_lua BINARY_DIR)
+ set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp)
endif()
add_lldb_library(liblldb SHARED ${option_framework}
@@ -127,8 +127,8 @@ if(PYTHON_RPATH)
endif()
-if(lldb_python_wrapper)
- add_dependencies(liblldb swig_wrapper)
+if(LLDB_ENABLE_PYTHON)
+ add_dependencies(liblldb swig_wrapper_python)
if (MSVC)
set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
@@ -148,7 +148,7 @@ if(lldb_python_wrapper)
endif ()
endif()
-if(lldb_lua_wrapper)
+if(LLDB_ENABLE_LUA)
add_dependencies(liblldb swig_wrapper_lua)
target_include_directories(liblldb PRIVATE ${LUA_INCLUDE_DIR})
More information about the lldb-commits
mailing list