[Lldb-commits] [lldb] r350393 - [CMake] Python bindings generation polishing
Stefan Granitz via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 4 04:47:02 PST 2019
Author: stefan.graenitz
Date: Fri Jan 4 04:47:02 2019
New Revision: 350393
URL: http://llvm.org/viewvc/llvm-project?rev=350393&view=rev
Log:
[CMake] Python bindings generation polishing
Summary:
Simplify SWIG invocation and handling of generated files.
The `swig_wrapper` target can generate `LLDBWrapPython.cpp` and `lldb.py` in its own binary directory, so we can get rid of a few global variables and their logic. We can use the swig_wrapper's BINARY_DIR target property to refer to it and liblldb's LIBRARY_OUTPUT_DIRECTORY to refer to the framework/shared object output directory.
Reviewers: JDevlieghere, aprantl, stella.stamenova, beanz, zturner, xiaobai
Reviewed By: aprantl
Subscribers: mgorny, lldb-commits, #lldb
Differential Revision: https://reviews.llvm.org/D55332
Modified:
lldb/trunk/CMakeLists.txt
lldb/trunk/scripts/CMakeLists.txt
lldb/trunk/source/API/CMakeLists.txt
Modified: lldb/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/CMakeLists.txt?rev=350393&r1=350392&r2=350393&view=diff
==============================================================================
--- lldb/trunk/CMakeLists.txt (original)
+++ lldb/trunk/CMakeLists.txt Fri Jan 4 04:47:02 2019
@@ -30,14 +30,6 @@ endif()
add_subdirectory(docs)
if (NOT LLDB_DISABLE_PYTHON)
- set(LLDB_PYTHON_TARGET_DIR ${LLDB_BINARY_DIR}/scripts)
- set(LLDB_WRAP_PYTHON ${LLDB_BINARY_DIR}/scripts/LLDBWrapPython.cpp)
- if(LLDB_BUILD_FRAMEWORK)
- set(LLDB_PYTHON_TARGET_DIR ${LLDB_FRAMEWORK_BUILD_DIR})
- set(LLDB_WRAP_PYTHON ${LLDB_PYTHON_TARGET_DIR}/LLDBWrapPython.cpp)
- endif()
-
-
add_subdirectory(scripts)
endif ()
add_subdirectory(source)
@@ -133,26 +125,27 @@ if (NOT LLDB_DISABLE_PYTHON)
if(LLDB_USE_SYSTEM_SIX)
set(use_six_py_from_system --useSystemSix)
endif()
+ get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR)
+ get_target_property(liblldb_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
# 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(finish_swig ALL
COMMAND
- ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
+ ${PYTHON_EXECUTABLE} ${LLDB_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
--srcRoot=${LLDB_SOURCE_DIR}
- --targetDir=${LLDB_PYTHON_TARGET_DIR}
- --cfgBldDir=${LLDB_PYTHON_TARGET_DIR}
+ --targetDir=${liblldb_build_dir}
+ --cfgBldDir=${lldb_scripts_dir}
--prefix=${CMAKE_BINARY_DIR}
--cmakeBuildConfiguration=${CMAKE_CFG_INTDIR}
--lldbLibDir=lib${LLVM_LIBDIR_SUFFIX}
${use_python_wrapper_from_src_dir}
${use_six_py_from_system}
VERBATIM
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
- DEPENDS ${LLDB_PYTHON_TARGET_DIR}/lldb.py
+ DEPENDS ${LLDB_SOURCE_DIR}/scripts/finishSwigWrapperClasses.py
+ DEPENDS ${lldb_scripts_dir}/lldb.py
COMMENT "Python script sym-linking LLDB Python API")
-
if (TARGET readline)
set(readline_dep readline)
endif()
Modified: lldb/trunk/scripts/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/CMakeLists.txt?rev=350393&r1=350392&r2=350393&view=diff
==============================================================================
--- lldb/trunk/scripts/CMakeLists.txt (original)
+++ lldb/trunk/scripts/CMakeLists.txt Fri Jan 4 04:47:02 2019
@@ -11,31 +11,14 @@ set(SWIG_HEADERS
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})
-else()
- set(SWIG_PYTHON_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/site-packages)
-endif()
-
-set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
-
-# Generating the LLDB framework correctly is a bit complicated because the
-# framework depends on the swig output.
if(LLDB_BUILD_FRAMEWORK)
set(framework_arg --framework --target-platform Darwin)
- set(SWIG_PYTHON_DIR
- ${LLDB_PYTHON_TARGET_DIR}/${LLDB_FRAMEWORK_RESOURCE_DIR}/Python)
- set(SWIG_INSTALL_DIR
- ${LLDB_FRAMEWORK_INSTALL_DIR}/${LLDB_FRAMEWORK_RESOURCE_DIR})
endif()
-get_filename_component(CFGBLDDIR ${LLDB_WRAP_PYTHON} DIRECTORY)
-
find_package(SWIG REQUIRED)
add_custom_command(
- OUTPUT ${LLDB_WRAP_PYTHON}
- OUTPUT ${LLDB_PYTHON_TARGET_DIR}/lldb.py
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
DEPENDS ${SWIG_SOURCES}
DEPENDS ${SWIG_INTERFACES}
DEPENDS ${SWIG_HEADERS}
@@ -44,19 +27,31 @@ add_custom_command(
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/prepare_bindings.py
${framework_arg}
--srcRoot=${LLDB_SOURCE_DIR}
- --targetDir=${LLDB_PYTHON_TARGET_DIR}
- --cfgBldDir=${CFGBLDDIR}
+ --targetDir=${CMAKE_CURRENT_BINARY_DIR}
+ --cfgBldDir=${CMAKE_CURRENT_BINARY_DIR}
--prefix=${CMAKE_BINARY_DIR}
--swigExecutable=${SWIG_EXECUTABLE}
VERBATIM
COMMENT "Python script building LLDB Python wrapper")
-add_custom_target(swig_wrapper ALL DEPENDS ${LLDB_WRAP_PYTHON})
-set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lldb.py PROPERTIES GENERATED 1)
+add_custom_target(swig_wrapper ALL DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/lldb.py
+)
+
+if(NOT LLDB_BUILD_FRAMEWORK)
+ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(swig_python_subdir site-packages)
+ else()
+ set(swig_python_subdir python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
+ endif()
+ set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir})
+ set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX})
-# Install the LLDB python module
-install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR})
+ # Install the LLDB python module
+ install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR})
+endif()
# build Python modules
add_subdirectory(Python/modules)
Modified: lldb/trunk/source/API/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/CMakeLists.txt?rev=350393&r1=350392&r2=350393&view=diff
==============================================================================
--- lldb/trunk/source/API/CMakeLists.txt (original)
+++ lldb/trunk/source/API/CMakeLists.txt Fri Jan 4 04:47:02 2019
@@ -4,6 +4,11 @@ endif()
get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
+if(NOT LLDB_DISABLE_PYTHON)
+ get_target_property(lldb_scripts_dir swig_wrapper BINARY_DIR)
+ set(lldb_python_wrapper ${lldb_scripts_dir}/LLDBWrapPython.cpp)
+endif()
+
add_lldb_library(liblldb SHARED
SBAddress.cpp
SBAttachInfo.cpp
@@ -73,7 +78,7 @@ add_lldb_library(liblldb SHARED
SBWatchpoint.cpp
SBUnixSignals.cpp
SystemInitializerFull.cpp
- ${LLDB_WRAP_PYTHON}
+ ${lldb_python_wrapper}
LINK_LIBS
lldbBase
@@ -92,23 +97,23 @@ add_lldb_library(liblldb SHARED
Support
)
-if(LLDB_WRAP_PYTHON)
+if(lldb_python_wrapper)
add_dependencies(liblldb swig_wrapper)
if (MSVC)
- set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
+ set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0")
else()
- set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
+ set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " -w")
endif()
- set_source_files_properties(${LLDB_WRAP_PYTHON} PROPERTIES GENERATED 1)
+ set_source_files_properties(${lldb_python_wrapper} PROPERTIES GENERATED ON)
if (CLANG_CL)
- set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING
+ set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
PROPERTY COMPILE_FLAGS " -Wno-unused-function")
endif()
if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND
NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
- set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING
+ set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING
PROPERTY COMPILE_FLAGS " -Wno-sequence-point -Wno-cast-qual")
endif ()
endif()
More information about the lldb-commits
mailing list