Warning, /acts/cmake/FindTensorRT.cmake is written in an unsupported language. File is not indexed.
0001 # ~~~
0002 # Locate the TensorRT runtime.
0003 #
0004 # ACTS only ever deserializes pre-built ``.engine`` files, so this module
0005 # deliberately looks for the runtime libraries only. The graph parsers
0006 # (``nvonnxparser``, ``nvparsers``) are not searched for: building an engine
0007 # from ONNX is an offline step performed outside of ACTS, and ``nvparsers`` no
0008 # longer ships as of TensorRT 10.
0009 #
0010 # This module defines the following variables:
0011 #
0012 # - TensorRT_FOUND: A boolean specifying whether or not TensorRT was found.
0013 # - TensorRT_VERSION: The exact version of TensorRT found.
0014 # - TensorRT_INCLUDE_DIRS: The path to the TensorRT ``include`` folder.
0015 # - TensorRT_LIBRARY_DIRS: The path to the TensorRT library directory.
0016 #
0017 # This module creates the following targets:
0018 #
0019 # - trt::nvinfer
0020 # - trt::nvinfer_plugin
0021 #
0022 # Hints
0023 # ^^^^^
0024 # A user may set ``TensorRT_ROOT`` to an installation root to tell this module
0025 # where to look.
0026 # ~~~
0027
0028 find_path(
0029 TensorRT_INCLUDE_DIR
0030 NAMES NvInfer.h
0031 HINTS ${TensorRT_ROOT}
0032 ENV TensorRT_ROOT
0033 PATH_SUFFIXES include
0034 )
0035
0036 if(EXISTS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h")
0037 file(READ "${TensorRT_INCLUDE_DIR}/NvInferVersion.h" _trt_version_header)
0038 set(_trt_version_parts)
0039 foreach(_part MAJOR MINOR PATCH BUILD)
0040 string(
0041 REGEX MATCH "NV_TENSORRT_${_part}[ \t]+([0-9]+)"
0042 _trt_version_match
0043 "${_trt_version_header}"
0044 )
0045 list(APPEND _trt_version_parts "${CMAKE_MATCH_1}")
0046 endforeach()
0047 list(JOIN _trt_version_parts "." TensorRT_VERSION)
0048 unset(_trt_version_header)
0049 unset(_trt_version_parts)
0050 unset(_trt_version_match)
0051 endif()
0052
0053 foreach(_component nvinfer nvinfer_plugin)
0054 find_library(
0055 TensorRT_${_component}_LIBRARY
0056 NAMES ${_component}
0057 HINTS ${TensorRT_ROOT}
0058 ENV TensorRT_ROOT
0059 PATH_SUFFIXES lib lib64
0060 )
0061 mark_as_advanced(TensorRT_${_component}_LIBRARY)
0062 endforeach()
0063
0064 include(FindPackageHandleStandardArgs)
0065 find_package_handle_standard_args(
0066 TensorRT
0067 REQUIRED_VARS
0068 TensorRT_INCLUDE_DIR
0069 TensorRT_nvinfer_LIBRARY
0070 TensorRT_nvinfer_plugin_LIBRARY
0071 VERSION_VAR TensorRT_VERSION
0072 )
0073
0074 if(TensorRT_FOUND)
0075 set(TensorRT_INCLUDE_DIRS "${TensorRT_INCLUDE_DIR}")
0076
0077 # Cached because ActsCreateSetup substitutes this into the setup scripts from
0078 # the top-level scope, while find_package(TensorRT) runs down in Plugins/Gnn.
0079 get_filename_component(
0080 _trt_library_dir
0081 "${TensorRT_nvinfer_LIBRARY}"
0082 DIRECTORY
0083 )
0084 set(TensorRT_LIBRARY_DIRS
0085 "${_trt_library_dir}"
0086 CACHE INTERNAL
0087 "TensorRT library directory"
0088 )
0089 unset(_trt_library_dir)
0090
0091 foreach(_component nvinfer nvinfer_plugin)
0092 if(NOT TARGET trt::${_component})
0093 # Imported targets treat their interface includes as SYSTEM by
0094 # default, which keeps the TensorRT headers from tripping -Werror.
0095 add_library(trt::${_component} UNKNOWN IMPORTED)
0096 set_target_properties(
0097 trt::${_component}
0098 PROPERTIES
0099 IMPORTED_LOCATION "${TensorRT_${_component}_LIBRARY}"
0100 INTERFACE_INCLUDE_DIRECTORIES "${TensorRT_INCLUDE_DIRS}"
0101 )
0102 endif()
0103 endforeach()
0104 endif()
0105
0106 mark_as_advanced(TensorRT_INCLUDE_DIR)