This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch tirx/standalone-package-cleanup
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 760fae90d2ccbfe9287ec0b89ec2a77cc555b83e
Author: Tianqi Chen <[email protected]>
AuthorDate: Thu Oct 15 01:37:33 2026 +0000

    [REFACTOR][CMake] Build and install independent core and parent libraries
---
 CMakeLists.txt                                     | 836 +++++----------------
 .../modules => cmake/modules/contrib}/CUDA.cmake   |  78 --
 .../modules => cmake/modules/contrib}/ROCM.cmake   |  36 -
 tests/cpp/CMakeLists.txt                           |   2 +-
 CMakeLists.txt => tirx/CMakeLists.txt              | 484 +++++-------
 tirx/cmake/modules/CUDA.cmake                      |  73 +-
 tirx/cmake/modules/ClangFlags.cmake                |   2 +-
 tirx/cmake/modules/Logging.cmake                   |   5 +-
 tirx/cmake/modules/OpenCL.cmake                    |  11 +-
 tirx/cmake/modules/ROCM.cmake                      |  31 -
 tirx/cmake/modules/contrib/Z3.cmake                |  12 +
 .../Logging.cmake => tvm_tirxConfig.cmake.in}      |  30 +-
 {tests => tirx/tests}/cpp/CMakeLists.txt           |  32 +-
 13 files changed, 440 insertions(+), 1192 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfa62d6b9d..3e40018bb0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,88 +1,99 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
 cmake_minimum_required(VERSION 3.18)
 project(tvm C CXX)
-
-# --- TVM version (no dependency on version.py) ---
-# When built via scikit-build-core the version is resolved by setuptools_scm 
and
-# passed in as SKBUILD_PROJECT_VERSION_FULL; bake it into the C++ TVM_VERSION 
macro.
-# A bare `cmake` build (no scikit-build-core) leaves the checked-in default in
-# include/tvm/runtime/base.h untouched. An explicit -DTVM_VERSION always wins.
-if(NOT DEFINED TVM_VERSION AND DEFINED SKBUILD_PROJECT_VERSION_FULL)
-  set(TVM_VERSION "${SKBUILD_PROJECT_VERSION_FULL}")
+include(GNUInstallDirs)
+if(EXISTS "${CMAKE_BINARY_DIR}/config.cmake")
+  include("${CMAKE_BINARY_DIR}/config.cmake")
+elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config.cmake")
+  include("${CMAKE_CURRENT_SOURCE_DIR}/config.cmake")
 endif()
-if(DEFINED TVM_VERSION)
-  message(STATUS "TVM_VERSION=${TVM_VERSION}")
-  add_compile_definitions(TVM_VERSION="${TVM_VERSION}")
+set(_installed_tirx ON)
+if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tirx/CMakeLists.txt")
+  set(_installed_tirx OFF)
 endif()
