Skip to content

Commit a1cb746

Browse files
authored
build: Rename Import Targets (#354)
This PR renames imported targets in `tvm_ffi-config.cmake` - `tvm_ffi_shared` => `tvm_ffi::shared` - `tvm_ffi_header` => `tvm_ffi::header` in order to avoid name conflicts with targets defined in `CMakeLists.txt`
1 parent dc0dd2f commit a1cb746

File tree

8 files changed

+43
-37
lines changed

8 files changed

+43
-37
lines changed

cmake/Utils/EmbedCubin.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,18 @@ function (tvm_ffi_embed_cubin)
173173
get_filename_component(OUTPUT_NAME "${ARG_OUTPUT_ABS}" NAME_WE)
174174
set(INTERMEDIATE_OBJ "${OUTPUT_DIR}/${OUTPUT_NAME}_intermediate.o")
175175

176-
# Get include directories from tvm_ffi_header
177-
get_target_property(TVM_FFI_INCLUDES tvm_ffi_header INTERFACE_INCLUDE_DIRECTORIES)
176+
# Get include directories from tvm_ffi header target
177+
if (TARGET tvm_ffi::header)
178+
set(TVM_FFI_HEADER_TARGET tvm_ffi::header)
179+
elseif (TARGET tvm_ffi_header)
180+
set(TVM_FFI_HEADER_TARGET tvm_ffi_header)
181+
else ()
182+
message(
183+
FATAL_ERROR
184+
"tvm_ffi_embed_cubin: required target 'tvm_ffi::header' or 'tvm_ffi_header' does not exist."
185+
)
186+
endif ()
187+
get_target_property(TVM_FFI_INCLUDES ${TVM_FFI_HEADER_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
178188

179189
# Convert list to -I flags
180190
set(INCLUDE_FLAGS "")

cmake/Utils/Library.cmake

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,18 @@ endfunction ()
145145
# [STUB_INIT ON|OFF] [STUB_DIR <dir>] [STUB_PKG <pkg>] [STUB_PREFIX <prefix>]
146146
# )
147147
# Configure a target to integrate with TVM-FFI CMake utilities:
148-
# - Optionally link against tvm_ffi_header and/or tvm_ffi_shared
148+
# - Link against tvm_ffi::header and/or tvm_ffi::shared
149149
# - Always apply tvm_ffi_add_prefix_map(target_name <current source dir>)
150-
# - Optionally enable Apple dSYM generation via tvm_ffi_add_apple_dsymutil(target_name)
151-
# - Optionally apply MSVC-specific flags via tvm_ffi_add_msvc_flags(target_name)
150+
# - Enable Apple dSYM generation via tvm_ffi_add_apple_dsymutil(target_name)
151+
# - Apply MSVC-specific flags via tvm_ffi_add_msvc_flags(target_name)
152+
# - Add post-build step to generate Python stubs via tvm_ffi.stub.cli
152153
#
153154
# Parameters:
154155
# target_name: Existing CMake target to modify (positional, required)
155156
#
156157
# Keyword parameters:
157-
# LINK_SHARED: Whether to link tvm_ffi_shared into the target (default: ON; ON/OFF-style)
158-
# LINK_HEADER: Whether to link tvm_ffi_header into the target (default: ON; ON/OFF-style)
158+
# LINK_SHARED: Whether to link tvm_ffi::shared into the target (default: ON; ON/OFF-style)
159+
# LINK_HEADER: Whether to link tvm_ffi::header into the target (default: ON; ON/OFF-style)
159160
# DEBUG_SYMBOL: Whether to enable debug symbol post-processing hooks.
160161
# On Apple this calls tvm_ffi_add_apple_dsymutil(target_name) (default: ON; ON/OFF-style)
161162
# On non-Apple platforms this is currently a no-op unless you extend it. (default: ON)
@@ -257,24 +258,24 @@ function (tvm_ffi_configure_target target)
257258

258259
# LINK_HEADER
259260
if (tvm_ffi_arg__LINK_HEADER)
260-
if (TARGET tvm_ffi_header)
261-
target_link_libraries("${target}" PRIVATE tvm_ffi_header)
261+
if (TARGET tvm_ffi::header)
262+
target_link_libraries("${target}" PRIVATE tvm_ffi::header)
262263
else ()
263264
message(
264265
FATAL_ERROR
265-
"tvm_ffi_configure_target(${target}): LINK_HEADER requested but target 'tvm_ffi_header' does not exist."
266+
"tvm_ffi_configure_target(${target}): LINK_HEADER requested but targets 'tvm_ffi::header' do not exist."
266267
)
267268
endif ()
268269
endif ()
269270

270271
# LINK_SHARED
271272
if (tvm_ffi_arg__LINK_SHARED)
272-
if (TARGET tvm_ffi_shared)
273-
target_link_libraries("${target}" PRIVATE tvm_ffi_shared)
273+
if (TARGET tvm_ffi::shared)
274+
target_link_libraries("${target}" PRIVATE tvm_ffi::shared)
274275
else ()
275276
message(
276277
FATAL_ERROR
277-
"tvm_ffi_configure_target(${target}): LINK_SHARED requested but target 'tvm_ffi_shared' does not exist."
278+
"tvm_ffi_configure_target(${target}): LINK_SHARED requested but targets 'tvm_ffi::shared' do not exist."
278279
)
279280
endif ()
280281
endif ()

cmake/tvm_ffi-config.cmake

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,22 @@ execute_process(
4242

4343
message(STATUS "Finding libfiles ${tvm_ffi_LIB_FILES}")
4444

45-
add_library(tvm_ffi_header INTERFACE)
46-
target_compile_features(tvm_ffi_header INTERFACE cxx_std_17)
47-
target_include_directories(tvm_ffi_header INTERFACE "${tvm_ffi_INCLUDE_DIR}")
48-
target_include_directories(tvm_ffi_header INTERFACE "${tvm_ffi_DLPACK_INCLUDE_DIR}")
45+
add_library(tvm_ffi::header INTERFACE IMPORTED)
46+
target_compile_features(tvm_ffi::header INTERFACE cxx_std_17)
47+
target_include_directories(tvm_ffi::header INTERFACE "${tvm_ffi_INCLUDE_DIR}")
48+
target_include_directories(tvm_ffi::header INTERFACE "${tvm_ffi_DLPACK_INCLUDE_DIR}")
4949

50-
add_library(tvm_ffi_shared SHARED IMPORTED)
51-
target_compile_features(tvm_ffi_shared INTERFACE cxx_std_17)
50+
add_library(tvm_ffi::shared SHARED IMPORTED)
51+
target_compile_features(tvm_ffi::shared INTERFACE cxx_std_17)
5252

5353
if (WIN32)
54-
set_target_properties(tvm_ffi_shared PROPERTIES IMPORTED_IMPLIB "${tvm_ffi_LIB_FILES}")
54+
set_target_properties(tvm_ffi::shared PROPERTIES IMPORTED_IMPLIB "${tvm_ffi_LIB_FILES}")
5555
else ()
56-
set_target_properties(tvm_ffi_shared PROPERTIES IMPORTED_LOCATION "${tvm_ffi_LIB_FILES}")
56+
set_target_properties(tvm_ffi::shared PROPERTIES IMPORTED_LOCATION "${tvm_ffi_LIB_FILES}")
5757
endif ()
58-
# cmake-lint: disable=C0307
5958
set_target_properties(
60-
tvm_ffi_shared PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
61-
"${tvm_ffi_INCLUDE_DIR};${tvm_ffi_DLPACK_INCLUDE_DIR}"
59+
tvm_ffi::shared PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
60+
"${tvm_ffi_INCLUDE_DIR};${tvm_ffi_DLPACK_INCLUDE_DIR}"
6261
)
6362

6463
include(${CMAKE_CURRENT_LIST_DIR}/Utils/Library.cmake)

docs/get_started/quickstart.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ TVM-FFI natively integrates with CMake via ``find_package`` as demonstrated belo
132132
execute_process(COMMAND "${Python_EXECUTABLE}" -m tvm_ffi.config --cmakedir OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE tvm_ffi_ROOT)
133133
find_package(tvm_ffi CONFIG REQUIRED)
134134
135-
# Link C++ target to `tvm_ffi_header` and `tvm_ffi_shared`
135+
# Link C++ target to `tvm_ffi::header` and `tvm_ffi::shared`
136136
add_library(add_one_cpu SHARED compile/add_one_cpu.cc)
137137
tvm_ffi_configure_target(add_one_cpu)
138138
@@ -146,7 +146,7 @@ TVM-FFI natively integrates with CMake via ``find_package`` as demonstrated belo
146146
execute_process(COMMAND "${Python_EXECUTABLE}" -m tvm_ffi.config --cmakedir OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE tvm_ffi_ROOT)
147147
find_package(tvm_ffi CONFIG REQUIRED)
148148
149-
# Link CUDA target to `tvm_ffi_header` and `tvm_ffi_shared`
149+
# Link CUDA target to `tvm_ffi::header` and `tvm_ffi::shared`
150150
add_library(add_one_cuda SHARED compile/add_one_cuda.cu)
151151
tvm_ffi_configure_target(add_one_cuda)
152152

examples/cubin_launcher/dynamic_cubin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ add_custom_target(
5252

5353
# Step 2: Build lib_dynamic shared library (loads CUBIN from file at runtime)
5454
add_library(lib_dynamic SHARED src/lib_dynamic.cc)
55-
target_link_libraries(lib_dynamic PRIVATE tvm_ffi_header tvm_ffi_shared CUDA::cudart)
55+
target_link_libraries(lib_dynamic PRIVATE tvm_ffi::header tvm_ffi::shared CUDA::cudart)
5656
add_dependencies(lib_dynamic generate_cubin)
5757
set_target_properties(
5858
lib_dynamic

examples/cubin_launcher/embedded_cubin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ tvm_ffi_embed_cubin(
5858

5959
# Step 3: Build lib_embedded shared library (with embedded CUBIN)
6060
add_library(lib_embedded SHARED ${CMAKE_CURRENT_BINARY_DIR}/lib_embedded_with_cubin.o)
61-
target_link_libraries(lib_embedded PRIVATE tvm_ffi_header tvm_ffi_shared CUDA::cudart)
61+
target_link_libraries(lib_embedded PRIVATE tvm_ffi::header tvm_ffi::shared CUDA::cudart)
6262
set_target_properties(
6363
lib_embedded
6464
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/"

examples/quickstart/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,20 @@ find_package(tvm_ffi CONFIG REQUIRED)
6161
if (EXAMPLE_NAME STREQUAL "compile_cpu")
6262
# Example 1. C++ `add_one`
6363
add_library(add_one_cpu SHARED compile/add_one_cpu.cc)
64-
target_link_libraries(add_one_cpu PRIVATE tvm_ffi_header)
65-
target_link_libraries(add_one_cpu PRIVATE tvm_ffi_shared)
64+
target_link_libraries(add_one_cpu PRIVATE tvm_ffi::header tvm_ffi::shared)
6665
set_target_properties(add_one_cpu PROPERTIES PREFIX "" SUFFIX ".so")
6766
set_flat_output_dirs(add_one_cpu)
6867
elseif (EXAMPLE_NAME STREQUAL "compile_cuda")
6968
# Example 2. CUDA `add_one`
7069
enable_language(CUDA)
7170
add_library(add_one_cuda SHARED compile/add_one_cuda.cu)
72-
target_link_libraries(add_one_cuda PRIVATE tvm_ffi_shared)
71+
target_link_libraries(add_one_cuda PRIVATE tvm_ffi::header tvm_ffi::shared)
7372
set_target_properties(add_one_cuda PROPERTIES PREFIX "" SUFFIX ".so")
7473
set_flat_output_dirs(add_one_cuda)
7574
elseif (EXAMPLE_NAME STREQUAL "load_cpp")
7675
# Example 3. Load C++ shared library
7776
add_executable(load_cpp load/load_cpp.cc)
78-
target_link_libraries(load_cpp PRIVATE tvm_ffi_header)
79-
target_link_libraries(load_cpp PRIVATE tvm_ffi_shared)
77+
target_link_libraries(load_cpp PRIVATE tvm_ffi::header tvm_ffi::shared)
8078
set_flat_output_dirs(load_cpp)
8179
else ()
8280
message(FATAL_ERROR "Unknown EXAMPLE_NAME option: ${EXAMPLE_NAME}. "

examples/stable_c_abi/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ find_package(tvm_ffi CONFIG REQUIRED)
5858
if (EXAMPLE_NAME STREQUAL "kernel")
5959
# Example 1. `add_one_cpu` in C
6060
add_library(add_one_cpu SHARED src/add_one_cpu.c)
61-
target_link_libraries(add_one_cpu PRIVATE tvm_ffi_header)
62-
target_link_libraries(add_one_cpu PRIVATE tvm_ffi_shared)
61+
target_link_libraries(add_one_cpu PRIVATE tvm_ffi::header tvm_ffi::shared)
6362
set_target_properties(
6463
add_one_cpu
6564
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/"
@@ -73,8 +72,7 @@ if (EXAMPLE_NAME STREQUAL "kernel")
7372
elseif (EXAMPLE_NAME STREQUAL "load")
7473
# Example 2. Load `add_one_cpu` shared library in C
7574
add_executable(load src/load.c)
76-
target_link_libraries(load PRIVATE tvm_ffi_header)
77-
target_link_libraries(load PRIVATE tvm_ffi_shared)
75+
target_link_libraries(load PRIVATE tvm_ffi::header tvm_ffi::shared)
7876
set_target_properties(
7977
load
8078
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/"

0 commit comments

Comments
 (0)