| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| if(NOT TensorRT_FIND_COMPONENTS) |
| set(TensorRT_FIND_COMPONENTS nvinfer nvinfer_plugin nvonnxparser nvparsers) |
| endif() |
| set(TensorRT_LIBRARIES) |
|
|
| |
| find_path( |
| TensorRT_INCLUDE_DIR |
| NAMES NvInfer.h |
| PATHS ${TensorRT_ROOT} ENV TensorRT_ROOT |
| PATH_SUFFIXES include |
| ) |
|
|
| string(FIND ${TensorRT_INCLUDE_DIR} "NOTFOUND" _include_dir_notfound) |
| if(NOT _include_dir_notfound EQUAL -1) |
| if(TensorRT_FIND_REQUIRED) |
| message(FATAL_ERROR "Fail to find TensorRT, please set TensorRT_ROOT. Include path not found.") |
| endif() |
| return() |
| endif() |
| set(TensorRT_INCLUDE_DIRS ${TensorRT_INCLUDE_DIR}) |
|
|
| |
| if(EXISTS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h") |
| file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_MAJOR REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$") |
| file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_MINOR REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$") |
| file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_PATCH REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$") |
| file(STRINGS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_TWEAK REGEX "^#define NV_TENSORRT_BUILD [0-9]+.*$") |
|
|
| string(REGEX REPLACE "^#define NV_TENSORRT_MAJOR ([0-9]+).*$" "\\1" TensorRT_VERSION_MAJOR "${TensorRT_MAJOR}") |
| string(REGEX REPLACE "^#define NV_TENSORRT_MINOR ([0-9]+).*$" "\\1" TensorRT_VERSION_MINOR "${TensorRT_MINOR}") |
| string(REGEX REPLACE "^#define NV_TENSORRT_PATCH ([0-9]+).*$" "\\1" TensorRT_VERSION_PATCH "${TensorRT_PATCH}") |
| string(REGEX REPLACE "^#define NV_TENSORRT_BUILD ([0-9]+).*$" "\\1" TensorRT_VERSION_TWEAK "${TensorRT_TWEAK}") |
| set(TensorRT_VERSION "${TensorRT_VERSION_MAJOR}.${TensorRT_VERSION_MINOR}.${TensorRT_VERSION_PATCH}.${TensorRT_VERSION_TWEAK}") |
| endif() |
|
|
| function(_find_trt_component component) |
|
|
| |
| find_library( |
| TensorRT_${component}_LIBRARY |
| NAMES ${component} |
| PATHS ${TensorRT_ROOT} ${TENSORRT_LIBRARY_DIR} ENV TensorRT_ROOT |
| ) |
|
|
| string(FIND ${TensorRT_${component}_LIBRARY} "NOTFOUND" _library_not_found) |
|
|
| if(NOT TensorRT_LIBRARY_DIR) |
| get_filename_component(_path ${TensorRT_${component}_LIBRARY} DIRECTORY) |
| set(TensorRT_LIBRARY_DIR |
| "${_path}" |
| CACHE INTERNAL "TensorRT_LIBRARY_DIR" |
| ) |
| endif() |
|
|
| if(NOT TensorRT_LIBRARY_DIRS) |
| get_filename_component(_path ${TensorRT_${component}_LIBRARY} DIRECTORY) |
| set(TensorRT_LIBRARY_DIRS |
| "${_path}" |
| CACHE INTERNAL "TensorRT_LIBRARY_DIRS" |
| ) |
| endif() |
|
|
| |
| if(_library_not_found EQUAL -1 AND NOT TARGET trt::${component}) |
| set(TensorRT_${component}_FOUND |
| TRUE |
| CACHE INTERNAL "Found ${component}" |
| ) |
|
|
| |
| add_library(trt::${component} IMPORTED INTERFACE) |
| target_include_directories(trt::${component} SYSTEM INTERFACE "${TensorRT_INCLUDE_DIRS}") |
| target_link_libraries(trt::${component} INTERFACE "${TensorRT_${component}_LIBRARY}") |
| set(TensorRT_LIBRARIES ${TensorRT_LIBRARIES} ${TensorRT_${component}_LIBRARY}) |
| endif() |
|
|
| endfunction() |
|
|
| |
| foreach(component IN LISTS TensorRT_FIND_COMPONENTS) |
| _find_trt_component(${component}) |
| endforeach() |
|
|
| include(FindPackageHandleStandardArgs) |
| find_package_handle_standard_args(TensorRT HANDLE_COMPONENTS VERSION_VAR TensorRT_VERSION REQUIRED_VARS TensorRT_INCLUDE_DIR) |
|
|
|
|