-
-# Utility functions
-include(cmake/utils/Utils.cmake)
-include(cmake/utils/Summary.cmake)
-include(cmake/utils/Linker.cmake)
-include(cmake/utils/Library.cmake)
-include(cmake/utils/FindCUDA.cmake)
-include(cmake/utils/FindNCCL.cmake)
-include(cmake/utils/FindOpenCL.cmake)
-include(cmake/utils/FindVulkan.cmake)
-include(cmake/utils/FindLLVM.cmake)
-include(cmake/utils/FindROCM.cmake)
-include(cmake/utils/FindRCCL.cmake)
-include(cmake/utils/FindNVSHMEM.cmake)
-
-if(EXISTS ${CMAKE_BINARY_DIR}/config.cmake)
-  include(${CMAKE_BINARY_DIR}/config.cmake)
+option(TVM_USE_INSTALLED_TIRX "Build against an installed apache-tvm-tirx 
package" ${_installed_tirx})
+option(TVM_BUILD_PYTHON_MODULE "Build Python module with scikit-build-core" 
OFF)
+if(TVM_BUILD_PYTHON_MODULE)
+  set(CMAKE_INSTALL_LIBDIR lib)
+endif()
+if(USE_CLML_GRAPH_EXECUTOR)
+  if(USE_CLML_GRAPH_EXECUTOR STREQUAL "ON")
+    set(USE_OPENCL "${CMAKE_CURRENT_SOURCE_DIR}/clml")
+  else()
+    set(USE_OPENCL "${USE_CLML_GRAPH_EXECUTOR}")
+  endif()
+endif()
+if(TVM_USE_INSTALLED_TIRX)
+  find_package(Python COMPONENTS Interpreter REQUIRED)
+  if(NOT tvm_tirx_DIR)
+    execute_process(COMMAND "${Python_EXECUTABLE}" -c
+      "import importlib.util; from pathlib import Path; 
print(Path(importlib.util.find_spec('tvm_tirx').origin).parent / 
'lib/cmake/tvm_tirx')"
+      OUTPUT_VARIABLE tvm_tirx_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
+      COMMAND_ERROR_IS_FATAL ANY)
+  endif()
+  find_package(tvm_tirx CONFIG REQUIRED)
+  if(NOT TVM_TIRX_VERSION STREQUAL "0.1.0a0")
+    message(FATAL_ERROR "TVM requires apache-tvm-tirx 0.1.0a0")
+  endif()
 else()
-  if(EXISTS ${CMAKE_SOURCE_DIR}/config.cmake)
-    include(${CMAKE_SOURCE_DIR}/config.cmake)
+  if(NOT TVM_OPENCL_HEADERS_ROOT AND EXISTS 
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/OpenCL-Headers/CL/cl.h")
+    set(TVM_OPENCL_HEADERS_ROOT 
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/OpenCL-Headers")
   endif()
+  add_subdirectory(tirx)
 endif()
-
-# NOTE: do not modify this file to change option values.
-# You can create a config.cmake at build folder
-# and add set(OPTION VALUE) to override these build options.
-# Alernatively, use cmake -DOPTION=VALUE through command-line.
-tvm_option(USE_CUDA "Build with CUDA" OFF)
+foreach(_utility Utils Summary Linker Library FindCUDA FindROCM FindOpenCL 
CCache)
+  include("${TVM_TIRX_CMAKE_DIR}/utils/${_utility}.cmake")
+endforeach()
+foreach(_collective NCCL RCCL NVSHMEM)
+  include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/Find${_collective}.cmake")
+endforeach()
+if(NOT TARGET tvm_ffi_header)
+  add_library(tvm_ffi_header ALIAS tvm_ffi::header)
+endif()
+# Keep existing integration modules' target names usable with an installed 
core.
+foreach(_library tvm_runtime tvm_runtime_static tvm_runtime_cuda 
tvm_runtime_rocm tvm_runtime_opencl tvm_runtime_vulkan tvm_runtime_metal)
+  if(NOT TARGET ${_library} AND TARGET tvm_tirx::${_library})
+    add_library(${_library} ALIAS tvm_tirx::${_library})
+  endif()
+endforeach()
+set(BUILD_FOR_ANDROID "${TVM_TIRX_BUILD_FOR_ANDROID}")
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CUDA_STANDARD 20)
+set(CMAKE_CUDA_STANDARD_REQUIRED ON)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+tvm_option(USE_CUDA "Build with CUDA" "${TVM_TIRX_USE_CUDA}")
 tvm_option(USE_NCCL "Build with NCCL" OFF)
-tvm_option(USE_OPENCL "Build with OpenCL" OFF)
-tvm_option(USE_OPENCL_ENABLE_HOST_PTR "Enable OpenCL memory object access to 
host" OFF)
-tvm_option(USE_OPENCL_GTEST "Path to OpenCL specific gtest version for runtime 
cpp tests." /path/to/opencl/gtest)
-tvm_option(USE_VULKAN "Build with Vulkan" OFF)
-
-
-# Whether to use spirv-tools and SPIRV-Headers from Khronos GitHub or GitLab.
-#
-# Possible values:
-# - OFF: not to use
-# - /path/to/install: path to your khronis spirv-tools and SPIRV-Headers 
installation directory
-#
-tvm_option(USE_KHRONOS_SPIRV "Whether to use spirv-tools and SPIRV-Headers 
from Khronos GitHub or GitLab" OFF)
-tvm_option(USE_SPIRV_KHR_INTEGER_DOT_PRODUCT "whether enable 
SPIRV_KHR_DOT_PRODUCT" OFF)
-tvm_option(USE_METAL "Build with Metal" OFF)
-tvm_option(USE_ROCM "Build with ROCM" OFF)
+tvm_option(USE_ROCM "Build with ROCM" "${TVM_TIRX_USE_ROCM}")
 tvm_option(USE_RCCL "Build with RCCL" OFF)
-tvm_option(ROCM_PATH "The path to rocm" /opt/rocm)
-tvm_option(USE_HEXAGON_QHL "Enable Hexagon QHL compiler lowering (requires 
external runtime wrappers)" OFF)
-
 tvm_option(USE_RPC "Build with RPC" ON)
 tvm_option(USE_THREADS "Build with thread support" ON)
-tvm_option(USE_LLVM "Build with LLVM, can be set to specific llvm-config path" 
OFF)
-tvm_option(USE_OPENMP "Build with OpenMP thread pool implementation" OFF)
 tvm_option(TVM_LOG_BEFORE_THROW "Whether log before throw, for debugging 
purposes" OFF)
-tvm_option(USE_RTTI "Build with RTTI" ON)
 tvm_option(USE_MSVC_MT "Build with MT" OFF)
 tvm_option(INSTALL_DEV "Install compiler infrastructure" OFF)
 tvm_option(HIDE_PRIVATE_SYMBOLS "Compile with -fvisibility=hidden." ON)
 tvm_option(INDEX_DEFAULT_I64 "Defaults the index datatype to int64" ON)
 tvm_option(USE_GTEST "Use GoogleTest for C++ sanity tests" AUTO)
-tvm_option(USE_CUSTOM_LOGGING "Use user-defined custom logging, 
tvm::runtime::detail::LogFatalImpl and tvm::runtime::detail::LogMessageImpl 
must be implemented" OFF)
 tvm_option(USE_ALTERNATIVE_LINKER "Use 'mold' or 'lld' if found when invoking 
compiler to link artifact" AUTO)
-tvm_option(USE_CCACHE "Use ccache if found when invoking compiler" AUTO)
-
-# 3rdparty libraries
-tvm_option(COMPILER_RT_PATH "Path to COMPILER-RT" "3rdparty/compiler-rt")
-# Contrib library options
 tvm_option(USE_BLAS "The blas library to be linked" none)
 tvm_option(USE_AMX "Enable Intel AMX" OFF)
-tvm_option(USE_Z3 "Build with Z3 SMT solver support" AUTO)
 tvm_option(USE_MKL "MKL root path when use MKL blas" OFF)
 tvm_option(USE_DNNL "Enable DNNL codegen" OFF)
 tvm_option(USE_CUDNN "Build with cuDNN" OFF)
@@ -108,190 +119,43 @@ tvm_option(USE_CLML "Build with CLML Codegen support" 
OFF)
 tvm_option(USE_CLML_GRAPH_EXECUTOR "Build with CLML graph runtime" OFF)
 tvm_option(USE_NVSHMEM "Build with NVSHMEM support" OFF)
 
-# Python package options
-tvm_option(TVM_BUILD_PYTHON_MODULE "Build Python module with 
scikit-build-core" OFF)
-
-# include directories
-include_directories(${CMAKE_INCLUDE_PATH})
-include_directories("include")
-include_directories(SYSTEM ${COMPILER_RT_PATH})
-
-# initial variables
-set(TVM_LINKER_LIBS "")
-set(TVM_RUNTIME_LINKER_LIBS "")
-set(TVM_RUNTIME_BACKEND_LIBS "")
-# Early target creation so contrib cmake files can call
-# target_link_libraries(tvm_runtime_extra PRIVATE <object_lib>) directly.
-add_library(tvm_runtime_extra SHARED)
-list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_extra)
-set_target_properties(tvm_runtime_extra PROPERTIES LINKER_LANGUAGE CXX)
-# INTERFACE target carrying compile definitions for OBJECT libs that build
-# into tvm_runtime_extra. On MSVC, TVM_RUNTIME_EXTRA_EXPORTS exports 
extra-owned
-# APIs while core-runtime APIs remain imports from tvm_runtime.dll.
-add_library(tvm_runtime_extra_defs INTERFACE)
-target_link_libraries(tvm_runtime_extra_defs INTERFACE tvm_ffi_header)
-target_compile_definitions(tvm_runtime_extra_defs
-  INTERFACE TVM_RUNTIME_EXTRA_EXPORTS TVM_FFI_EXPORTS)
-
-
-# Check if this is being run on its own or as a subdirectory for another 
project
-# If we update to CMake 2.21+, we can use PROJECT_IS_TOP_LEVEL instead
-get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
-
-if(NOT IS_SUBPROJECT AND NOT DEFINED "${CMAKE_EXPORT_COMPILE_COMMANDS}")
-  # If not set manually, change the default to ON
-  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-endif()
-
-if(TVM_LOG_BEFORE_THROW)
-  # log error before throw as
-  # when system have issues with stack trace
-  add_definitions(-DTVM_LOG_BEFORE_THROW=1)
-endif()
-
-# Generic compilation options
+include_directories(include)
 if(MSVC)
-  add_definitions(-DWIN32_LEAN_AND_MEAN)
-  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
-  add_definitions(-D_SCL_SECURE_NO_WARNINGS)
-  add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
-  add_definitions(-DNOMINMAX)
-  # regeneration does not work well with msbuild custom rules.
-  set(CMAKE_SUPPRESS_REGENERATION ON)
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
-  add_compile_options(/bigobj)
-
-  # Use standard-conforming two-phase name resolution for templates.
-  # This minimizes the differences between g++/clang builds on Linux,
-  # and MSVC builds on Windows.
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
-
-  # MSVC already errors on undefined symbols, no additional flag needed.
-  set(TVM_NO_UNDEFINED_SYMBOLS "")
-
+  add_compile_definitions(WIN32_LEAN_AND_MEAN _CRT_SECURE_NO_WARNINGS
+    _SCL_SECURE_NO_WARNINGS _ENABLE_EXTENDED_ALIGNED_STORAGE NOMINMAX)
+  add_compile_options(/bigobj /permissive- /EHsc)
   if(USE_MSVC_MT)
-    foreach(flag_var
-        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
-        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
-      if(${flag_var} MATCHES "/MD")
-        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
-      endif(${flag_var} MATCHES "/MD")
-    endforeach(flag_var)
-    # Static linking. CMake behavior changed in 3.15 making this necessary.
-    add_compile_options(/MT)
+    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
   endif()
-  # Disable common MSVC warnings
-  # Integer conversion warnings(e.g. int64 to int)
-  add_compile_options(/wd4244)
-  add_compile_options(/wd4267)
-  # Signed unsigned constant comparison
-  add_compile_options(/wd4018)
-  # Aligned alloc may not met(need c++17)
-  add_compile_options(/wd4316)
-  # unreferenced local variables(usually in exception catch)
-  add_compile_options(/wd4101)
-  # always inline keyword not necessary
-  add_compile_options(/wd4180)
-  # DLL interface warning in c++
-  add_compile_options(/wd4251)
-  # destructor was implicitly defined as deleted
-  add_compile_options(/wd4624)
-  # unary minus operator applied to unsigned type, result still unsigned
-  add_compile_options(/wd4146)
-  # 'inline': used more than once
-  add_compile_options(/wd4141)
-  # unknown pragma
-  add_compile_options(/wd4068)
-else(MSVC)
-  set(WARNING_FLAG -Wall)
-  if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-    message(STATUS "Build in Debug mode")
-    set(CMAKE_C_FLAGS "-O0 -g ${WARNING_FLAG} -fPIC ${CMAKE_C_FLAGS}")
-    set(CMAKE_CXX_FLAGS "-O0 -g ${WARNING_FLAG} -fPIC ${CMAKE_CXX_FLAGS}")
-    set(CMAKE_CUDA_FLAGS "-O0 -g -Xcompiler=-Wall -Xcompiler=-fPIC 
${CMAKE_CUDA_FLAGS}")
-  else()
-    set(CMAKE_C_FLAGS "-O2 ${WARNING_FLAG} -fPIC ${CMAKE_C_FLAGS}")
-    set(CMAKE_CXX_FLAGS "-O2 ${WARNING_FLAG} -fPIC ${CMAKE_CXX_FLAGS}")
-    set(CMAKE_CUDA_FLAGS "-O2 -Xcompiler=-Wall -Xcompiler=-fPIC 
${CMAKE_CUDA_FLAGS}")
-    set(TVM_VISIBILITY_FLAG "")
-    if (HIDE_PRIVATE_SYMBOLS)
-      message(STATUS "Hide private symbols...")
-      set(TVM_VISIBILITY_FLAG "-fvisibility=hidden")
-    endif(HIDE_PRIVATE_SYMBOLS)
-  endif ()
-  if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND
-      CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
-    set(CMAKE_CXX_FLAGS "-faligned-new ${CMAKE_CXX_FLAGS}")
+else()
+  add_compile_options(-Wall)
+  if(HIDE_PRIVATE_SYMBOLS)
+    add_compile_options(-fvisibility=hidden)
   endif()
-
-  # ld option to warn if symbols are undefined (e.g. libtvm_runtime.so
-  # using symbols only present in libtvm.so).  Not needed for MSVC,
-  # since this is already the default there.
-  if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES 
"iOS")
+  if(APPLE)
     set(TVM_NO_UNDEFINED_SYMBOLS "-Wl,-undefined,error")
   else()
     set(TVM_NO_UNDEFINED_SYMBOLS "-Wl,--no-undefined")
   endif()
-  message(STATUS "Forbidding undefined symbols in shared library, using 
${TVM_NO_UNDEFINED_SYMBOLS} on platform ${CMAKE_SYSTEM_NAME}")
-
-  # Detect if we're compiling for Android.
-  set(TEST_FOR_ANDROID_CXX
-      "#ifndef __ANDROID__"
-      "#error"
-      "#endif"
-      "int main() {}")
-  set(TEST_FOR_ANDROID_DIR
-      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
-  set(TEST_FOR_ANDROID_FILE "${TEST_FOR_ANDROID_DIR}/test_for_android.cc")
-  string(REPLACE ";" "\n" TEST_FOR_ANDROID_CXX_TEXT "${TEST_FOR_ANDROID_CXX}")
-  file(WRITE "${TEST_FOR_ANDROID_FILE}" "${TEST_FOR_ANDROID_CXX_TEXT}")
-  try_compile(BUILD_FOR_ANDROID "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"
-              "${TEST_FOR_ANDROID_FILE}")
-  file(REMOVE "${TEST_FOR_ANDROID_FILE}")
-  if(BUILD_FOR_ANDROID)
-    message(STATUS "Building for Android")
-  endif()
-endif(MSVC)
-
-list(APPEND TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS})
-
-# add source group
-tvm_file_glob(GLOB_RECURSE GROUP_SOURCE "src/*.cc")
-tvm_file_glob(GLOB_RECURSE GROUP_INCLUDE "src/*.h" "include/*.h")
-assign_source_group("Source" ${GROUP_SOURCE})
-assign_source_group("Include" ${GROUP_INCLUDE})
-
-# Source file lists
-# Core compiler sources, extended by the backend modules.
+endif()
+if(DEFINED TVM_VERSION)
+  add_compile_definitions(TVM_VERSION="${TVM_VERSION}")
+elseif(DEFINED SKBUILD_PROJECT_VERSION_FULL)
+  add_compile_definitions(TVM_VERSION="${SKBUILD_PROJECT_VERSION_FULL}")
+else()
+  add_compile_definitions(TVM_VERSION="0.28.dev0")
+endif()
+if(TVM_LOG_BEFORE_THROW)
+  add_compile_definitions(TVM_LOG_BEFORE_THROW=1)
+endif()
+set(TVM_LINKER_LIBS "")
+set(TVM_RUNTIME_LINKER_LIBS "")
+set(TVM_RUNTIME_BACKEND_LIBS "")
 tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
-    src/ir/*.cc
-    src/sym/*.cc
     src/te/*.cc
-    src/tirx/*.cc
     src/s_tir/*.cc
     src/topi/*.cc
     src/driver/*.cc
-    src/support/*.cc
-    # Shared printer and TVMScript IR builder. Per-dialect printer/builder 
pieces
-    # live under src/<dialect>/script/. List shared files explicitly so a 
dialect
-    # implementation cannot be silently included through a recursive glob.
-    src/script/ir_builder/base.cc
-    src/script/ir_builder/ir.cc
-    src/script/ir_builder/frame.cc
-    src/script/printer/config.cc
-    src/script/printer/doc.cc
-    src/script/printer/doc_translator.cc
-    src/script/printer/ir/call.cc
-    src/script/printer/ir/utils.cc
-    src/script/printer/ir/ir.cc
-    src/script/printer/ir/misc.cc
-    src/script/printer/ir/prim_type.cc
-    src/script/printer/ir/prim_expr.cc
-    src/script/printer/ir/stmt.cc
-    src/script/printer/printer.cc
-    src/script/printer/doc_printer.cc
-    src/script/printer/script_printer.cc
     src/relax/ir/*.cc
     src/relax/op/*.cc
     src/relax/analysis/*.cc
@@ -306,431 +170,139 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
     src/relax/op/distributed/*.cc
     src/relax/script/*.cc
     src/relax/testing/*.cc
-    )
-
-tvm_file_glob(GLOB CODEGEN_SRCS
-  src/target/*.cc
-  src/codegen/c/*.cc
-  src/codegen/*.cc
-  src/codegen/canonicalizer/*.cc
-  src/codegen/llvm/target_kind.cc
-  src/codegen/llvm/canonicalizer/*.cc
-  src/backend/cuda/codegen/*.cc
-  src/backend/cuda/op/*.cc
-  src/backend/cuda/transforms/*.cc
-  src/backend/cuda/tile/*.cc
-  src/backend/cuda/layout/*.cc
-  src/backend/hexagon/codegen/*.cc
-  src/backend/metal/codegen/*.cc
-  src/backend/metal/op/*.cc
-  src/backend/opencl/codegen/*.cc
-  src/backend/opencl/op/*.cc
-  src/backend/rocm/codegen/*.cc
-  src/backend/trn/codegen/*.cc
-  src/backend/trn/op/*.cc
-  src/backend/trn/transform/*.cc
-  src/backend/trn/layout/*.cc
-  src/backend/vulkan/codegen/target_kind.cc
-  src/backend/vulkan/codegen/vulkan_fallback_module.cc
-  src/backend/webgpu/codegen/*.cc
-    )
-
-list(APPEND COMPILER_SRCS ${CODEGEN_SRCS})
-# Core runtime sources, extended by the backend modules.
-tvm_file_glob(GLOB RUNTIME_SRCS
-  src/runtime/*.cc
-  src/runtime/rpc/minrpc/*.cc
 )
-# VM-owned runtime implementations, including external-module constant loading.
-tvm_file_glob(GLOB RUNTIME_VM_SRCS src/runtime/vm/*.cc)
-list(APPEND RUNTIME_SRCS ${RUNTIME_VM_SRCS})
-# Note: src/runtime/extra/disco/** moves to libtvm_runtime_extra.
-# Note: src/backend/*/runtime sources move to per-backend DSOs.
-set(TVM_RUNTIME_EXT_OBJS "")
 
+# VM, RPC, Disco and optional integrations remain parent runtime extensions.
+add_library(tvm_runtime_extra SHARED)
+add_library(tvm_runtime_extra_defs INTERFACE)
+target_link_libraries(tvm_runtime_extra_defs INTERFACE
+  tvm_tirx::tvm_runtime tvm_tirx::private_headers tvm_ffi::header)
+target_compile_definitions(tvm_runtime_extra_defs INTERFACE 
TVM_RUNTIME_EXTRA_EXPORTS TVM_FFI_EXPORTS)
+target_link_libraries(tvm_runtime_extra PRIVATE tvm_runtime_extra_defs)
+tvm_file_glob(GLOB _vm_sources src/runtime/vm/*.cc src/runtime/rpc/minrpc/*.cc)
+target_sources(tvm_runtime_extra PRIVATE ${_vm_sources})
 if(USE_RPC)
-  message(STATUS "Build with RPC support...")
-  tvm_file_glob(GLOB RUNTIME_RPC_SRCS src/runtime/rpc/*.cc)
-  list(APPEND RUNTIME_SRCS ${RUNTIME_RPC_SRCS})
-endif(USE_RPC)
-
-# Package runtime rules
-if(NOT USE_RTTI)
+  tvm_file_glob(GLOB _rpc_sources src/runtime/rpc/*.cc)
+  target_sources(tvm_runtime_extra PRIVATE ${_rpc_sources})
+  if(WIN32)
+    target_link_libraries(tvm_runtime_extra PRIVATE ws2_32)
+  endif()
 endif()
-
-if(INDEX_DEFAULT_I64)
-  add_definitions(-DTVM_INDEX_DEFAULT_I64=1)
+if(USE_CUDA)
+  if(NOT TARGET tvm_tirx::tvm_runtime_cuda)
+    message(FATAL_ERROR "Parent CUDA support requires a CUDA-enabled core")
+  endif()
+  find_cuda(${USE_CUDA} ${USE_CUDNN})
+  enable_language(CUDA)
+  if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
+    set(CMAKE_CUDA_ARCHITECTURES native)
+  endif()
+  include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
+  tvm_file_glob(GLOB _vm_cuda_sources src/runtime/vm/cuda/*.cc)
+  target_sources(tvm_runtime_extra PRIVATE ${_vm_cuda_sources})
 endif()
-
-if(USE_KALLOC_ALIGNMENT)
-  message(STATUS "Build Alloc alignment set to ${USE_KALLOC_ALIGNMENT}")
-  add_definitions(-DTVM_KALLOC_ALIGNMENT=${USE_KALLOC_ALIGNMENT})
-endif(USE_KALLOC_ALIGNMENT)
-
-# Caches the build.
-# Note that ccache-3.x doesn't support nvcc well, so CUDA kernels may never 
hit the cache and still
-# need to be re-compiled every time. Using ccache 4.0+ can resolve this issue.
-include(cmake/utils/CCache.cmake)
-
-include(CheckCXXCompilerFlag)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_STANDARD 20)
-set(CMAKE_CUDA_STANDARD_REQUIRED ON)
-set(CMAKE_CUDA_STANDARD 20)
-
-# Module rules
-include(cmake/modules/CUDA.cmake)
-include(cmake/modules/contrib/CLML.cmake) # Must be before OpenCL.cmake
-include(cmake/modules/OpenCL.cmake)
-include(cmake/modules/OpenMP.cmake)
-include(cmake/modules/Vulkan.cmake)
-include(cmake/modules/Metal.cmake)
-include(cmake/modules/ROCM.cmake)
-include(cmake/modules/LLVM.cmake)
+if(USE_ROCM)
+  if(NOT TARGET tvm_tirx::tvm_runtime_rocm)
+    message(FATAL_ERROR "Parent ROCm support requires a ROCm-enabled core")
+  endif()
+  find_rocm(${USE_ROCM})
+  include_directories(SYSTEM ${ROCM_INCLUDE_DIRS})
+  add_compile_definitions(__HIP_PLATFORM_HCC__=1 __HIP_PLATFORM_AMD__=1)
+endif()
+if(USE_NVTX)
+  target_compile_definitions(tvm_runtime_extra_defs INTERFACE 
TVM_NVTX_ENABLED=1)
+endif()
+include(cmake/modules/contrib/CUDA.cmake)
+include(cmake/modules/contrib/ROCM.cmake)
 include(cmake/modules/contrib/BLAS.cmake)
 include(cmake/modules/contrib/DNNL.cmake)
 include(cmake/modules/contrib/AMX.cmake)
 include(cmake/modules/contrib/CUTLASS.cmake)
+include(cmake/modules/contrib/CLML.cmake)
 include(cmake/modules/contrib/Random.cmake)
 include(cmake/modules/contrib/Sort.cmake)
-include(cmake/modules/contrib/Z3.cmake)
 include(cmake/modules/contrib/CoreML.cmake)
 include(cmake/modules/contrib/TensorRT.cmake)
 include(cmake/modules/contrib/NNAPI.cmake)
 include(cmake/modules/contrib/ExampleNPU.cmake)
 include(cmake/modules/contrib/vllm.cmake)
-include(cmake/modules/Git.cmake)
-
-include(cmake/modules/RuntimeExtra.cmake)
-add_subdirectory(3rdparty/tvm-ffi)
-include(GNUInstallDirs)
-
-if(USE_THREADS)
-  message(STATUS "Build with thread support...")
-  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
-  set(THREADS_PREFER_PTHREAD_FLAG TRUE)
-  find_package(Threads REQUIRED)
-endif()
-
-set(TVM_IS_DEBUG_BUILD OFF)
-if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL 
"RelWithDebInfo" OR CMAKE_CXX_FLAGS MATCHES "-g")
-  set(TVM_IS_DEBUG_BUILD ON)
-  set(FILE_PREFIX_MAP_FLAG "-ffile-prefix-map=..=${CMAKE_CURRENT_SOURCE_DIR}")
-  CHECK_CXX_COMPILER_FLAG("${FILE_PREFIX_MAP_FLAG}" FILE_PREFIX_MAP_SUPPORTED)
-endif()
-
-# Core runtime objects are shared by the dynamic and static libraries.
-add_library(tvm_runtime_objs OBJECT ${RUNTIME_SRCS})
-target_link_libraries(tvm_runtime_objs PUBLIC tvm_ffi_header)
-if(TVM_VISIBILITY_FLAG)
-  target_compile_options(tvm_runtime_objs PRIVATE "${TVM_VISIBILITY_FLAG}")
-endif()
-if(MSVC)
-  # Runtime objects export only runtime/FFI symbols, never compiler symbols.
-  target_compile_definitions(tvm_runtime_objs PRIVATE TVM_RUNTIME_EXPORTS 
TVM_FFI_EXPORTS)
+if(USE_CLML_GRAPH_EXECUTOR)
+  target_link_libraries(tvm_clml_objs PRIVATE tvm_tirx::tvm_runtime_opencl)
+  target_link_libraries(tvm_runtime_extra PRIVATE tvm_tirx::tvm_runtime_opencl)
 endif()
-
-# Loaded with RTLD_GLOBAL so downstream runtime modules can resolve its 
symbols.
-add_library(tvm_runtime SHARED
-  $<TARGET_OBJECTS:tvm_runtime_objs>
-  ${TVM_RUNTIME_EXT_OBJS}
-)
-target_link_libraries(tvm_runtime PUBLIC tvm_ffi_shared)
-set_property(TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS 
"${TVM_NO_UNDEFINED_SYMBOLS}")
-set_property(TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS 
"${TVM_VISIBILITY_FLAG}")
-
-# Static consumers must retain registration objects from both archives, with
-# tvm_ffi_static before tvm_runtime_static so FFI type attributes initialize 
first:
-#   -Wl,--whole-archive tvm_ffi_static tvm_runtime_static 
-Wl,--no-whole-archive
-# Use the corresponding archive-retention flags on other platforms.
-add_library(tvm_runtime_static STATIC
-  $<TARGET_OBJECTS:tvm_runtime_objs>
-  ${TVM_RUNTIME_EXT_OBJS}
-)
-target_link_libraries(tvm_runtime_static PUBLIC tvm_ffi_static)
-if(MSVC)
-  # Static consumers reference ordinary symbols rather than DLL import stubs.
-  target_compile_definitions(tvm_runtime_static INTERFACE
-    TVM_RUNTIME_DLL= TVM_RUNTIME_DLL_EXPORT= TVM_FFI_DLL= TVM_FFI_DLL_EXPORT=)
-endif()
-
-foreach(runtime_target tvm_runtime tvm_runtime_static)
-  target_include_directories(${runtime_target} PUBLIC 
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
-  target_link_libraries(${runtime_target} PRIVATE ${TVM_RUNTIME_LINKER_LIBS})
-  if(USE_THREADS)
-    target_link_libraries(${runtime_target} PUBLIC Threads::Threads)
+# Retain the upstream runtime-extra assembly module and its target composition.
+include(cmake/modules/RuntimeExtra.cmake)
+target_link_libraries(tvm_runtime_extra PRIVATE ${TVM_RUNTIME_LINKER_LIBS} 
${CMAKE_DL_LIBS})
+add_library(tvm_compiler SHARED ${COMPILER_SRCS})
+target_compile_definitions(tvm_compiler PRIVATE TVM_EXPORTS TVM_FFI_EXPORTS)
+target_link_libraries(tvm_compiler PUBLIC tvm_tirx::tvm_tirx tvm_runtime_extra)
+target_link_libraries(tvm_compiler PRIVATE tvm_tirx::private_headers 
${TVM_LINKER_LIBS})
+foreach(_target tvm_compiler tvm_runtime_extra)
+  target_include_directories(${_target} PUBLIC
+    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+  target_link_options(${_target} PRIVATE ${TVM_NO_UNDEFINED_SYMBOLS})
+  set_target_properties(${_target} PROPERTIES
+    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
+  if(MSVC)
+    foreach(_config RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
+      set_target_properties(${_target} PROPERTIES
+        LIBRARY_OUTPUT_DIRECTORY_${_config} "${CMAKE_BINARY_DIR}/lib"
+        ARCHIVE_OUTPUT_DIRECTORY_${_config} "${CMAKE_BINARY_DIR}/lib"
+        RUNTIME_OUTPUT_DIRECTORY_${_config} "${CMAKE_BINARY_DIR}/lib")
+    endforeach()
+  endif()
+  tvm_configure_target_library(${_target})
+  if(APPLE)
+    set_property(TARGET ${_target} APPEND PROPERTY INSTALL_RPATH 
"@loader_path/../../tvm_tirx/lib")
+  elseif(UNIX)
+    set_property(TARGET ${_target} APPEND PROPERTY INSTALL_RPATH 
"\$ORIGIN/../../tvm_tirx/lib")
   endif()
+  tvm_ffi_add_apple_dsymutil(${_target})
 endforeach()
-
-set_target_properties(tvm_runtime tvm_runtime_static PROPERTIES
-  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
-  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
-  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
-)
-if(MSVC)
-  foreach(config_type Release RELEASE Debug DEBUG RelWithDebInfo 
RELWITHDEBINFO MinSizeRel MINSIZEREL)
-    set_target_properties(tvm_runtime tvm_runtime_static PROPERTIES
-      ARCHIVE_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
-      LIBRARY_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
-      RUNTIME_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
-    )
-  endforeach()
-endif()
-
-if(TVM_IS_DEBUG_BUILD AND FILE_PREFIX_MAP_SUPPORTED)
-  target_compile_options(tvm_runtime PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
-  target_compile_options(tvm_runtime_objs PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
-endif()
-
-tvm_ffi_add_apple_dsymutil(tvm_runtime)
-tvm_configure_target_library(tvm_runtime)
-add_custom_target(runtime DEPENDS tvm_runtime tvm_runtime_static)
-install(TARGETS tvm_runtime DESTINATION lib${LIB_SUFFIX})
-# Keep wheel contents unchanged; the archive is available to native consumers.
-if(NOT TVM_BUILD_PYTHON_MODULE)
-  install(TARGETS tvm_runtime_static DESTINATION lib${LIB_SUFFIX})
-endif()
-add_library(tvm_objs OBJECT ${COMPILER_SRCS})
-target_link_libraries(tvm_objs PUBLIC tvm_ffi_header)
-if(TARGET tvm_llvm_header)
-  target_link_libraries(tvm_objs PUBLIC tvm_llvm_header)
-endif()
-if(TVM_VISIBILITY_FLAG)
-  target_compile_options(tvm_objs PRIVATE "${TVM_VISIBILITY_FLAG}")
-endif()
-if(MSVC)
-  # Compiler objects import runtime symbols from the separate runtime DLL.
-  target_compile_definitions(tvm_objs PRIVATE TVM_EXPORTS TVM_FFI_EXPORTS)
-endif()
-
-# Compiler library: built from compiler-only sources.
-# Links against tvm_runtime (and tvm_ffi_shared transitively). Loaded with
-# RTLD_LOCAL so compiler-internal symbols don't leak into the global namespace.
-add_library(tvm_compiler SHARED
-  $<TARGET_OBJECTS:tvm_objs>
-)
-target_link_libraries(tvm_compiler PUBLIC tvm_runtime tvm_ffi_shared)
-target_include_directories(tvm_compiler PUBLIC 
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
-set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"${TVM_NO_UNDEFINED_SYMBOLS}")
-set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"${TVM_VISIBILITY_FLAG}")
-
-# Work around a GNU ld (binutils) relaxation bug that miscompiles
-# R_X86_64_GOTPCRELX relocations inside very large statically-linked archives.
-# When the full LLVM static libraries are linked into libtvm_compiler.so, the
-# library is large enough that ld can relax an indirect GOT call (LLVM built
-# with -fno-plt emits these) into a direct call with an incorrect displacement.
-# The call then targets read-only data instead of the intended function and
-# crashes at runtime with a SIGSEGV inside llvm::X86Subtarget during code
-# generation. Disabling linker relaxation keeps the GOT-indirect sequences and
-# avoids the miscompilation; it is harmless when LLVM is linked dynamically.
-# See binutils bug ld/25754.
-if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT "${USE_LLVM}" MATCHES 
${IS_FALSE_PATTERN})
-  set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"-Wl,--no-relax")
-  # LLVM's --system-libs reports -lxml2, but TVM calls no libxml2 symbols. The
-  # manylinux toolchain does not default to --as-needed, so set it explicitly:
-  # the unused libxml2 is then not recorded as a NEEDED dependency, so 
auditwheel
-  # does not vendor it (and its deps) into the wheel.
-  set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"-Wl,--as-needed")
-endif()
-
-set_target_properties(tvm_compiler PROPERTIES
-  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
-  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
-  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
-)
-if(MSVC)
-  foreach(config_type Release RELEASE Debug DEBUG RelWithDebInfo 
RELWITHDEBINFO MinSizeRel MINSIZEREL)
-    set_target_properties(tvm_compiler PROPERTIES
-      ARCHIVE_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
-      LIBRARY_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
-      RUNTIME_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
-    )
-  endforeach()
+add_subdirectory(tests/cpp)
+if(GTEST_FOUND)
+  enable_testing()
+  include(CTest)
 endif()
-
-if(USE_THREADS)
-  target_link_libraries(tvm_compiler PUBLIC Threads::Threads)
+if(TARGET cpptest AND TARGET tirx_cpptest)
+  add_dependencies(cpptest tirx_cpptest)
 endif()
-target_link_libraries(tvm_compiler PRIVATE ${TVM_LINKER_LIBS} 
${TVM_RUNTIME_LINKER_LIBS})
-
-if(TVM_IS_DEBUG_BUILD)
-  target_compile_options(tvm_compiler PRIVATE "${FILE_PREFIX_MAP_FLAG}")
-  if(FILE_PREFIX_MAP_SUPPORTED)
-    target_compile_options(tvm_compiler PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
-    target_compile_options(tvm_objs PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
+add_custom_target(runtime DEPENDS tvm_runtime_extra)
+add_dependencies(runtime tvm_tirx::tvm_runtime)
+set(TVM_RUNTIME_BACKEND_LIBS tvm_runtime_extra)
+foreach(_backend cuda opencl vulkan metal rocm)
+  if(TARGET tvm_tirx::tvm_runtime_${_backend})
+    list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_tirx::tvm_runtime_${_backend})
   endif()
-endif()
-
-tvm_ffi_add_apple_dsymutil(tvm_compiler)
-tvm_configure_target_library(tvm_compiler)
-install(TARGETS tvm_compiler DESTINATION lib${LIB_SUFFIX})
-
-# logging option for libbacktrace
-include(cmake/modules/Logging.cmake)
-
+endforeach()
 if(USE_CPP_RPC)
-  add_subdirectory("apps/cpp_rpc")
+  add_subdirectory(apps/cpp_rpc)
 endif()
-
 if(USE_CPP_RTVM)
-  add_subdirectory("apps/cpp_rtvm")
+  add_subdirectory(apps/cpp_rtvm)
 endif()
-
 if(USE_IOS_RPC)
-  add_subdirectory("apps/ios_rpc")
-endif()
-
-# Set flags for clang
-include(cmake/modules/ClangFlags.cmake)
-# Installation rules
-if (INSTALL_DEV)
-  install(
-    DIRECTORY "include/" DESTINATION "include"
-    FILES_MATCHING
-    PATTERN "*.h"
-  )
-else(INSTALL_DEV)
-  install(
-    DIRECTORY "include/tvm/runtime" "include/tvm/support" DESTINATION 
"include/tvm"
-    FILES_MATCHING
-    PATTERN "*.h"
-    )
-endif(INSTALL_DEV)
-
-include(CMakePackageConfigHelpers)
-set(PROJECT_CONFIG_CONTENT "@PACKAGE_INIT@\n")
-string(APPEND PROJECT_CONFIG_CONTENT "include(CMakeFindDependencyMacro)\n")
-string(APPEND PROJECT_CONFIG_CONTENT "find_dependency(Threads REQUIRED)\n")
-string(APPEND PROJECT_CONFIG_CONTENT
-       "include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")")
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/temp_config_file.cmake" 
${PROJECT_CONFIG_CONTENT})
-
-# install(EXPORT ${PROJECT_NAME}Targets
-#   NAMESPACE ${PROJECT_NAME}::
-#   DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
-
-# Create config for find_package()
-configure_package_config_file(
-  "${CMAKE_CURRENT_BINARY_DIR}/temp_config_file.cmake" 
${PROJECT_NAME}Config.cmake
-  INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
-
-install(
-  FILES
-  "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
-  DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
-
-find_and_set_linker(${USE_ALTERNATIVE_LINKER})
-
-if(${SUMMARIZE})
-  print_summary()
-endif()
-
-dump_options_to_file("${TVM_ALL_OPTIONS}")
-
-if(USE_CUDA AND USE_CUTLASS)
-  install(TARGETS fpA_intB_gemm EXPORT ${PROJECT_NAME}Targets DESTINATION 
lib${LIB_SUFFIX})
-  install(TARGETS flash_attn EXPORT ${PROJECT_NAME}Targets DESTINATION 
lib${LIB_SUFFIX})
-  # fpA_intB_gemm, fpA_intB_gemm_tvm, and flash_attn are linked by
-  # tvm_runtime_extra (see RuntimeExtra.cmake); no link needed here.
-endif()
-
-if(USE_CUDA AND USE_NVTX)
-  add_compile_definitions(TVM_NVTX_ENABLED=1)
+  add_subdirectory(apps/ios_rpc)
 endif()
-
-# Tests inherit the final project linker flags and compile definitions.
-add_subdirectory(tests/cpp)
-if(GTEST_FOUND)
-  # CTest must also be enabled at the project root for subdirectory discovery.
-  enable_testing()
-  include(CTest)
-endif()
-
-# Python package installation configuration
-# This section ensures that all necessary files are installed for the Python 
wheel
+install(TARGETS tvm_compiler tvm_runtime_extra
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 
FILES_MATCHING PATTERN "*.h")
+# Parent minRPC compilation retains its own source and private header closure.
+install(DIRECTORY src/runtime/rpc/ DESTINATION src/runtime/rpc FILES_MATCHING 
PATTERN "*.h" PATTERN "*.cc")
+install(DIRECTORY src/support/ DESTINATION src/support FILES_MATCHING PATTERN 
"*.h")
+install(DIRECTORY src/runtime/extra/ DESTINATION src/runtime/extra 
FILES_MATCHING PATTERN "*.h" PATTERN "*.cuh")
 if(TVM_BUILD_PYTHON_MODULE)
-  message(STATUS "Configuring Python package installation")
-
-  # Install compiled shared libraries into <project>/lib so that
-  # tvm_ffi.libinfo.load_lib_ctypes(package="tvm", target_name=...) can find
-  # them via the package RECORD or the project's lib/ fallback dir.
-  install(TARGETS tvm_compiler DESTINATION "lib")
-  install(TARGETS tvm_runtime DESTINATION "lib")
-
-  # Install third-party compiled dependencies into the same lib/ dir.
-  if(TARGET fpA_intB_gemm)
-    tvm_configure_target_library(fpA_intB_gemm)
-    install(TARGETS fpA_intB_gemm DESTINATION "lib")
-  endif()
-  if(TARGET flash_attn)
-    tvm_configure_target_library(flash_attn)
-    install(TARGETS flash_attn DESTINATION "lib")
-  endif()
-
-  # Install prebuilt extra runtime libraries into the same lib/ dir. This is 
how
-  # the separately-built CUDA runtime (libtvm_runtime_cuda.so) is bundled: the
-  # publishing flow builds it in a CUDA-enabled environment and passes its path
-  # via TVM_PACKAGE_EXTRA_LIBS, so it ships through the normal CMake install
-  # rather than a post-build wheel rewrite.
-  foreach(_extra_lib IN LISTS TVM_PACKAGE_EXTRA_LIBS)
-    if(NOT EXISTS "${_extra_lib}")
-      message(FATAL_ERROR "TVM_PACKAGE_EXTRA_LIBS entry does not exist: 
${_extra_lib}")
-    endif()
-    install(FILES "${_extra_lib}" DESTINATION "lib")
-  endforeach()
-
-  # Install minimal header files needed by Python extensions
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/tvm/runtime/"
-    DESTINATION "include/tvm/runtime/"
-    FILES_MATCHING
-    PATTERN "*.h"
-  )
-
-  # Install minimal CMake configuration
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/"
-    DESTINATION "cmake/utils/"
-    FILES_MATCHING
-    PATTERN "*.cmake"
-  )
-
-  # Install CUTLASS headers only if available
+  install(DIRECTORY web/ DESTINATION web)
+  install(DIRECTORY licenses/ DESTINATION licenses)
+  install(FILES LICENSE NOTICE DESTINATION .)
   if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cutlass/include")
-    install(
-      DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cutlass/include/"
-      DESTINATION "3rdparty/cutlass/include/"
-      FILES_MATCHING
-      PATTERN "*.h"
-      PATTERN "*.hpp"
-    )
+    install(DIRECTORY 3rdparty/cutlass/include/ DESTINATION 
3rdparty/cutlass/include
+      FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
   endif()
-
-  # Install minimal source files
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/"
-    DESTINATION "src/runtime/"
-    FILES_MATCHING
-    PATTERN "*.cc"
-    PATTERN "*.h"
-  )
-
-  # Install web package
-  install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/web/" DESTINATION "web/")
-
-  # Install licenses (required for distribution)
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/licenses/"
-    DESTINATION "licenses/"
-  )
-
-  # Install essential metadata files
-  install(FILES
-    "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
-    "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
-    "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE"
-    DESTINATION "."
-  )
-
-  message(STATUS "Python package installation configured")
 endif()
+find_and_set_linker(${USE_ALTERNATIVE_LINKER})
diff --git a/tirx/cmake/modules/CUDA.cmake b/cmake/modules/contrib/CUDA.cmake
similarity index 56%
copy from tirx/cmake/modules/CUDA.cmake
copy to cmake/modules/contrib/CUDA.cmake
index 4e2cdd508c..c4f6d68791 100644
--- a/tirx/cmake/modules/CUDA.cmake
+++ b/cmake/modules/contrib/CUDA.cmake
@@ -15,84 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# CUDA Module
-find_cuda(${USE_CUDA} ${USE_CUDNN})
-
-if(CUDA_FOUND)
-  # always set the includedir when CUDA is available
-  # avoid global retrigger of CMake
-  include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
-endif(CUDA_FOUND)
-
-if(USE_CUDA)
-  if(NOT CUDA_FOUND)
-    message(FATAL_ERROR "Cannot find CUDA, USE_CUDA=" ${USE_CUDA})
-  endif()
-  message(STATUS "Build with CUDA ${CUDA_VERSION} support")
-  enable_language(CUDA)
-
-  # Ensure that include directives to NVCC are in the
-  # `compile_commands.json`, as required by clangd.
-  #
-  # As of CMake 3.29.5 [0], if the NVCC version is 11 or higher, CMake
-  # will generate a "options-file.rsp" containing the -I flags for
-  # include directories, rather than providing them on the
-  # command-line.  This setting exists to work around the short
-  # command-line length limits on Windows, but is enabled on all
-  # platforms.  If set, because include directories are not part of
-  # the `compile_commands.json`, the clangd LSP cannot find the
-  # include files.
-  #
-  # Furthermore, this override cannot be specified in a user's
-  # `config.cmake` for TVM, because it must be set after CMake's
-  # built-in CUDA support.
-  #
-  # [0] https://github.com/Kitware/CMake/commit/6377a438
-  set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
-
-  if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
-    if(CMAKE_VERSION VERSION_LESS "3.24")
-      message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES not set. Please upgrade 
CMake to 3.24 to use native, or set CMAKE_CUDA_ARCHITECTURES manually")
-    endif()
-    message(STATUS "CMAKE_CUDA_ARCHITECTURES not set, using native")
-    set(CMAKE_CUDA_ARCHITECTURES native)
-  endif()
-endif(USE_CUDA)
-
-if(USE_CUDA)
-  message(STATUS "Build cuda device runtime")
-
-  # tvm_runtime_cuda links libcuda; without it the .so silently drops its
-  # libcuda.so.1 dependency, so fail configure instead.
-  if(NOT CUDA_CUDA_LIBRARY)
-    message(FATAL_ERROR "USE_CUDA is on but libcuda was not found. "
-      "Set -DCUDA_CUDA_LIBRARY=<path to libcuda.so> or make the driver stub 
discoverable.")
-  endif()
-
-  tvm_file_glob(GLOB RUNTIME_CUDA_SRCS src/backend/cuda/runtime/*.cc)
-  tvm_file_glob(GLOB VM_CUDA_BUILTIN_SRC_CC src/runtime/vm/cuda/*.cc)
-
-  add_library(tvm_runtime_cuda_objs OBJECT ${RUNTIME_CUDA_SRCS} 
${VM_CUDA_BUILTIN_SRC_CC})
-  target_link_libraries(tvm_runtime_cuda_objs PUBLIC tvm_ffi_header)
-  # These sources compile into tvm_runtime_cuda.dll, so their TVM_RUNTIME_DLL /
-  # TVM_FFI_DLL symbols must be dllexport on MSVC (e.g. GetCudaDeviceCount in
-  # cuda_device_api.cc). Mirror tvm_runtime_objs; a no-op on non-MSVC 
platforms.
-  target_compile_definitions(tvm_runtime_cuda_objs PRIVATE TVM_RUNTIME_EXPORTS 
TVM_FFI_EXPORTS)
-  set_target_properties(tvm_runtime_cuda_objs PROPERTIES 
POSITION_INDEPENDENT_CODE ON)
-  if(TVM_VISIBILITY_FLAG)
-    target_compile_options(tvm_runtime_cuda_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
-  endif()
-  add_library(tvm_runtime_cuda SHARED $<TARGET_OBJECTS:tvm_runtime_cuda_objs>)
-  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_cuda)
-  target_link_libraries(tvm_runtime_cuda PUBLIC tvm_runtime PRIVATE 
${CUDA_CUDART_LIBRARY} ${CUDA_CUDA_LIBRARY})
-  tvm_configure_target_library(tvm_runtime_cuda RUNTIME_MODULE)
-
-  if(USE_NVTX)
-    message(STATUS "Build with NVTX support")
-    target_link_libraries(tvm_runtime_cuda PRIVATE ${CUDA_NVTX_LIBRARY})
-  endif()
-endif(USE_CUDA)
-
 # Contrib sources gated by USE_CUDA go into libtvm_runtime_extra.
 # See the RuntimeExtra assembly block in CMakeLists.txt.
 
diff --git a/tirx/cmake/modules/ROCM.cmake b/cmake/modules/contrib/ROCM.cmake
similarity index 64%
copy from tirx/cmake/modules/ROCM.cmake
copy to cmake/modules/contrib/ROCM.cmake
index 33abc75a2b..37ee066099 100644
--- a/tirx/cmake/modules/ROCM.cmake
+++ b/cmake/modules/contrib/ROCM.cmake
@@ -15,42 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# ROCM Module
-find_rocm(${USE_ROCM})
-
-if(ROCM_FOUND)
-  # always set the includedir
-  # avoid global retrigger of CMake
-  include_directories(SYSTEM ${ROCM_INCLUDE_DIRS})
-  add_definitions(-D__HIP_PLATFORM_HCC__=1)
-  add_definitions(-D__HIP_PLATFORM_AMD__=1)
-endif(ROCM_FOUND)
-
-if(USE_ROCM)
-  if(NOT ROCM_FOUND)
-    message(FATAL_ERROR "Cannot find ROCM, USE_ROCM=" ${USE_ROCM})
-  endif()
-  message(STATUS "Build rocm device runtime")
-
-  tvm_file_glob(GLOB RUNTIME_ROCM_SRCS src/backend/rocm/runtime/*.cc)
-
-  set(_rocm_libs ${ROCM_HIPHCC_LIBRARY})
-  if(ROCM_HSA_LIBRARY)
-    list(APPEND _rocm_libs ${ROCM_HSA_LIBRARY})
-  endif()
-
-  add_library(tvm_runtime_rocm_objs OBJECT ${RUNTIME_ROCM_SRCS})
-  target_link_libraries(tvm_runtime_rocm_objs PUBLIC tvm_ffi_header)
-  set_target_properties(tvm_runtime_rocm_objs PROPERTIES 
POSITION_INDEPENDENT_CODE ON)
-  if(TVM_VISIBILITY_FLAG)
-    target_compile_options(tvm_runtime_rocm_objs PRIVATE 
"${TVM_VISIBILITY_FLAG}")
-  endif()
-  add_library(tvm_runtime_rocm SHARED $<TARGET_OBJECTS:tvm_runtime_rocm_objs>)
-  list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_rocm)
-  target_link_libraries(tvm_runtime_rocm PUBLIC tvm_runtime PRIVATE 
${_rocm_libs})
-  tvm_configure_target_library(tvm_runtime_rocm RUNTIME_MODULE)
-endif(USE_ROCM)
-
 # HIPBLAS contrib goes into libtvm_runtime_extra.
 if(USE_ROCM AND USE_HIPBLAS)
   message(STATUS "Build with HIPBLAS support")
diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt
index 35c9fadb9e..45be2dee75 100644
--- a/tests/cpp/CMakeLists.txt
+++ b/tests/cpp/CMakeLists.txt
@@ -16,7 +16,7 @@
 # under the License.
 
 # Enable ctest if gtest is available
-if(USE_GTEST)
+if(USE_GTEST AND NOT BUILD_TESTING STREQUAL "OFF")
   # Check env var for backward compatibility. A better way to specify package
   # locations is to use CMAKE_PREFIX_PATH or other standard CMake mechanism
   # (see CMake documentation for `find_package`).
diff --git a/CMakeLists.txt b/tirx/CMakeLists.txt
similarity index 57%
copy from CMakeLists.txt
copy to tirx/CMakeLists.txt
index bfa62d6b9d..0b508905ee 100644
--- a/CMakeLists.txt
+++ b/tirx/CMakeLists.txt
@@ -1,32 +1,42 @@
-cmake_minimum_required(VERSION 3.18)
-project(tvm C CXX)
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 
-# --- TVM version (no dependency on version.py) ---
-# When built via scikit-build-core the version is resolved by setuptools_scm 
and
-# passed in as SKBUILD_PROJECT_VERSION_FULL; bake it into the C++ TVM_VERSION 
macro.
-# A bare `cmake` build (no scikit-build-core) leaves the checked-in default in
-# include/tvm/runtime/base.h untouched. An explicit -DTVM_VERSION always wins.
-if(NOT DEFINED TVM_VERSION AND DEFINED SKBUILD_PROJECT_VERSION_FULL)
-  set(TVM_VERSION "${SKBUILD_PROJECT_VERSION_FULL}")
-endif()
-if(DEFINED TVM_VERSION)
-  message(STATUS "TVM_VERSION=${TVM_VERSION}")
-  add_compile_definitions(TVM_VERSION="${TVM_VERSION}")
+cmake_minimum_required(VERSION 3.18)
+project(tvm_tirx C CXX)
+include(GNUInstallDirs)
+if(TVM_BUILD_PYTHON_MODULE)
+  set(CMAKE_INSTALL_LIBDIR lib)
 endif()
 
+# The extracted package has an independent version; parent SCM tags do not 
apply.
+set(TVM_TIRX_VERSION "0.1.0a0")
+set(TVM_VERSION "${TVM_TIRX_VERSION}")
+add_compile_definitions(TVM_VERSION="${TVM_VERSION}")
+
 # Utility functions
-include(cmake/utils/Utils.cmake)
-include(cmake/utils/Summary.cmake)
-include(cmake/utils/Linker.cmake)
-include(cmake/utils/Library.cmake)
-include(cmake/utils/FindCUDA.cmake)
-include(cmake/utils/FindNCCL.cmake)
-include(cmake/utils/FindOpenCL.cmake)
-include(cmake/utils/FindVulkan.cmake)
-include(cmake/utils/FindLLVM.cmake)
-include(cmake/utils/FindROCM.cmake)
-include(cmake/utils/FindRCCL.cmake)
-include(cmake/utils/FindNVSHMEM.cmake)
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/Utils.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/Summary.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/Linker.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/Library.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/FindCUDA.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/FindOpenCL.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/FindVulkan.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/FindLLVM.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/FindROCM.cmake")
 
 if(EXISTS ${CMAKE_BINARY_DIR}/config.cmake)
   include(${CMAKE_BINARY_DIR}/config.cmake)
@@ -41,7 +51,6 @@ endif()
 # and add set(OPTION VALUE) to override these build options.
 # Alernatively, use cmake -DOPTION=VALUE through command-line.
 tvm_option(USE_CUDA "Build with CUDA" OFF)
-tvm_option(USE_NCCL "Build with NCCL" OFF)
 tvm_option(USE_OPENCL "Build with OpenCL" OFF)
 tvm_option(USE_OPENCL_ENABLE_HOST_PTR "Enable OpenCL memory object access to 
host" OFF)
 tvm_option(USE_OPENCL_GTEST "Path to OpenCL specific gtest version for runtime 
cpp tests." /path/to/opencl/gtest)
@@ -58,11 +67,9 @@ tvm_option(USE_KHRONOS_SPIRV "Whether to use spirv-tools and 
SPIRV-Headers from
 tvm_option(USE_SPIRV_KHR_INTEGER_DOT_PRODUCT "whether enable 
SPIRV_KHR_DOT_PRODUCT" OFF)
 tvm_option(USE_METAL "Build with Metal" OFF)
 tvm_option(USE_ROCM "Build with ROCM" OFF)
-tvm_option(USE_RCCL "Build with RCCL" OFF)
 tvm_option(ROCM_PATH "The path to rocm" /opt/rocm)
 tvm_option(USE_HEXAGON_QHL "Enable Hexagon QHL compiler lowering (requires 
external runtime wrappers)" OFF)
 
-tvm_option(USE_RPC "Build with RPC" ON)
 tvm_option(USE_THREADS "Build with thread support" ON)
 tvm_option(USE_LLVM "Build with LLVM, can be set to specific llvm-config path" 
OFF)
 tvm_option(USE_OPENMP "Build with OpenMP thread pool implementation" OFF)
@@ -78,35 +85,11 @@ tvm_option(USE_ALTERNATIVE_LINKER "Use 'mold' or 'lld' if 
found when invoking co
 tvm_option(USE_CCACHE "Use ccache if found when invoking compiler" AUTO)
 
 # 3rdparty libraries
-tvm_option(COMPILER_RT_PATH "Path to COMPILER-RT" "3rdparty/compiler-rt")
+tvm_option(COMPILER_RT_PATH "Path to COMPILER-RT" 
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/compiler-rt")
 # Contrib library options
-tvm_option(USE_BLAS "The blas library to be linked" none)
-tvm_option(USE_AMX "Enable Intel AMX" OFF)
 tvm_option(USE_Z3 "Build with Z3 SMT solver support" AUTO)
-tvm_option(USE_MKL "MKL root path when use MKL blas" OFF)
-tvm_option(USE_DNNL "Enable DNNL codegen" OFF)
-tvm_option(USE_CUDNN "Build with cuDNN" OFF)
-tvm_option(USE_CUBLAS "Build with cuBLAS" OFF)
 tvm_option(USE_NVTX "Build with NVTX" OFF)
-tvm_option(USE_CUTLASS "Build with CUTLASS" OFF)
-tvm_option(USE_THRUST "Build with Thrust" OFF)
-tvm_option(USE_CURAND "Build with cuRAND" OFF)
-tvm_option(USE_HIPBLAS "Build with ROCM:HIPBLAS" OFF)
-tvm_option(USE_SORT "Build with sort support" ON)
-tvm_option(USE_RANDOM "Build with random support" ON)
-tvm_option(USE_CPP_RPC "Build CPP RPC" OFF)
-tvm_option(USE_IOS_RPC "Build iOS RPC" OFF)
-tvm_option(USE_COREML "Build with coreml support" OFF)
-tvm_option(USE_TENSORRT_CODEGEN "Build with TensorRT Codegen support" OFF)
-tvm_option(USE_TENSORRT_RUNTIME "Build with TensorRT runtime" OFF)
-tvm_option(USE_NNAPI_CODEGEN "Build with NNAPI Codegen support" OFF)
-tvm_option(USE_NNAPI_RUNTIME "Build with NNAPI runtime" OFF)
-tvm_option(USE_EXAMPLE_NPU_CODEGEN "Build with Example NPU Codegen support" 
OFF)
-tvm_option(USE_EXAMPLE_NPU_RUNTIME "Build with Example NPU runtime" OFF)
 tvm_option(SUMMARIZE "Print CMake option summary after configuring" OFF)
-tvm_option(USE_CLML "Build with CLML Codegen support" OFF)
-tvm_option(USE_CLML_GRAPH_EXECUTOR "Build with CLML graph runtime" OFF)
-tvm_option(USE_NVSHMEM "Build with NVSHMEM support" OFF)
 
 # Python package options
 tvm_option(TVM_BUILD_PYTHON_MODULE "Build Python module with 
scikit-build-core" OFF)
@@ -120,19 +103,24 @@ include_directories(SYSTEM ${COMPILER_RT_PATH})
 set(TVM_LINKER_LIBS "")
 set(TVM_RUNTIME_LINKER_LIBS "")
 set(TVM_RUNTIME_BACKEND_LIBS "")
-# Early target creation so contrib cmake files can call
-# target_link_libraries(tvm_runtime_extra PRIVATE <object_lib>) directly.
-add_library(tvm_runtime_extra SHARED)
-list(APPEND TVM_RUNTIME_BACKEND_LIBS tvm_runtime_extra)
-set_target_properties(tvm_runtime_extra PROPERTIES LINKER_LANGUAGE CXX)
-# INTERFACE target carrying compile definitions for OBJECT libs that build
-# into tvm_runtime_extra. On MSVC, TVM_RUNTIME_EXTRA_EXPORTS exports 
extra-owned
-# APIs while core-runtime APIs remain imports from tvm_runtime.dll.
-add_library(tvm_runtime_extra_defs INTERFACE)
-target_link_libraries(tvm_runtime_extra_defs INTERFACE tvm_ffi_header)
-target_compile_definitions(tvm_runtime_extra_defs
-  INTERFACE TVM_RUNTIME_EXTRA_EXPORTS TVM_FFI_EXPORTS)
-
+# Use one external FFI registry for both the core and its parent consumers.
+find_package(Python COMPONENTS Interpreter REQUIRED)
+if(NOT tvm_ffi_DIR)
+  execute_process(COMMAND "${Python_EXECUTABLE}" -m tvm_ffi.config --cmakedir
+    OUTPUT_VARIABLE tvm_ffi_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
+    COMMAND_ERROR_IS_FATAL ANY)
+endif()
+if(NOT TARGET tvm_ffi::shared)
+  find_package(tvm_ffi CONFIG REQUIRED)
+  foreach(_ffi_target header shared static)
+    if(TARGET tvm_ffi::${_ffi_target})
+      set_target_properties(tvm_ffi::${_ffi_target} PROPERTIES IMPORTED_GLOBAL 
TRUE)
+    endif()
+  endforeach()
+endif()
+if(NOT TARGET tvm_ffi_header)
+  add_library(tvm_ffi_header ALIAS tvm_ffi::header)
+endif()
 
 # Check if this is being run on its own or as a subdirectory for another 
project
 # If we update to CMake 2.21+, we can use PROJECT_IS_TOP_LEVEL instead
@@ -267,11 +255,7 @@ assign_source_group("Include" ${GROUP_INCLUDE})
 tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
     src/ir/*.cc
     src/sym/*.cc
-    src/te/*.cc
     src/tirx/*.cc
-    src/s_tir/*.cc
-    src/topi/*.cc
-    src/driver/*.cc
     src/support/*.cc
     # Shared printer and TVMScript IR builder. Per-dialect printer/builder 
pieces
     # live under src/<dialect>/script/. List shared files explicitly so a 
dialect
@@ -292,20 +276,6 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
     src/script/printer/printer.cc
     src/script/printer/doc_printer.cc
     src/script/printer/script_printer.cc
-    src/relax/ir/*.cc
-    src/relax/op/*.cc
-    src/relax/analysis/*.cc
-    src/relax/transform/*.cc
-    src/relax/backend/vm/*.cc
-    src/relax/backend/adreno/*.cc
-    src/relax/backend/task_extraction.cc
-    src/relax/backend/pattern_registry.cc
-    src/relax/utils.cc
-    src/relax/distributed/*.cc
-    src/relax/distributed/transform/*.cc
-    src/relax/op/distributed/*.cc
-    src/relax/script/*.cc
-    src/relax/testing/*.cc
     )
 
 tvm_file_glob(GLOB CODEGEN_SRCS
@@ -339,21 +309,9 @@ list(APPEND COMPILER_SRCS ${CODEGEN_SRCS})
 # Core runtime sources, extended by the backend modules.
 tvm_file_glob(GLOB RUNTIME_SRCS
   src/runtime/*.cc
-  src/runtime/rpc/minrpc/*.cc
 )
-# VM-owned runtime implementations, including external-module constant loading.
-tvm_file_glob(GLOB RUNTIME_VM_SRCS src/runtime/vm/*.cc)
-list(APPEND RUNTIME_SRCS ${RUNTIME_VM_SRCS})
-# Note: src/runtime/extra/disco/** moves to libtvm_runtime_extra.
-# Note: src/backend/*/runtime sources move to per-backend DSOs.
 set(TVM_RUNTIME_EXT_OBJS "")
 
-if(USE_RPC)
-  message(STATUS "Build with RPC support...")
-  tvm_file_glob(GLOB RUNTIME_RPC_SRCS src/runtime/rpc/*.cc)
-  list(APPEND RUNTIME_SRCS ${RUNTIME_RPC_SRCS})
-endif(USE_RPC)
-
 # Package runtime rules
 if(NOT USE_RTTI)
 endif()
@@ -370,7 +328,7 @@ endif(USE_KALLOC_ALIGNMENT)
 # Caches the build.
 # Note that ccache-3.x doesn't support nvcc well, so CUDA kernels may never 
hit the cache and still
 # need to be re-compiled every time. Using ccache 4.0+ can resolve this issue.
-include(cmake/utils/CCache.cmake)
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/CCache.cmake")
 
 include(CheckCXXCompilerFlag)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -379,30 +337,16 @@ set(CMAKE_CUDA_STANDARD_REQUIRED ON)
 set(CMAKE_CUDA_STANDARD 20)
 
 # Module rules
-include(cmake/modules/CUDA.cmake)
-include(cmake/modules/contrib/CLML.cmake) # Must be before OpenCL.cmake
-include(cmake/modules/OpenCL.cmake)
-include(cmake/modules/OpenMP.cmake)
-include(cmake/modules/Vulkan.cmake)
-include(cmake/modules/Metal.cmake)
-include(cmake/modules/ROCM.cmake)
-include(cmake/modules/LLVM.cmake)
-include(cmake/modules/contrib/BLAS.cmake)
-include(cmake/modules/contrib/DNNL.cmake)
-include(cmake/modules/contrib/AMX.cmake)
-include(cmake/modules/contrib/CUTLASS.cmake)
-include(cmake/modules/contrib/Random.cmake)
-include(cmake/modules/contrib/Sort.cmake)
-include(cmake/modules/contrib/Z3.cmake)
-include(cmake/modules/contrib/CoreML.cmake)
-include(cmake/modules/contrib/TensorRT.cmake)
-include(cmake/modules/contrib/NNAPI.cmake)
-include(cmake/modules/contrib/ExampleNPU.cmake)
-include(cmake/modules/contrib/vllm.cmake)
-include(cmake/modules/Git.cmake)
-
-include(cmake/modules/RuntimeExtra.cmake)
-add_subdirectory(3rdparty/tvm-ffi)
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/CUDA.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/OpenCL.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/OpenMP.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/Vulkan.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/Metal.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ROCM.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/LLVM.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/contrib/Z3.cmake")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/Git.cmake")
+
 include(GNUInstallDirs)
 
 if(USE_THREADS)
@@ -435,41 +379,50 @@ add_library(tvm_runtime SHARED
   $<TARGET_OBJECTS:tvm_runtime_objs>
   ${TVM_RUNTIME_EXT_OBJS}
 )
-target_link_libraries(tvm_runtime PUBLIC tvm_ffi_shared)
+target_link_libraries(tvm_runtime PUBLIC tvm_ffi::shared)
 set_property(TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS 
"${TVM_NO_UNDEFINED_SYMBOLS}")
 set_property(TARGET tvm_runtime APPEND PROPERTY LINK_OPTIONS 
"${TVM_VISIBILITY_FLAG}")
 
 # Static consumers must retain registration objects from both archives, with
-# tvm_ffi_static before tvm_runtime_static so FFI type attributes initialize 
first:
-#   -Wl,--whole-archive tvm_ffi_static tvm_runtime_static 
-Wl,--no-whole-archive
+# tvm_ffi::static before tvm_runtime_static so FFI type attributes initialize 
first:
+#   -Wl,--whole-archive tvm_ffi::static tvm_runtime_static 
-Wl,--no-whole-archive
 # Use the corresponding archive-retention flags on other platforms.
+set(_ffi_static_dependency tvm_ffi::shared)
+if(TARGET tvm_ffi::static)
+  set(_ffi_static_dependency tvm_ffi::static)
+endif()
 add_library(tvm_runtime_static STATIC
   $<TARGET_OBJECTS:tvm_runtime_objs>
   ${TVM_RUNTIME_EXT_OBJS}
 )
-target_link_libraries(tvm_runtime_static PUBLIC tvm_ffi_static)
+target_link_libraries(tvm_runtime_static PUBLIC ${_ffi_static_dependency})
 if(MSVC)
   # Static consumers reference ordinary symbols rather than DLL import stubs.
   target_compile_definitions(tvm_runtime_static INTERFACE
-    TVM_RUNTIME_DLL= TVM_RUNTIME_DLL_EXPORT= TVM_FFI_DLL= TVM_FFI_DLL_EXPORT=)
+    TVM_RUNTIME_DLL= TVM_RUNTIME_DLL_EXPORT=)
+  if(TARGET tvm_ffi::static)
+    target_compile_definitions(tvm_runtime_static INTERFACE TVM_FFI_DLL= 
TVM_FFI_DLL_EXPORT=)
+  endif()
 endif()
 
-foreach(runtime_target tvm_runtime tvm_runtime_static)
-  target_include_directories(${runtime_target} PUBLIC 
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+set(_runtime_targets tvm_runtime tvm_runtime_static)
+
+foreach(runtime_target IN LISTS _runtime_targets)
+  target_include_directories(${runtime_target} PUBLIC 
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" 
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
   target_link_libraries(${runtime_target} PRIVATE ${TVM_RUNTIME_LINKER_LIBS})
   if(USE_THREADS)
     target_link_libraries(${runtime_target} PUBLIC Threads::Threads)
   endif()
 endforeach()
 
-set_target_properties(tvm_runtime tvm_runtime_static PROPERTIES
+set_target_properties(${_runtime_targets} PROPERTIES
   ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
   LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
   RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
 )
 if(MSVC)
   foreach(config_type Release RELEASE Debug DEBUG RelWithDebInfo 
RELWITHDEBINFO MinSizeRel MINSIZEREL)
-    set_target_properties(tvm_runtime tvm_runtime_static PROPERTIES
+    set_target_properties(${_runtime_targets} PROPERTIES
       ARCHIVE_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
       LIBRARY_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
       RUNTIME_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
@@ -484,39 +437,41 @@ endif()
 
 tvm_ffi_add_apple_dsymutil(tvm_runtime)
 tvm_configure_target_library(tvm_runtime)
-add_custom_target(runtime DEPENDS tvm_runtime tvm_runtime_static)
+if(NOT IS_SUBPROJECT)
+  add_custom_target(runtime DEPENDS ${_runtime_targets})
+endif()
 install(TARGETS tvm_runtime DESTINATION lib${LIB_SUFFIX})
 # Keep wheel contents unchanged; the archive is available to native consumers.
-if(NOT TVM_BUILD_PYTHON_MODULE)
+if(TARGET tvm_runtime_static AND NOT TVM_BUILD_PYTHON_MODULE)
   install(TARGETS tvm_runtime_static DESTINATION lib${LIB_SUFFIX})
 endif()
-add_library(tvm_objs OBJECT ${COMPILER_SRCS})
-target_link_libraries(tvm_objs PUBLIC tvm_ffi_header)
+add_library(tvm_tirx_objs OBJECT ${COMPILER_SRCS})
+target_link_libraries(tvm_tirx_objs PUBLIC tvm_ffi_header)
 if(TARGET tvm_llvm_header)
-  target_link_libraries(tvm_objs PUBLIC tvm_llvm_header)
+  target_link_libraries(tvm_tirx_objs PUBLIC tvm_llvm_header)
 endif()
 if(TVM_VISIBILITY_FLAG)
-  target_compile_options(tvm_objs PRIVATE "${TVM_VISIBILITY_FLAG}")
+  target_compile_options(tvm_tirx_objs PRIVATE "${TVM_VISIBILITY_FLAG}")
 endif()
 if(MSVC)
   # Compiler objects import runtime symbols from the separate runtime DLL.
-  target_compile_definitions(tvm_objs PRIVATE TVM_EXPORTS TVM_FFI_EXPORTS)
+  target_compile_definitions(tvm_tirx_objs PRIVATE TVM_TIRX_EXPORTS 
TVM_FFI_EXPORTS)
 endif()
 
 # Compiler library: built from compiler-only sources.
-# Links against tvm_runtime (and tvm_ffi_shared transitively). Loaded with
+# Links against tvm_runtime (and tvm_ffi::shared transitively). Loaded with
 # RTLD_LOCAL so compiler-internal symbols don't leak into the global namespace.
-add_library(tvm_compiler SHARED
-  $<TARGET_OBJECTS:tvm_objs>
+add_library(tvm_tirx SHARED
+  $<TARGET_OBJECTS:tvm_tirx_objs>
 )
-target_link_libraries(tvm_compiler PUBLIC tvm_runtime tvm_ffi_shared)
-target_include_directories(tvm_compiler PUBLIC 
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
-set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"${TVM_NO_UNDEFINED_SYMBOLS}")
-set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"${TVM_VISIBILITY_FLAG}")
+target_link_libraries(tvm_tirx PUBLIC tvm_runtime tvm_ffi::shared)
+target_include_directories(tvm_tirx PUBLIC 
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" 
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+set_property(TARGET tvm_tirx APPEND PROPERTY LINK_OPTIONS 
"${TVM_NO_UNDEFINED_SYMBOLS}")
+set_property(TARGET tvm_tirx APPEND PROPERTY LINK_OPTIONS 
"${TVM_VISIBILITY_FLAG}")
 
 # Work around a GNU ld (binutils) relaxation bug that miscompiles
 # R_X86_64_GOTPCRELX relocations inside very large statically-linked archives.
-# When the full LLVM static libraries are linked into libtvm_compiler.so, the
+# When the full LLVM static libraries are linked into libtvm_tirx.so, the
 # library is large enough that ld can relax an indirect GOT call (LLVM built
 # with -fno-plt emits these) into a direct call with an incorrect displacement.
 # The call then targets read-only data instead of the intended function and
@@ -525,22 +480,22 @@ set_property(TARGET tvm_compiler APPEND PROPERTY 
LINK_OPTIONS "${TVM_VISIBILITY_
 # avoids the miscompilation; it is harmless when LLVM is linked dynamically.
 # See binutils bug ld/25754.
 if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT "${USE_LLVM}" MATCHES 
${IS_FALSE_PATTERN})
-  set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"-Wl,--no-relax")
+  set_property(TARGET tvm_tirx APPEND PROPERTY LINK_OPTIONS "-Wl,--no-relax")
   # LLVM's --system-libs reports -lxml2, but TVM calls no libxml2 symbols. The
   # manylinux toolchain does not default to --as-needed, so set it explicitly:
   # the unused libxml2 is then not recorded as a NEEDED dependency, so 
auditwheel
   # does not vendor it (and its deps) into the wheel.
-  set_property(TARGET tvm_compiler APPEND PROPERTY LINK_OPTIONS 
"-Wl,--as-needed")
+  set_property(TARGET tvm_tirx APPEND PROPERTY LINK_OPTIONS "-Wl,--as-needed")
 endif()
 
-set_target_properties(tvm_compiler PROPERTIES
+set_target_properties(tvm_tirx PROPERTIES
   ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
   LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
   RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
 )
 if(MSVC)
   foreach(config_type Release RELEASE Debug DEBUG RelWithDebInfo 
RELWITHDEBINFO MinSizeRel MINSIZEREL)
-    set_target_properties(tvm_compiler PROPERTIES
+    set_target_properties(tvm_tirx PROPERTIES
       ARCHIVE_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
       LIBRARY_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
       RUNTIME_OUTPUT_DIRECTORY_${config_type} "${CMAKE_BINARY_DIR}/lib"
@@ -549,188 +504,105 @@ if(MSVC)
 endif()
 
 if(USE_THREADS)
-  target_link_libraries(tvm_compiler PUBLIC Threads::Threads)
+  target_link_libraries(tvm_tirx PUBLIC Threads::Threads)
 endif()
-target_link_libraries(tvm_compiler PRIVATE ${TVM_LINKER_LIBS} 
${TVM_RUNTIME_LINKER_LIBS})
+target_link_libraries(tvm_tirx PRIVATE ${TVM_LINKER_LIBS} 
${TVM_RUNTIME_LINKER_LIBS})
 
 if(TVM_IS_DEBUG_BUILD)
-  target_compile_options(tvm_compiler PRIVATE "${FILE_PREFIX_MAP_FLAG}")
+  target_compile_options(tvm_tirx PRIVATE "${FILE_PREFIX_MAP_FLAG}")
   if(FILE_PREFIX_MAP_SUPPORTED)
-    target_compile_options(tvm_compiler PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
-    target_compile_options(tvm_objs PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
+    target_compile_options(tvm_tirx PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
+    target_compile_options(tvm_tirx_objs PRIVATE 
$<$<COMPILE_LANGUAGE:CXX>:${FILE_PREFIX_MAP_FLAG}>)
   endif()
 endif()
 
-tvm_ffi_add_apple_dsymutil(tvm_compiler)
-tvm_configure_target_library(tvm_compiler)
-install(TARGETS tvm_compiler DESTINATION lib${LIB_SUFFIX})
+tvm_ffi_add_apple_dsymutil(tvm_tirx)
+tvm_configure_target_library(tvm_tirx)
+install(TARGETS tvm_tirx DESTINATION lib${LIB_SUFFIX})
 
 # logging option for libbacktrace
-include(cmake/modules/Logging.cmake)
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/Logging.cmake")
 
-if(USE_CPP_RPC)
-  add_subdirectory("apps/cpp_rpc")
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangFlags.cmake")
+if(USE_CUDA AND USE_NVTX)
+  add_compile_definitions(TVM_NVTX_ENABLED=1)
+  target_compile_definitions(tvm_runtime INTERFACE TVM_NVTX_ENABLED=1)
 endif()
-
-if(USE_CPP_RTVM)
-  add_subdirectory("apps/cpp_rtvm")
+if(INDEX_DEFAULT_I64)
+  target_compile_definitions(tvm_runtime INTERFACE TVM_INDEX_DEFAULT_I64=1)
 endif()
-
-if(USE_IOS_RPC)
-  add_subdirectory("apps/ios_rpc")
+if(USE_KALLOC_ALIGNMENT)
+  target_compile_definitions(tvm_runtime INTERFACE 
TVM_KALLOC_ALIGNMENT=${USE_KALLOC_ALIGNMENT})
 endif()
-
-# Set flags for clang
-include(cmake/modules/ClangFlags.cmake)
-# Installation rules
-if (INSTALL_DEV)
-  install(
-    DIRECTORY "include/" DESTINATION "include"
-    FILES_MATCHING
-    PATTERN "*.h"
-  )
-else(INSTALL_DEV)
-  install(
-    DIRECTORY "include/tvm/runtime" "include/tvm/support" DESTINATION 
"include/tvm"
-    FILES_MATCHING
-    PATTERN "*.h"
-    )
-endif(INSTALL_DEV)
-
-include(CMakePackageConfigHelpers)
-set(PROJECT_CONFIG_CONTENT "@PACKAGE_INIT@\n")
-string(APPEND PROJECT_CONFIG_CONTENT "include(CMakeFindDependencyMacro)\n")
-string(APPEND PROJECT_CONFIG_CONTENT "find_dependency(Threads REQUIRED)\n")
-string(APPEND PROJECT_CONFIG_CONTENT
-       "include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")")
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/temp_config_file.cmake" 
${PROJECT_CONFIG_CONTENT})
-
-# install(EXPORT ${PROJECT_NAME}Targets
-#   NAMESPACE ${PROJECT_NAME}::
-#   DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
-
-# Create config for find_package()
-configure_package_config_file(
-  "${CMAKE_CURRENT_BINARY_DIR}/temp_config_file.cmake" 
${PROJECT_NAME}Config.cmake
-  INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
-
-install(
-  FILES
-  "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
-  DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
-
-find_and_set_linker(${USE_ALTERNATIVE_LINKER})
-
-if(${SUMMARIZE})
-  print_summary()
+if(TVM_DEBUG_WITH_ABI_CHANGE)
+  target_compile_definitions(tvm_runtime PUBLIC TVM_DEBUG_WITH_ABI_CHANGE)
+  target_compile_definitions(tvm_runtime_objs PRIVATE 
TVM_DEBUG_WITH_ABI_CHANGE)
+  target_compile_definitions(tvm_tirx_objs PRIVATE TVM_DEBUG_WITH_ABI_CHANGE)
 endif()
 
-dump_options_to_file("${TVM_ALL_OPTIONS}")
-
-if(USE_CUDA AND USE_CUTLASS)
-  install(TARGETS fpA_intB_gemm EXPORT ${PROJECT_NAME}Targets DESTINATION 
lib${LIB_SUFFIX})
-  install(TARGETS flash_attn EXPORT ${PROJECT_NAME}Targets DESTINATION 
lib${LIB_SUFFIX})
-  # fpA_intB_gemm, fpA_intB_gemm_tvm, and flash_attn are linked by
-  # tvm_runtime_extra (see RuntimeExtra.cmake); no link needed here.
+get_target_property(_runtime_compile_definitions tvm_runtime 
INTERFACE_COMPILE_DEFINITIONS)
+if(_runtime_compile_definitions)
+  target_compile_definitions(tvm_runtime_static INTERFACE 
${_runtime_compile_definitions})
 endif()
-
-if(USE_CUDA AND USE_NVTX)
-  add_compile_definitions(TVM_NVTX_ENABLED=1)
+add_library(tvm_tirx_private_headers INTERFACE)
+set_target_properties(tvm_tirx_private_headers PROPERTIES EXPORT_NAME 
private_headers)
+target_include_directories(tvm_tirx_private_headers INTERFACE
+  "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
+  "$<BUILD_INTERFACE:${COMPILER_RT_PATH}>"
+  "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/tvm_tirx/private>"
+  "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/tvm_tirx/compiler-rt>")
+set(_tirx_targets tvm_tirx ${_runtime_targets} tvm_tirx_private_headers 
${TVM_RUNTIME_BACKEND_LIBS})
+foreach(_target IN LISTS _tirx_targets)
+  get_target_property(_export_name ${_target} EXPORT_NAME)
+  if(NOT _export_name)
+    set(_export_name ${_target})
+  endif()
+  add_library(tvm_tirx::${_export_name} ALIAS ${_target})
+endforeach()
+install(TARGETS ${_tirx_targets} EXPORT tvm_tirxTargets
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 
FILES_MATCHING PATTERN "*.h")
+# CLML's retained OpenCL interface needs this bounded private include closure.
+foreach(_header backend/opencl/memory_scope.h
+    backend/opencl/runtime/opencl_common.h backend/opencl/runtime/texture.h
+    runtime/metadata.h runtime/pack_args.h runtime/workspace_pool.h)
+  get_filename_component(_dir "${_header}" DIRECTORY)
+  install(FILES "src/${_header}" DESTINATION 
"${CMAKE_INSTALL_INCLUDEDIR}/tvm_tirx/private/${_dir}")
+endforeach()
+install(FILES 3rdparty/compiler-rt/builtin_fp16.h DESTINATION 
${CMAKE_INSTALL_INCLUDEDIR}/tvm_tirx/compiler-rt)
+include(CMakePackageConfigHelpers)
+configure_package_config_file(cmake/tvm_tirxConfig.cmake.in
+  "${CMAKE_CURRENT_BINARY_DIR}/tvm_tirxConfig.cmake"
+  INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tvm_tirx")
+install(EXPORT tvm_tirxTargets NAMESPACE tvm_tirx:: DESTINATION 
"${CMAKE_INSTALL_LIBDIR}/cmake/tvm_tirx")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tvm_tirxConfig.cmake" DESTINATION 
"${CMAKE_INSTALL_LIBDIR}/cmake/tvm_tirx")
+install(DIRECTORY cmake/utils cmake/modules DESTINATION 
"${CMAKE_INSTALL_LIBDIR}/cmake/tvm_tirx" FILES_MATCHING PATTERN "*.cmake")
+set(TVM_TIRX_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+if(IS_SUBPROJECT)
+  set(TVM_TIRX_CMAKE_DIR "${TVM_TIRX_CMAKE_DIR}" PARENT_SCOPE)
+  foreach(_option USE_CUDA USE_ROCM BUILD_FOR_ANDROID)
+    set(TVM_TIRX_${_option} "${${_option}}" PARENT_SCOPE)
+  endforeach()
 endif()
-
-# Tests inherit the final project linker flags and compile definitions.
 add_subdirectory(tests/cpp)
 if(GTEST_FOUND)
-  # CTest must also be enabled at the project root for subdirectory discovery.
   enable_testing()
   include(CTest)
 endif()
-
-# Python package installation configuration
-# This section ensures that all necessary files are installed for the Python 
wheel
-if(TVM_BUILD_PYTHON_MODULE)
-  message(STATUS "Configuring Python package installation")
-
-  # Install compiled shared libraries into <project>/lib so that
-  # tvm_ffi.libinfo.load_lib_ctypes(package="tvm", target_name=...) can find
-  # them via the package RECORD or the project's lib/ fallback dir.
-  install(TARGETS tvm_compiler DESTINATION "lib")
-  install(TARGETS tvm_runtime DESTINATION "lib")
-
-  # Install third-party compiled dependencies into the same lib/ dir.
-  if(TARGET fpA_intB_gemm)
-    tvm_configure_target_library(fpA_intB_gemm)
-    install(TARGETS fpA_intB_gemm DESTINATION "lib")
-  endif()
-  if(TARGET flash_attn)
-    tvm_configure_target_library(flash_attn)
-    install(TARGETS flash_attn DESTINATION "lib")
-  endif()
-
-  # Install prebuilt extra runtime libraries into the same lib/ dir. This is 
how
-  # the separately-built CUDA runtime (libtvm_runtime_cuda.so) is bundled: the
-  # publishing flow builds it in a CUDA-enabled environment and passes its path
-  # via TVM_PACKAGE_EXTRA_LIBS, so it ships through the normal CMake install
-  # rather than a post-build wheel rewrite.
+find_and_set_linker(${USE_ALTERNATIVE_LINKER})
+if(SUMMARIZE)
+  print_summary()
+endif()
+dump_options_to_file("${TVM_ALL_OPTIONS}")
+if(TVM_BUILD_PYTHON_MODULE AND NOT IS_SUBPROJECT)
   foreach(_extra_lib IN LISTS TVM_PACKAGE_EXTRA_LIBS)
     if(NOT EXISTS "${_extra_lib}")
       message(FATAL_ERROR "TVM_PACKAGE_EXTRA_LIBS entry does not exist: 
${_extra_lib}")
     endif()
-    install(FILES "${_extra_lib}" DESTINATION "lib")
+    install(FILES "${_extra_lib}" DESTINATION lib)
   endforeach()
-
-  # Install minimal header files needed by Python extensions
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/tvm/runtime/"
-    DESTINATION "include/tvm/runtime/"
-    FILES_MATCHING
-    PATTERN "*.h"
-  )
-
-  # Install minimal CMake configuration
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/"
-    DESTINATION "cmake/utils/"
-    FILES_MATCHING
-    PATTERN "*.cmake"
-  )
-
-  # Install CUTLASS headers only if available
-  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cutlass/include")
-    install(
-      DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cutlass/include/"
-      DESTINATION "3rdparty/cutlass/include/"
-      FILES_MATCHING
-      PATTERN "*.h"
-      PATTERN "*.hpp"
-    )
-  endif()
-
-  # Install minimal source files
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/"
-    DESTINATION "src/runtime/"
-    FILES_MATCHING
-    PATTERN "*.cc"
-    PATTERN "*.h"
-  )
-
-  # Install web package
-  install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/web/" DESTINATION "web/")
-
-  # Install licenses (required for distribution)
-  install(
-    DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/licenses/"
-    DESTINATION "licenses/"
-  )
-
-  # Install essential metadata files
-  install(FILES
-    "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
-    "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
-    "${CMAKE_CURRENT_SOURCE_DIR}/NOTICE"
-    DESTINATION "."
-  )
-
-  message(STATUS "Python package installation configured")
+  install(DIRECTORY licenses/ DESTINATION licenses)
+  install(FILES LICENSE NOTICE DESTINATION .)
 endif()
diff --git a/tirx/cmake/modules/CUDA.cmake b/tirx/cmake/modules/CUDA.cmake
index 4e2cdd508c..29217b891c 100644
--- a/tirx/cmake/modules/CUDA.cmake
+++ b/tirx/cmake/modules/CUDA.cmake
@@ -16,7 +16,7 @@
 # under the License.
 
 # CUDA Module
-find_cuda(${USE_CUDA} ${USE_CUDNN})
+find_cuda(${USE_CUDA} OFF)
 
 if(CUDA_FOUND)
   # always set the includedir when CUDA is available
@@ -70,9 +70,8 @@ if(USE_CUDA)
   endif()
 
   tvm_file_glob(GLOB RUNTIME_CUDA_SRCS src/backend/cuda/runtime/*.cc)
-  tvm_file_glob(GLOB VM_CUDA_BUILTIN_SRC_CC src/runtime/vm/cuda/*.cc)
 
-  add_library(tvm_runtime_cuda_objs OBJECT ${RUNTIME_CUDA_SRCS} 
${VM_CUDA_BUILTIN_SRC_CC})
+  add_library(tvm_runtime_cuda_objs OBJECT ${RUNTIME_CUDA_SRCS})
   target_link_libraries(tvm_runtime_cuda_objs PUBLIC tvm_ffi_header)
   # These sources compile into tvm_runtime_cuda.dll, so their TVM_RUNTIME_DLL /
   # TVM_FFI_DLL symbols must be dllexport on MSVC (e.g. GetCudaDeviceCount in
@@ -92,71 +91,3 @@ if(USE_CUDA)
     target_link_libraries(tvm_runtime_cuda PRIVATE ${CUDA_NVTX_LIBRARY})
   endif()
 endif(USE_CUDA)
-
-# Contrib sources gated by USE_CUDA go into libtvm_runtime_extra.
-# See the RuntimeExtra assembly block in CMakeLists.txt.
-
-if(USE_CUDA AND USE_CUDNN)
-  message(STATUS "Build with cuDNN support")
-  include_directories(SYSTEM ${CUDA_CUDNN_INCLUDE_DIRS})
-  tvm_file_glob(GLOB CUDNN_RELAX_CONTRIB_SRC 
src/relax/backend/contrib/cudnn/*.cc)
-  list(APPEND COMPILER_SRCS ${CUDNN_RELAX_CONTRIB_SRC})
-  tvm_file_glob(GLOB CONTRIB_CUDNN_SRCS src/runtime/extra/contrib/cudnn/*.cc)
-  add_library(tvm_cudnn_objs OBJECT ${CONTRIB_CUDNN_SRCS})
-  target_link_libraries(tvm_cudnn_objs PRIVATE tvm_runtime_extra_defs)
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_cudnn_objs 
${CUDA_CUDNN_LIBRARY})
-endif(USE_CUDA AND USE_CUDNN)
-
-if(USE_CUDA AND USE_CUDNN_FRONTEND)
-  message(STATUS "Build with cuDNN Frontend support")
-  if(IS_DIRECTORY ${USE_CUDNN_FRONTEND})
-    find_file(CUDNN_FRONTEND_HEADER cudnn_frontend.h HINTS 
${USE_CUDNN_FRONTEND}/include)
-    include_directories(SYSTEM ${USE_CUDNN_FRONTEND}/include)
-  else()
-    find_file(CUDNN_FRONTEND_HEADER cudnn_frontend.h)
-  endif()
-  if(NOT CUDNN_FRONTEND_HEADER)
-    message(FATAL_ERROR "Cannot find cudnn_frontend.h, please set 
USE_CUDNN_FRONTEND to the path of the cuDNN frontend header")
-  endif()
-  tvm_file_glob(GLOB CONTRIB_CUDNN_FRONTEND_SRCS 
src/runtime/extra/contrib/cudnn/cudnn_frontend/*.cc)
-  set_source_files_properties(${CONTRIB_CUDNN_SRCS} PROPERTIES 
COMPILE_DEFINITIONS TVM_USE_CUDNN_FRONTEND=1)
-  add_library(tvm_cudnn_frontend_objs OBJECT ${CONTRIB_CUDNN_FRONTEND_SRCS})
-  target_link_libraries(tvm_cudnn_frontend_objs PRIVATE tvm_runtime_extra_defs)
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_cudnn_frontend_objs)
-endif(USE_CUDA AND USE_CUDNN_FRONTEND)
-
-if(USE_CUDA AND USE_CUBLAS)
-  message(STATUS "Build with cuBLAS support")
-  tvm_file_glob(GLOB CUBLAS_CONTRIB_SRC src/relax/backend/contrib/cublas/*.cc)
-  list(APPEND COMPILER_SRCS ${CUBLAS_CONTRIB_SRC})
-  tvm_file_glob(GLOB CONTRIB_CUBLAS_SRCS src/runtime/extra/contrib/cublas/*.cc)
-  add_library(tvm_cublas_objs OBJECT ${CONTRIB_CUBLAS_SRCS})
-  target_link_libraries(tvm_cublas_objs PRIVATE tvm_runtime_extra_defs)
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_cublas_objs 
${CUDA_CUBLAS_LIBRARY})
-  if(NOT CUDA_CUBLASLT_LIBRARY STREQUAL "CUDA_CUBLASLT_LIBRARY-NOTFOUND")
-    target_link_libraries(tvm_runtime_extra PRIVATE ${CUDA_CUBLASLT_LIBRARY})
-  endif()
-endif(USE_CUDA AND USE_CUBLAS)
-
-if(USE_CUDA AND USE_THRUST)
-  message(STATUS "Build with Thrust support")
-  tvm_file_glob(GLOB CONTRIB_THRUST_SRC src/runtime/extra/contrib/thrust/*.cu)
-  add_library(tvm_thrust_objs OBJECT ${CONTRIB_THRUST_SRC})
-  target_link_libraries(tvm_thrust_objs PRIVATE tvm_runtime_extra_defs)
-  target_compile_options(tvm_thrust_objs PRIVATE 
$<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>)
-  if(NOT USE_THRUST MATCHES ${IS_TRUE_PATTERN})
-    find_package(CCCL REQUIRED COMPONENTS Thrust)
-    target_link_libraries(tvm_thrust_objs PRIVATE CCCL::Thrust)
-  endif()
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_thrust_objs)
-endif(USE_CUDA AND USE_THRUST)
-
-if(USE_CUDA AND USE_CURAND)
-  message(STATUS "Build with cuRAND support")
-  message(STATUS "${CUDA_CURAND_LIBRARY}")
-  tvm_file_glob(GLOB CONTRIB_CURAND_SRC_CC 
src/runtime/extra/contrib/curand/*.cc)
-  tvm_file_glob(GLOB CONTRIB_CURAND_SRC_CU 
src/runtime/extra/contrib/curand/*.cu)
-  add_library(tvm_curand_objs OBJECT ${CONTRIB_CURAND_SRC_CC} 
${CONTRIB_CURAND_SRC_CU})
-  target_link_libraries(tvm_curand_objs PRIVATE tvm_runtime_extra_defs)
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_curand_objs 
${CUDA_CURAND_LIBRARY})
-endif(USE_CUDA AND USE_CURAND)
diff --git a/tirx/cmake/modules/ClangFlags.cmake 
b/tirx/cmake/modules/ClangFlags.cmake
index 61a88116c7..f296165726 100644
--- a/tirx/cmake/modules/ClangFlags.cmake
+++ b/tirx/cmake/modules/ClangFlags.cmake
@@ -82,7 +82,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
       -Wno-gnu-anonymous-struct
       -Wno-nested-anon-types
     )
-  target_compile_options(tvm_objs PRIVATE $<$<COMPILE_LANGUAGE:CXX>: 
${warning_opts}>)
+  target_compile_options(tvm_tirx_objs PRIVATE $<$<COMPILE_LANGUAGE:CXX>: 
${warning_opts}>)
   target_compile_options(tvm_runtime_objs PRIVATE $<$<COMPILE_LANGUAGE:CXX>: 
${warning_opts}>)
 
 
diff --git a/tirx/cmake/modules/Logging.cmake b/tirx/cmake/modules/Logging.cmake
index 09bb094c29..434e284da3 100644
--- a/tirx/cmake/modules/Logging.cmake
+++ b/tirx/cmake/modules/Logging.cmake
@@ -21,9 +21,8 @@ include(FindPackageHandleStandardArgs)
 
 if(USE_CUSTOM_LOGGING)
   # Set and propagate TVM_LOG_CUSTOMIZE flag is custom logging has been 
requested
-  target_compile_definitions(tvm_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
+  target_compile_definitions(tvm_tirx_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
   target_compile_definitions(tvm_runtime_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
-  target_compile_definitions(tvm_libinfo_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
-  target_compile_definitions(tvm_compiler PUBLIC TVM_LOG_CUSTOMIZE=1)
+  target_compile_definitions(tvm_tirx PUBLIC TVM_LOG_CUSTOMIZE=1)
   target_compile_definitions(tvm_runtime PUBLIC TVM_LOG_CUSTOMIZE=1)
 endif()
diff --git a/tirx/cmake/modules/OpenCL.cmake b/tirx/cmake/modules/OpenCL.cmake
index 4a398ae79f..e24ec2a24f 100644
--- a/tirx/cmake/modules/OpenCL.cmake
+++ b/tirx/cmake/modules/OpenCL.cmake
@@ -25,7 +25,10 @@ if(USE_OPENCL)
       "src/backend/opencl/runtime/opencl_wrapper/opencl_wrapper.cc"
     )
     list(APPEND RUNTIME_OPENCL_SRCS ${OPENCL_WRAPPER_SRCS})
-    set(_opencl_include_dirs 
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/OpenCL-Headers")
+    find_path(TVM_OPENCL_HEADERS_DIR CL/cl.h
+      HINTS "${TVM_OPENCL_HEADERS_ROOT}" ENV OPENCL_SDK
+      PATH_SUFFIXES include REQUIRED)
+    set(_opencl_include_dirs "${TVM_OPENCL_HEADERS_DIR}")
   else()
     find_opencl(${USE_OPENCL})
     if(NOT OpenCL_FOUND)
@@ -61,11 +64,7 @@ if(USE_OPENCL)
     "$<BUILD_INTERFACE:${_opencl_include_dirs}>")
   tvm_configure_target_library(tvm_runtime_opencl RUNTIME_MODULE)
 
-  if(USE_CLML_GRAPH_EXECUTOR)
-    # CLML calls both OpenCL SDK and TVM OpenCL runtime APIs directly.
-    target_link_libraries(tvm_clml_objs PRIVATE tvm_runtime_opencl)
-    target_link_libraries(tvm_runtime_extra PRIVATE tvm_runtime_opencl 
${_opencl_libs})
-  endif()
+
 
   if(USE_OPENCL_ENABLE_HOST_PTR)
     target_compile_definitions(tvm_runtime_opencl_objs PRIVATE 
OPENCL_ENABLE_HOST_PTR)
diff --git a/tirx/cmake/modules/ROCM.cmake b/tirx/cmake/modules/ROCM.cmake
index 33abc75a2b..d910674dc2 100644
--- a/tirx/cmake/modules/ROCM.cmake
+++ b/tirx/cmake/modules/ROCM.cmake
@@ -50,34 +50,3 @@ if(USE_ROCM)
   target_link_libraries(tvm_runtime_rocm PUBLIC tvm_runtime PRIVATE 
${_rocm_libs})
   tvm_configure_target_library(tvm_runtime_rocm RUNTIME_MODULE)
 endif(USE_ROCM)
-
-# HIPBLAS contrib goes into libtvm_runtime_extra.
-if(USE_ROCM AND USE_HIPBLAS)
-  message(STATUS "Build with HIPBLAS support")
-  tvm_file_glob(GLOB HIPBLAS_CONTRIB_SRC 
src/relax/backend/contrib/hipblas/*.cc)
-  list(APPEND COMPILER_SRCS ${HIPBLAS_CONTRIB_SRC})
-  tvm_file_glob(GLOB HIPBLAS_CONTRIB_SRCS 
src/runtime/extra/contrib/hipblas/*.cc)
-  add_library(tvm_hipblas_objs OBJECT ${HIPBLAS_CONTRIB_SRCS})
-  target_link_libraries(tvm_hipblas_objs PRIVATE tvm_runtime_extra_defs)
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_hipblas_objs 
${ROCM_HIPBLAS_LIBRARY})
-  if(NOT ROCM_HIPBLASLT_LIBRARY STREQUAL "ROCM_HIPBLASLT_LIBRARY-NOTFOUND")
-    target_link_libraries(tvm_runtime_extra PRIVATE ${ROCM_HIPBLASLT_LIBRARY})
-  endif()
-endif(USE_ROCM AND USE_HIPBLAS)
-
-if(USE_ROCM AND USE_THRUST)
-  message(STATUS "Build with rocThrust support")
-  # We need to override CXX to hipcc. This is required by rocthrust
-  if(${CMAKE_CXX_COMPILER} MATCHES "hipcc$")
-    message(STATUS "Using hipcc compiler to compile rocthrust code.")
-  else()
-    message(FATAL_ERROR "Set CXX=hipcc to compile rocthrust code.")
-  endif()
-
-  find_package(rocprim REQUIRED)
-  find_package(rocthrust REQUIRED)
-  set_source_files_properties(src/runtime/extra/contrib/thrust/thrust.cu 
PROPERTIES LANGUAGE CXX)
-  add_library(tvm_rocthrust_objs OBJECT 
src/runtime/extra/contrib/thrust/thrust.cu)
-  target_link_libraries(tvm_rocthrust_objs PRIVATE tvm_runtime_extra_defs)
-  target_link_libraries(tvm_runtime_extra PRIVATE tvm_rocthrust_objs 
roc::rocthrust)
-endif(USE_ROCM AND USE_THRUST)
diff --git a/tirx/cmake/modules/contrib/Z3.cmake 
b/tirx/cmake/modules/contrib/Z3.cmake
index bf61ec1352..48dc4f8d9c 100644
--- a/tirx/cmake/modules/contrib/Z3.cmake
+++ b/tirx/cmake/modules/contrib/Z3.cmake
@@ -95,3 +95,15 @@ endif()
 # Enable the real Z3 implementation inside the single src/sym/z3_prover.cc 
file.
 add_compile_definitions(TVM_USE_Z3)
 message(STATUS "Build with Z3 SMT solver support")
+
+if(TVM_BUILD_PYTHON_MODULE AND Z3_TARGET)
+  get_target_property(_z3_target_type ${Z3_TARGET} TYPE)
+  if(_z3_target_type STREQUAL "STATIC_LIBRARY" AND Python3_EXECUTABLE)
+    execute_process(COMMAND "${Python3_EXECUTABLE}" -c
+      "import importlib.util; from pathlib import Path; 
s=importlib.util.find_spec('mlc_z3_static'); print(Path(s.origin).parent / 
'licenses/LICENSE-Z3.txt' if s else '')"
+      OUTPUT_VARIABLE _z3_license OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(EXISTS "${_z3_license}")
+      install(FILES "${_z3_license}" DESTINATION licenses)
+    endif()
+  endif()
+endif()
diff --git a/tirx/cmake/modules/Logging.cmake 
b/tirx/cmake/tvm_tirxConfig.cmake.in
similarity index 52%
copy from tirx/cmake/modules/Logging.cmake
copy to tirx/cmake/tvm_tirxConfig.cmake.in
index 09bb094c29..abce76e80a 100644
--- a/tirx/cmake/modules/Logging.cmake
+++ b/tirx/cmake/tvm_tirxConfig.cmake.in
@@ -15,15 +15,23 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# This script configures the logging module and dependency on libbacktrace
-
-include(FindPackageHandleStandardArgs)
-
-if(USE_CUSTOM_LOGGING)
-  # Set and propagate TVM_LOG_CUSTOMIZE flag is custom logging has been 
requested
-  target_compile_definitions(tvm_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
-  target_compile_definitions(tvm_runtime_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
-  target_compile_definitions(tvm_libinfo_objs PUBLIC TVM_LOG_CUSTOMIZE=1)
-  target_compile_definitions(tvm_compiler PUBLIC TVM_LOG_CUSTOMIZE=1)
-  target_compile_definitions(tvm_runtime PUBLIC TVM_LOG_CUSTOMIZE=1)
+@PACKAGE_INIT@
+include(CMakeFindDependencyMacro)
+find_dependency(Python COMPONENTS Interpreter)
+if(NOT TARGET tvm_ffi::shared)
+  if(NOT tvm_ffi_DIR)
+    execute_process(COMMAND "${Python_EXECUTABLE}" -m tvm_ffi.config --cmakedir
+      OUTPUT_VARIABLE tvm_ffi_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
+      COMMAND_ERROR_IS_FATAL ANY)
+  endif()
+  find_dependency(tvm_ffi CONFIG)
+endif()
+if("@USE_THREADS@")
+  find_dependency(Threads)
 endif()
+include("${CMAKE_CURRENT_LIST_DIR}/tvm_tirxTargets.cmake")
+set(TVM_TIRX_VERSION "@TVM_TIRX_VERSION@")
+set(TVM_TIRX_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}")
+set(TVM_TIRX_USE_CUDA "@USE_CUDA@")
+set(TVM_TIRX_USE_ROCM "@USE_ROCM@")
+set(TVM_TIRX_BUILD_FOR_ANDROID "@BUILD_FOR_ANDROID@")
diff --git a/tests/cpp/CMakeLists.txt b/tirx/tests/cpp/CMakeLists.txt
similarity index 78%
copy from tests/cpp/CMakeLists.txt
copy to tirx/tests/cpp/CMakeLists.txt
index 35c9fadb9e..255ea70ed0 100644
--- a/tests/cpp/CMakeLists.txt
+++ b/tirx/tests/cpp/CMakeLists.txt
@@ -16,7 +16,7 @@
 # under the License.
 
 # Enable ctest if gtest is available
-if(USE_GTEST)
+if(USE_GTEST AND NOT BUILD_TESTING STREQUAL "OFF")
   # Check env var for backward compatibility. A better way to specify package
   # locations is to use CMAKE_PREFIX_PATH or other standard CMake mechanism
   # (see CMake documentation for `find_package`).
@@ -54,18 +54,18 @@ if(USE_GTEST)
   endif()
 endif()
 
-# Create the `cpptest` target when GTest is available.
+# Create the `tirx_cpptest` target when GTest is available.
 if(GTEST_FOUND)
   tvm_file_glob(GLOB_RECURSE TEST_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
-  add_executable(cpptest ${TEST_SRCS})
+  add_executable(tirx_cpptest ${TEST_SRCS})
   # Preserve the executable location used before this became a subdirectory.
-  set_target_properties(cpptest PROPERTIES RUNTIME_OUTPUT_DIRECTORY 
"${PROJECT_BINARY_DIR}")
+  set_target_properties(tirx_cpptest PROPERTIES RUNTIME_OUTPUT_DIRECTORY 
"${CMAKE_BINARY_DIR}")
   # include runtime files for unit testing
-  target_link_libraries(cpptest PRIVATE tvm_compiler GTest::GTest GTest::Main 
GTest::gmock pthread dl)
+  target_link_libraries(tirx_cpptest PRIVATE tvm_tirx GTest::GTest GTest::Main 
GTest::gmock pthread dl)
   if(DEFINED LLVM_LIBS)
     # The TVM library is linked with LLVM libraries. If the LLVM libraries are
     # static and the symbols are not hidden, then don't link them again into
-    # cpptest since cpptest is itself linked against the TVM library. If static
+    # tirx_cpptest since tirx_cpptest is itself linked against the TVM 
library. If static
     # LLVM libraries are linked in twice, it can cause issues with global
     # variable initialization (cl::opt).
     # If the LLVM libraries are dynamic, we have to link them again, since the
@@ -78,32 +78,32 @@ if(GTEST_FOUND)
       endif()
     endforeach()
     if(DEFINED LLVM_SO OR HIDE_PRIVATE_SYMBOLS)
-      target_link_libraries(cpptest PRIVATE ${LLVM_LIBS})
+      target_link_libraries(tirx_cpptest PRIVATE ${LLVM_LIBS})
     endif()
   endif()
-  set_target_properties(cpptest PROPERTIES EXCLUDE_FROM_ALL 1)
-  set_target_properties(cpptest PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
-  # cpptest is built into ${CMAKE_BINARY_DIR} but the TVM shared libs it
-  # links against (libtvm_compiler.so / libtvm_runtime.so) now live in
+  set_target_properties(tirx_cpptest PROPERTIES EXCLUDE_FROM_ALL 1)
+  set_target_properties(tirx_cpptest PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
+  # tirx_cpptest is built into ${CMAKE_BINARY_DIR} but the TVM shared libs it
+  # links against (libtvm_tirx.so / libtvm_runtime.so) now live in
   # ${CMAKE_BINARY_DIR}/lib. CMake's default behaviour bakes the
   # absolute path of build/lib/ into the binary's RUNPATH, which works in tree
   # but is not relocatable. Set $ORIGIN/lib (or @loader_path/lib on macOS)
   # explicitly so the test binary finds its TVM libs relative to its own
   # location, mirroring the install-time RPATH setup.
   if(APPLE)
-    set_target_properties(cpptest PROPERTIES
+    set_target_properties(tirx_cpptest PROPERTIES
       BUILD_RPATH "@loader_path/lib"
       INSTALL_RPATH "@loader_path/lib"
     )
   elseif(UNIX)
-    set_target_properties(cpptest PROPERTIES
+    set_target_properties(tirx_cpptest PROPERTIES
       BUILD_RPATH "\$ORIGIN/lib"
       INSTALL_RPATH "\$ORIGIN/lib"
     )
   endif()
-  target_compile_definitions(cpptest PRIVATE "NDEBUG")
+  target_compile_definitions(tirx_cpptest PRIVATE "NDEBUG")
 
   # For some reason, compile definitions are not propagated correctly, so we 
manually add them here
-  target_compile_definitions(cpptest PUBLIC 
$<TARGET_PROPERTY:tvm_compiler,INTERFACE_COMPILE_DEFINITIONS>)
-  gtest_discover_tests(cpptest WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
+  target_compile_definitions(tirx_cpptest PUBLIC 
$<TARGET_PROPERTY:tvm_tirx,INTERFACE_COMPILE_DEFINITIONS>)
+  gtest_discover_tests(tirx_cpptest WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
 endif()

Reply via email to