mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52093 # Summary The previous debug if statement only prints the file list, but it's not clear whether the target includes the file list correctly. This function can examine the target so it's more accurate. This pr includes changes: 1. Add a file `DebugHelper.cmake` with `print_target_properties` function. 2. Replace the debug if statement `if(FALSE)` by adding magical variable `PRINT_CMAKE_DEBUG_INFO` and applying the variable accordingly. Note: previous debug if statement output example: ``` -- CPU sources: -- /Users/chenlai/pytorch/aten/src/ATen/BatchedFallback.cpp -- /Users/chenlai/pytorch/aten/src/ATen/BatchedTensorImpl.cpp -- /Users/chenlai/pytorch/aten/src/ATen/BatchingRegistrations.cpp -- /Users/chenlai/pytorch/aten/src/ATen/CPUGeneratorImpl.cpp -- /Users/chenlai/pytorch/aten/src/ATen/Context.cpp -- /Users/chenlai/pytorch/aten/src/ATen/DLConvertor.cpp -- /Users/chenlai/pytorch/aten/src/ATen/DynamicLibrary.cpp -- /Users/chenlai/pytorch/aten/src/ATen/ExpandUtils.cpp -- /Users/chenlai/pytorch/aten/src/ATen/LegacyTHFunctionsCPU.cpp -- /Users/chenlai/pytorch/aten/src/ATen/MemoryOverlap.cpp ... -- GPU sources: -- CPU include: -- /Users/chenlai/pytorch/build_android/caffe2/aten/src/TH -- /Users/chenlai/pytorch/aten/src/TH -- /Users/chenlai/pytorch/aten/src -- /Users/chenlai/pytorch/build_android/caffe2/aten/src ... -- GPU include: -- /Users/chenlai/pytorch/build_android/caffe2/aten/src/TH -- /Users/chenlai/pytorch/aten/src/TH -- /Users/chenlai/pytorch/build_android/caffe2/aten/src/TH -- /Users/chenlai/pytorch/aten/src/TH ``` # Test plan Set `PRINT_CMAKE_DEBUG_INFO` to true by adding `DPRINT_CMAKE_DEBUG_INFO` in `./scripts/build_pytorch_android.sh`, run `./scripts/build_pytorch_android.sh x86` `print_target_properties(torch)` shows ``` torch ANDROID_ARCH = x86 torch ANDROID_STL_TYPE = c++_static torch ARCHIVE_OUTPUT_DIRECTORY = /Users/chenlai/pytorch/build_android_x86/lib torch AUTOGEN_ORIGIN_DEPENDS = ON torch AUTOMOC_COMPILER_PREDEFINES = ON torch AUTOMOC_MACRO_NAMES = Q_OBJECT;Q_GADGET;Q_NAMESPACE;Q_NAMESPACE_EXPORT torch AUTOMOC_PATH_PREFIX = OFF torch BINARY_DIR = /Users/chenlai/pytorch/build_android_x86/caffe2 torch BINARY_DIR = /Users/chenlai/pytorch/build_android_x86/caffe2 torch BUILD_WITH_INSTALL_RPATH = FALSE torch CXX_STANDARD = 14 torch C_STANDARD = 11 torch IMPORTED = FALSE torch IMPORTED_GLOBAL = FALSE torch INCLUDE_DIRECTORIES = /Users/chenlai/pytorch/build_android_x86/aten/src;/Users/chenlai/pytorch/aten/src;/Users/chenlai/pytorch/build_android_x86;/Users/chenlai/pytorch;/Users/chenlai/pytorch/third_party/XNNPACK/include;/Users/chenlai/Library/Android/sdk/ndk/21.3.6528147/sources/third_party/vulkan/src/common;/Users/chenlai/pytorch/cmake/../third_party/eigen;/Users/chenlai/pytorch/cmake/../third_party/pybind11/include torch INCLUDE_DIRECTORIES = /Users/chenlai/pytorch/build_android_x86/aten/src;/Users/chenlai/pytorch/aten/src;/Users/chenlai/pytorch/build_android_x86;/Users/chenlai/pytorch;/Users/chenlai/pytorch/third_party/XNNPACK/include;/Users/chenlai/Library/Android/sdk/ndk/21.3.6528147/sources/third_party/vulkan/src/common;/Users/chenlai/pytorch/cmake/../third_party/eigen;/Users/chenlai/pytorch/cmake/../third_party/pybind11/include torch INCLUDE_DIRECTORIES = /Users/chenlai/pytorch/build_android_x86/aten/src;/Users/chenlai/pytorch/aten/src;/Users/chenlai/pytorch/build_android_x86;/Users/chenlai/pytorch;/Users/chenlai/pytorch/third_party/XNNPACK/include;/Users/chenlai/Library/Android/sdk/ndk/21.3.6528147/sources/third_party/vulkan/src/common;/Users/chenlai/pytorch/cmake/../third_party/eigen;/Users/chenlai/pytorch/cmake/../third_party/pybind11/include torch INSTALL_RPATH = $ORIGIN torch INSTALL_RPATH_USE_LINK_PATH = TRUE torch INTERFACE_LINK_LIBRARIES = torch_cpu_library torch ISPC_HEADER_SUFFIX = _ispc.h torch LIBRARY_OUTPUT_DIRECTORY = /Users/chenlai/pytorch/build_android_x86/lib torch LINK_LIBRARIES = torch_cpu_library torch NAME = torch torch PCH_INSTANTIATE_TEMPLATES = ON torch PCH_WARN_INVALID = ON torch POSITION_INDEPENDENT_CODE = TRUE torch RUNTIME_OUTPUT_DIRECTORY = /Users/chenlai/pytorch/build_android_x86/bin torch SKIP_BUILD_RPATH = FALSE torch SOURCES = /Users/chenlai/pytorch/build_android_x86/empty.cpp torch SOURCE_DIR = /Users/chenlai/pytorch/caffe2 torch SOURCE_DIR = /Users/chenlai/pytorch/caffe2 torch TYPE = STATIC_LIBRARY torch TYPE = STATIC_LIBRARY torch UNITY_BUILD_BATCH_SIZE = 8 torch UNITY_BUILD_MODE = BATCH ``` Test Plan: Imported from OSS Reviewed By: walterddr Differential Revision: D26377725 Pulled By: cccclai fbshipit-source-id: dbe21ad533759f33711a0ce5328205bbcd5cf0f3
27 lines
1.1 KiB
CMake
27 lines
1.1 KiB
CMake
function(print_target_properties tgt)
|
|
# Get all propreties that cmake supports
|
|
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
|
|
|
|
# Convert command output into a CMake list
|
|
STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
|
|
STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
|
|
if(NOT TARGET ${tgt})
|
|
message("There is no target named '${tgt}'")
|
|
return()
|
|
endif()
|
|
|
|
foreach(prop ${CMAKE_PROPERTY_LIST})
|
|
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" prop ${prop})
|
|
# Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i
|
|
if(prop STREQUAL "LOCATION" OR prop MATCHES "^LOCATION_" OR prop MATCHES "_LOCATION$")
|
|
continue()
|
|
endif()
|
|
# message ("Checking ${prop}")
|
|
get_property(propval TARGET ${tgt} PROPERTY ${prop} SET)
|
|
if(propval)
|
|
get_target_property(propval ${tgt} ${prop})
|
|
message("${tgt} ${prop} = ${propval}")
|
|
endif()
|
|
endforeach(prop)
|
|
endfunction(print_target_properties)
|