1 set(SWIG_EXTRA_FLAGS -c++ -threads -python)
3 if ("${SWIG_VERSION}" VERSION_LESS "4.1.0")
4 set(SWIG_EXTRA_FLAGS ${SWIG_EXTRA_FLAGS} -py3)
5 message(STATUS "SWIG version ${SWIG_VERSION} uses `-py3` flag.")
9 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
10 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
11 DEPENDS ${SWIG_SOURCES}
12 DEPENDS ${SWIG_INTERFACES}
13 DEPENDS ${SWIG_HEADERS}
14 COMMAND ${SWIG_EXECUTABLE}
16 -I${CMAKE_CURRENT_SOURCE_DIR}
18 -outdir ${CMAKE_CURRENT_BINARY_DIR}
19 -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
20 ${CMAKE_CURRENT_SOURCE_DIR}/python.swig
22 COMMENT "Building LLDB Python wrapper")
24 add_custom_target(swig_wrapper_python ALL DEPENDS
25 ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
26 ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
31 OUTPUT ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-python
33 COMMAND ${CMAKE_COMMAND} -E copy lldb-python ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-python
34 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36 add_custom_target(lldb-python-wrapper ALL DEPENDS
37 ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-python
41 function(create_python_package swig_target working_dir pkg_dir)
42 cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN})
44 set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir})
47 set(init_cmd COMMAND ${Python3_EXECUTABLE}
48 "${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py"
49 "${pkg_dir}" ${ARG_FILES})
51 add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
52 COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir}
55 WORKING_DIRECTORY ${working_dir})
58 function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir)
59 # Add a Post-Build Event to copy over Python files and create the symlink to
60 # liblldb.so for the Python API(hardlink on Windows).
61 add_custom_target(${swig_target} ALL VERBATIM
62 COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir}
63 DEPENDS ${lldb_python_bindings_dir}/lldb.py
64 COMMENT "Python script sym-linking LLDB Python API")
66 add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
67 COMMAND ${CMAKE_COMMAND} -E copy
68 "${lldb_python_bindings_dir}/lldb.py"
69 "${lldb_python_target_dir}/__init__.py")
71 add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM
72 COMMAND ${CMAKE_COMMAND} -E copy
73 "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py"
74 "${lldb_python_target_dir}")
76 # Distribute the examples as python packages.
77 create_python_package(
79 ${lldb_python_target_dir}
81 FILES "${LLDB_SOURCE_DIR}/examples/synthetic/gnu_libstdcpp.py"
82 "${LLDB_SOURCE_DIR}/examples/synthetic/libcxx.py")
84 create_python_package(
86 ${lldb_python_target_dir}
88 FILES "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/cache.py"
89 "${LLDB_SOURCE_DIR}/examples/summaries/synth.py"
90 "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/metrics.py"
91 "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/attrib_fromdict.py"
92 "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/Logger.py")
94 create_python_package(
96 ${lldb_python_target_dir}
98 FILES "${LLDB_SOURCE_DIR}/examples/python/in_call_stack.py"
99 "${LLDB_SOURCE_DIR}/examples/python/symbolication.py")
101 create_python_package(
103 ${lldb_python_target_dir}
106 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py"
107 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py"
108 "${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py")
111 create_python_package(
113 ${lldb_python_target_dir} "macosx"
114 FILES "${LLDB_SOURCE_DIR}/examples/python/crashlog.py"
115 "${LLDB_SOURCE_DIR}/examples/python/crashlog_scripted_process.py"
116 "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap.py")
118 create_python_package(
120 ${lldb_python_target_dir} "macosx/heap"
121 FILES "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp"
122 "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile"
125 create_python_package(
127 ${lldb_python_target_dir} "diagnose"
128 FILES "${LLDB_SOURCE_DIR}/examples/python/diagnose_unwind.py"
129 "${LLDB_SOURCE_DIR}/examples/python/diagnose_nsstring.py")
132 if(LLDB_BUILD_FRAMEWORK)
133 set(LIBLLDB_SYMLINK_DEST "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB")
135 set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}")
137 set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb${LLDB_PYTHON_EXT_SUFFIX}")
138 create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
139 ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE})
143 add_dependencies(${swig_target} lldb-python-wrapper)
146 if(NOT LLDB_BUILD_FRAMEWORK)
147 set(LLDB_ARGDUMPER_FILENAME "lldb-argdumper${CMAKE_EXECUTABLE_SUFFIX}")
148 create_relative_symlink(${swig_target} "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}"
149 ${lldb_python_target_dir} ${LLDB_ARGDUMPER_FILENAME})
152 add_dependencies(${swig_target} swig_wrapper_python liblldb lldb-argdumper)
153 set_target_properties(${swig_target} swig_wrapper_python PROPERTIES FOLDER "lldb misc")
155 # Ensure we do the python post-build step when building lldb.
156 add_dependencies(lldb ${swig_target})
158 # Install the LLDB python module
159 if(LLDB_BUILD_FRAMEWORK)
160 set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources/Python)
162 set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH})
164 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
165 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
166 string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir})
168 set(python_scripts_target "${swig_target}-scripts")
169 set(python_scripts_install_target "install-${python_scripts_target}")
170 add_custom_target(${python_scripts_target})
171 add_dependencies(${python_scripts_target} ${swig_target})
172 install(DIRECTORY ${lldb_python_target_dir}/../
173 DESTINATION ${LLDB_PYTHON_INSTALL_PATH}
174 COMPONENT ${python_scripts_target})
175 if (NOT LLVM_ENABLE_IDE)
176 add_llvm_install_targets(${python_scripts_install_target}
177 COMPONENT ${python_scripts_target}
178 DEPENDS ${python_scripts_target})
181 # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching
182 # lldb.exe or any other executables that were linked with liblldb.
183 if (WIN32 AND NOT "${PYTHON_DLL}" STREQUAL "")
184 # When using the Visual Studio CMake generator the lldb binaries end up in Release/bin, Debug/bin etc.
185 file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin" LLDB_BIN_DIR)
186 file(TO_NATIVE_PATH "${PYTHON_DLL}" PYTHON_DLL_NATIVE_PATH)
188 TARGET ${swig_target}
190 COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM
191 COMMENT "Copying Python DLL to LLDB binaries directory.")