diff options
author | Mehdi Amini <joker.eph@gmail.com> | 2021-11-12 02:30:53 +0000 |
---|---|---|
committer | Mehdi Amini <joker.eph@gmail.com> | 2021-11-12 02:30:53 +0000 |
commit | 1a6c26d1f52999edbfbf6a978ae3f0e6759ea755 (patch) | |
tree | d1e66778ee69bee7d21a63fc4191c010538dbf55 /mlir/cmake | |
parent | 72e947765a8f99cb415e366f0df3a6c8a4969732 (diff) | |
download | llvm-1a6c26d1f52999edbfbf6a978ae3f0e6759ea755.zip llvm-1a6c26d1f52999edbfbf6a978ae3f0e6759ea755.tar.gz llvm-1a6c26d1f52999edbfbf6a978ae3f0e6759ea755.tar.bz2 |
Revert "[mlir] Allow out-of-tree python building from installed MLIR."
This reverts commit c7be8b75399c727ec9e1ddc3f81510f284c65155.
Build is broken (multiple buildbots)
Diffstat (limited to 'mlir/cmake')
-rw-r--r-- | mlir/cmake/modules/AddMLIRPython.cmake | 154 | ||||
-rw-r--r-- | mlir/cmake/modules/MLIRConfig.cmake.in | 1 |
2 files changed, 30 insertions, 125 deletions
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake index dd5b709..cc977000 100644 --- a/mlir/cmake/modules/AddMLIRPython.cmake +++ b/mlir/cmake/modules/AddMLIRPython.cmake @@ -35,7 +35,6 @@ function(declare_mlir_python_sources name) if(NOT ARG_ROOT_DIR) set(ARG_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") endif() - set(_install_destination "src/python/${name}") # Process the glob. set(_glob_sources) @@ -51,44 +50,21 @@ function(declare_mlir_python_sources name) # We create a custom target to carry properties and dependencies for # generated sources. - add_library(${name} INTERFACE) + add_custom_target(${name}) set(_file_depends "${ARG_SOURCES}") list(TRANSFORM _file_depends PREPEND "${ARG_ROOT_DIR}/") set_target_properties(${name} PROPERTIES - # Yes: Leading-lowercase property names are load bearing and the recommended - # way to do this: https://gitlab.kitware.com/cmake/cmake/-/issues/19261 - # Note that ROOT_DIR and FILE_DEPENDS are not exported because they are - # only relevant to in-tree uses. - EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_DEST_PREFIX;mlir_python_DEST_PREFIX;mlir_python_SOURCES;mlir_python_DEPENDS" - mlir_python_SOURCES_TYPE pure - mlir_python_ROOT_DIR "${ARG_ROOT_DIR}" - mlir_python_DEST_PREFIX "${ARG_DEST_PREFIX}" - mlir_python_SOURCES "${ARG_SOURCES}" - mlir_python_FILE_DEPENDS "${_file_depends}" - mlir_python_DEPENDS "" - ) - # Note that an "include" directory has no meaning to such faux targets, - # but it is a CMake supported way to specify a directory search list in a - # way that works both in-tree and out. It has some super powers which are - # not possible to emulate with custom properties (because of the prohibition - # on using generator expressions in exported custom properties and the - # special dispensation for $<INSTALL_PREFIX>). - target_include_directories(${name} INTERFACE - "$<BUILD_INTERFACE:${ARG_ROOT_DIR}>" - "$<INSTALL_INTERFACE:${_install_destination}>" + PYTHON_SOURCES_TYPE pure + PYTHON_ROOT_DIR "${ARG_ROOT_DIR}" + PYTHON_DEST_PREFIX "${ARG_DEST_PREFIX}" + PYTHON_SOURCES "${ARG_SOURCES}" + PYTHON_FILE_DEPENDS "${_file_depends}" + PYTHON_DEPENDS "" ) # Add to parent. if(ARG_ADD_TO_PARENT) - set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY mlir_python_DEPENDS ${name}) - endif() - - # Install. - if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - _mlir_python_install_sources( - ${name} "${ARG_ROOT_DIR}" "${_install_destination}" - ${ARG_SOURCES} - ) + set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY PYTHON_DEPENDS ${name}) endif() endfunction() @@ -96,8 +72,6 @@ endfunction() # Declares a buildable python extension from C++ source files. The built # module is considered a python source file and included as everything else. # Arguments: -# ROOT_DIR: Root directory where sources are interpreted relative to. -# Defaults to CMAKE_CURRENT_SOURCE_DIR. # MODULE_NAME: Local import name of the module (i.e. "_mlir"). # ADD_TO_PARENT: Same as for declare_mlir_python_sources. # SOURCES: C++ sources making up the module. @@ -110,77 +84,27 @@ endfunction() function(declare_mlir_python_extension name) cmake_parse_arguments(ARG "" - "ROOT_DIR;MODULE_NAME;ADD_TO_PARENT" + "MODULE_NAME;ADD_TO_PARENT" "SOURCES;PRIVATE_LINK_LIBS;EMBED_CAPI_LINK_LIBS" ${ARGN}) - if(NOT ARG_ROOT_DIR) - set(ARG_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - endif() - set(_install_destination "src/python/${name}") - - add_library(${name} INTERFACE) + add_custom_target(${name}) set_target_properties(${name} PROPERTIES - # Yes: Leading-lowercase property names are load bearing and the recommended - # way to do this: https://gitlab.kitware.com/cmake/cmake/-/issues/19261 - # Note that ROOT_DIR and FILE_DEPENDS are not exported because they are - # only relevant to in-tree uses. - EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_EXTENSION_MODULE_NAME;mlir_python_CPP_SOURCES;mlir_python_PRIVATE_LINK_LIBS;mlir_python_EMBED_CAPI_LINK_LIBS;mlir_python_DEPENDS" - mlir_python_SOURCES_TYPE extension - mlir_python_ROOT_DIR "${ARG_ROOT_DIR}" - mlir_python_EXTENSION_MODULE_NAME "${ARG_MODULE_NAME}" - mlir_python_CPP_SOURCES "${ARG_SOURCES}" - mlir_python_PRIVATE_LINK_LIBS "${ARG_PRIVATE_LINK_LIBS}" - mlir_python_EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS}" - mlir_python_FILE_DEPENDS "" - mlir_python_DEPENDS "" - ) - # Note that an "include" directory has no meaning to such faux targets, - # but it is a CMake supported way to specify an install-prefix relative - # directory. It has some super powers which are not possible to emulate - # with custom properties (because of the prohibition on using generator - # expressions in exported custom properties and the special dispensation - # for $<INSTALL_PREFIX> and $<INSTALL_INTERFACE>). On imported targets, - # this is used as a single value, not as a list, so it must only have one - # item in it. - target_include_directories(${name} INTERFACE - "$<INSTALL_INTERFACE:${_install_destination}>" + PYTHON_SOURCES_TYPE extension + PYTHON_EXTENSION_MODULE_NAME "${ARG_MODULE_NAME}" + PYTHON_CPP_SOURCES "${ARG_SOURCES}" + PYTHON_PRIVATE_LINK_LIBS "${ARG_PRIVATE_LINK_LIBS}" + PYTHON_EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS}" + PYTHON_FILE_DEPENDS "" + PYTHON_DEPENDS "" ) # Add to parent. if(ARG_ADD_TO_PARENT) - set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY mlir_python_DEPENDS ${name}) - endif() - - # Install. - if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - _mlir_python_install_sources( - ${name} "${ARG_ROOT_DIR}" "src/python/${name}" - ${ARG_SOURCES} - ) + set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY PYTHON_DEPENDS ${name}) endif() endfunction() -function(_mlir_python_install_sources name source_root_dir destination) - foreach(source_relative_path ${ARGN}) - # Transform "a/b/c.py" -> "${install_prefix}/a/b" for installation. - get_filename_component( - dest_relative_path "${source_relative_path}" DIRECTORY - BASE_DIR "${source_root_dir}" - ) - install( - FILES "${source_root_dir}/${source_relative_path}" - DESTINATION "${destination}/${dest_relative_path}" - COMPONENT "${name}" - ) - endforeach() - get_target_export_arg(${name} MLIR export_to_mlirtargets UMBRELLA mlir-libraries) - install(TARGETS ${name} - COMPONENT ${name} - ${export_to_mlirtargets} - ) -endfunction() - # Function: add_mlir_python_modules # Adds python modules to a project, building them from a list of declared # source groupings (see declare_mlir_python_sources and @@ -204,26 +128,12 @@ function(add_mlir_python_modules name) ${ARGN}) # Helper to process an individual target. function(_process_target modules_target sources_target) - get_target_property(_source_type ${sources_target} mlir_python_SOURCES_TYPE) - - # The root directory differs based on whether it is IMPORTED (installed - # dep). - get_target_property(_is_imported ${sources_target} IMPORTED) - if(NOT _is_imported) - # In-tree. - get_target_property(_python_root_dir ${sources_target} mlir_python_ROOT_DIR) - else() - # Imported. - # Note: We only populate a single directory in - # INTERFACE_INCLUDE_DIRECTORIES, so we can get away with just using it - # as a single value. - get_target_property(_python_root_dir ${sources_target} INTERFACE_INCLUDE_DIRECTORIES) - endif() - + get_target_property(_source_type ${sources_target} PYTHON_SOURCES_TYPE) if(_source_type STREQUAL "pure") # Pure python sources to link into the tree. - get_target_property(_python_sources ${sources_target} mlir_python_SOURCES) - get_target_property(_specified_dest_prefix ${sources_target} mlir_python_DEST_PREFIX) + get_target_property(_python_root_dir ${sources_target} PYTHON_ROOT_DIR) + get_target_property(_python_sources ${sources_target} PYTHON_SOURCES) + get_target_property(_specified_dest_prefix ${sources_target} PYTHON_DEST_PREFIX) foreach(_source_relative_path ${_python_sources}) set(_dest_relative_path "${_source_relative_path}") if(_specified_dest_prefix) @@ -252,11 +162,9 @@ function(add_mlir_python_modules name) endforeach() elseif(_source_type STREQUAL "extension") # Native CPP extension. - get_target_property(_module_name ${sources_target} mlir_python_EXTENSION_MODULE_NAME) - get_target_property(_cpp_sources ${sources_target} mlir_python_CPP_SOURCES) - get_target_property(_private_link_libs ${sources_target} mlir_python_PRIVATE_LINK_LIBS) - # Transform relative source to based on root dir. - list(TRANSFORM _cpp_sources PREPEND "${_python_root_dir}/") + get_target_property(_module_name ${sources_target} PYTHON_EXTENSION_MODULE_NAME) + get_target_property(_cpp_sources ${sources_target} PYTHON_CPP_SOURCES) + get_target_property(_private_link_libs ${sources_target} PYTHON_PRIVATE_LINK_LIBS) set(_extension_target "${name}.extension.${_module_name}.dso") add_mlir_python_extension(${_extension_target} "${_module_name}" INSTALL_COMPONENT ${modules_target} @@ -279,10 +187,8 @@ function(add_mlir_python_modules name) # Collect dependencies. set(_depends) foreach(sources_target ${_flat_targets}) - get_target_property(_local_depends ${sources_target} mlir_python_FILE_DEPENDS) - if(_local_depends) - list(APPEND _depends ${_local_depends}) - endif() + get_target_property(_local_depends ${sources_target} PYTHON_FILE_DEPENDS) + list(APPEND _depends ${_local_depends}) endforeach() # Build the modules target. @@ -428,7 +334,7 @@ function(add_mlir_python_common_capi_library name) set(_embed_libs ${ARG_EMBED_LIBS}) _flatten_mlir_python_targets(_all_source_targets ${ARG_DECLARED_SOURCES}) foreach(t ${_all_source_targets}) - get_target_property(_local_embed_libs ${t} mlir_python_EMBED_CAPI_LINK_LIBS) + get_target_property(_local_embed_libs ${t} PYTHON_EMBED_CAPI_LINK_LIBS) if(_local_embed_libs) list(APPEND _embed_libs ${_local_embed_libs}) endif() @@ -466,8 +372,8 @@ endfunction() function(_flatten_mlir_python_targets output_var) set(_flattened) foreach(t ${ARGN}) - get_target_property(_source_type ${t} mlir_python_SOURCES_TYPE) - get_target_property(_depends ${t} mlir_python_DEPENDS) + get_target_property(_source_type ${t} PYTHON_SOURCES_TYPE) + get_target_property(_depends ${t} PYTHON_DEPENDS) if(_source_type) list(APPEND _flattened "${t}") if(_depends) diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in index 9f70647..93ca162 100644 --- a/mlir/cmake/modules/MLIRConfig.cmake.in +++ b/mlir/cmake/modules/MLIRConfig.cmake.in @@ -10,7 +10,6 @@ set(MLIR_CMAKE_DIR "@MLIR_CONFIG_CMAKE_DIR@") set(MLIR_INCLUDE_DIRS "@MLIR_CONFIG_INCLUDE_DIRS@") set(MLIR_TABLEGEN_EXE "@MLIR_TABLEGEN_EXE@") set(MLIR_INSTALL_AGGREGATE_OBJECTS "@MLIR_INSTALL_AGGREGATE_OBJECTS@") -set(MLIR_ENABLE_BINDINGS_PYTHON "@MLIR_ENABLE_BINDINGS_PYTHON@") # For mlir_tablegen() set(MLIR_INCLUDE_DIR "@MLIR_INCLUDE_DIR@") |