1515# limitations under the License.
1616#
1717
18- cmake_minimum_required (VERSION 3.13 FATAL_ERROR )
18+ cmake_minimum_required (VERSION 3.31 FATAL_ERROR )
1919include (cmake/modules/set_ifndef.cmake )
2020include (cmake/modules/find_library_create_target.cmake )
2121list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR } /cmake/modules)
@@ -24,13 +24,10 @@ set_ifndef(TRT_LIB_DIR ${CMAKE_BINARY_DIR})
2424set_ifndef (TRT_OUT_DIR ${CMAKE_BINARY_DIR } )
2525
2626# Converts Windows paths
27- if (CMAKE_VERSION VERSION_LESS 3.20)
28- file (TO_CMAKE_PATH "${TRT_LIB_DIR} " TRT_LIB_DIR )
29- file (TO_CMAKE_PATH "${TRT_OUT_DIR} " TRT_OUT_DIR )
30- else ()
31- cmake_path (SET TRT_LIB_DIR ${TRT_LIB_DIR} )
32- cmake_path (SET TRT_OUT_DIR ${TRT_OUT_DIR} )
33- endif ()
27+ cmake_path (SET TRT_LIB_DIR ${TRT_LIB_DIR} )
28+ cmake_path (SET TRT_OUT_DIR ${TRT_OUT_DIR} )
29+
30+ cmake_path (SET TRT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR } /include )
3431
3532# Required to export symbols to build *.libs
3633if (WIN32 )
4845 set (STATIC_LIB_EXT "a" )
4946endif ()
5047
51- file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR } /include /NvInferVersion.h" VERSION_STRINGS REGEX "#define TRT_.*_ENTERPRISE" )
48+ file (STRINGS "${TRT_INCLUDE_DIR} /NvInferVersion.h" VERSION_STRINGS REGEX "#define TRT_.*_ENTERPRISE" )
5249
5350foreach (TYPE MAJOR MINOR PATCH BUILD)
5451 string (REGEX MATCH "TRT_${TYPE} _ENTERPRISE [0-9]+" TRT_TYPE_STRING ${VERSION_STRINGS} )
@@ -65,45 +62,16 @@ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
6562endif ()
6663
6764set (CMAKE_SKIP_BUILD_RPATH True )
65+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
6866
69- # CUDA targets
70- set (DEFAULT_CUDA_VERSION 13.2)
71- set_ifndef (CUDA_VERSION ${DEFAULT_CUDA_VERSION} )
72- message (STATUS "CUDA version set to ${CUDA_VERSION} " )
73-
74- if (DEFINED GPU_ARCHS)
75- message (STATUS "GPU_ARCHS defined as ${GPU_ARCHS} . Generating CUDA code for SM ${GPU_ARCHS} " )
76- separate_arguments (GPU_ARCHS )
77- foreach (SM IN LISTS GPU_ARCHS)
78- list (APPEND CMAKE_CUDA_ARCHITECTURES "${SM} " )
79- endforeach ()
80- else ()
81- list (APPEND CMAKE_CUDA_ARCHITECTURES 75 80 86 87 89 90)
82-
83- if (CUDA_VERSION VERSION_GREATER_EQUAL 12.8)
84- list (APPEND CMAKE_CUDA_ARCHITECTURES 100 120)
85- endif ()
86-
87- if (CUDA_VERSION VERSION_GREATER_EQUAL 13.0)
88- list (APPEND CMAKE_CUDA_ARCHITECTURES 110)
67+ if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
68+ set (CMAKE_CUDA_ARCHITECTURES 80 86 89 90 100 120)
69+ # SM 110 (Thor) requires CUDA 13.0+.
70+ if (DEFINED CUDA_VERSION AND CUDA_VERSION VERSION_GREATER_EQUAL "13.0" )
71+ list (APPEND CMAKE_CUDA_ARCHITECTURES 110)
8972 endif ()
90- message (STATUS "GPU_ARCHS is not defined. Generating CUDA code for default SMs: ${CMAKE_CUDA_ARCHITECTURES} " )
91- endif ()
92- set (BERT_GENCODES)
93- # Generate SASS for each architecture
94- foreach (arch ${CMAKE_CUDA_ARCHITECTURES} )
95- if (${arch} GREATER_EQUAL 75 AND NOT ${arch} EQUAL 110)
96- set (BERT_GENCODES "${BERT_GENCODES} -gencode arch=compute_${arch} ,code=sm_${arch} " )
97- endif ()
98- set (GENCODES "${GENCODES} -gencode arch=compute_${arch} ,code=sm_${arch} " )
99- endforeach ()
100-
101- # Generate PTX for the last architecture in the list.
102- list (GET CMAKE_CUDA_ARCHITECTURES -1 LATEST_SM)
103- set (GENCODES "${GENCODES} -gencode arch=compute_${LATEST_SM} ,code=compute_${LATEST_SM} " )
104- if (${LATEST_SM} GREATER_EQUAL 75 AND NOT ${arch} EQUAL 110)
105- set (BERT_GENCODES "${BERT_GENCODES} -gencode arch=compute_${LATEST_SM} ,code=compute_${LATEST_SM} " )
10673endif ()
74+ message (STATUS "Generating CUDA code for SMs: ${CMAKE_CUDA_ARCHITECTURES} " )
10775
10876project (TensorRT
10977 LANGUAGES CXX CUDA
@@ -124,6 +92,7 @@ option(BUILD_PARSERS "Build TensorRT parsers" ON)
12492option (BUILD_SAMPLES "Build TensorRT samples" ON )
12593option (BUILD_SAFE_SAMPLES "Build TensorRT safety samples" OFF )
12694option (TRT_SAFETY_INFERENCE_ONLY "Build only the safety inference components (no safety builders)" OFF )
95+ option (TRT_BUILD_TESTING "Build gtests for TensorRT components" OFF )
12796
12897############################################################################################
12998# Early dependency discovery
@@ -141,14 +110,8 @@ else()
141110 endif ()
142111endif ()
143112
144- ## find_package(CUDA) is broken for cross-compilation. Enable CUDA language instead.
145- if (NOT DEFINED CMAKE_TOOLCHAIN_FILE )
146- find_package (CUDA ${CUDA_VERSION} REQUIRED )
147- endif ()
148-
149- include_directories (
150- ${CUDA_INCLUDE_DIRS}
151- )
113+ find_package (CUDAToolkit REQUIRED )
114+ message (STATUS "CUDA version: ${CUDAToolkit_VERSION} " )
152115
153116############################################################################################
154117# Safety runtime libraries (libnvinfer_safe) used by safety samples and
@@ -204,8 +167,6 @@ if(BUILD_SAFE_SAMPLES OR TRT_SAFETY_INFERENCE_ONLY)
204167 target_link_options (TRTSAFE::nvinfer_safe_shared INTERFACE LINKER:--unresolved-symbols=ignore-in-shared-libs )
205168 target_link_options (TRTSAFE::nvinfer_safe_debug INTERFACE LINKER:--unresolved-symbols=ignore-in-shared-libs )
206169 endif ()
207- # Enable unified builder safety features when building safety samples or in inference-only mode.
208- add_compile_definitions (ENABLE_UNIFIED_BUILDER=1 )
209170endif ()
210171
211172# OSS safety inference-only mode: require safety samples and disable enterprise
@@ -223,8 +184,8 @@ if(TRT_SAFETY_INFERENCE_ONLY)
223184 set (BUILD_SAMPLES OFF CACHE BOOL "" FORCE )
224185
225186 # Add CUDA library directory early so all samples can find it
226- if (CUDA_TOOLKIT_ROOT_DIR )
227- link_directories (${CUDA_TOOLKIT_ROOT_DIR} /lib64 ${CUDA_TOOLKIT_ROOT_DIR} /lib ${CUDA_TOOLKIT_ROOT_DIR} /targets/x86_64-linux/lib )
187+ if (CUDAToolkit_LIBRARY_DIR )
188+ link_directories (${CUDAToolkit_LIBRARY_DIR} )
228189 endif ()
229190
230191 # Interface target for safety samples in inference-only mode.
@@ -240,10 +201,10 @@ if(TRT_SAFETY_INFERENCE_ONLY)
240201 target_link_libraries (trt_global_definitions INTERFACE dl rt )
241202 endif ()
242203 target_include_directories (trt_global_definitions INTERFACE
243- ${CMAKE_CURRENT_SOURCE_DIR } /include
204+ ${TRT_INCLUDE_DIR}
244205 ${CMAKE_CURRENT_SOURCE_DIR } /samples/common
245206 ${CMAKE_CURRENT_SOURCE_DIR } /shared
246- ${CUDA_INCLUDE_DIRS }
207+ ${CUDAToolkit_INCLUDE_DIRS }
247208 )
248209 target_compile_options (trt_global_definitions INTERFACE
249210 $<$<COMPILE_LANGUAGE :CUDA >:--expt -relaxed -constexpr >
@@ -290,12 +251,6 @@ message(STATUS "Protobuf version set to ${PROTOBUF_VERSION}")
290251if (BUILD_PLUGINS OR BUILD_PARSERS)
291252 include (third_party/protobuf.cmake )
292253endif ()
293- if (NOT CUB_ROOT_DIR)
294- if (CUDA_VERSION VERSION_LESS 11.0)
295- set (CUB_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR } /third_party/cub CACHE STRING "directory of CUB installation" )
296- endif ()
297- endif ()
298-
299254if (BUILD_PARSERS)
300255 configure_protobuf (${PROTOBUF_VERSION} )
301256endif ()
@@ -320,36 +275,12 @@ endif()
320275
321276find_library_create_target (nvinfer ${nvinfer_lib_name} SHARED "${TRT_LIB_DIR} " )
322277
323- if (DEFINED USE_CUGFX)
324- find_library (CUDART_LIB cugfx_dll HINTS ${CUDA_TOOLKIT_ROOT_DIR} PATH_SUFFIXES lib lib/x64 lib64 )
325- else ()
326- # DriveOS platforms use cudart.so instead of cudart_static. This isn't the most sophisticated check, but it's correct.
327- if (CUDA_VERSION VERSION_GREATER_EQUAL 12.0)
328- set (CUDART_LIB_NAME cudart_static)
329- set (CMAKE_CUDA_RUNTIME_LIBRARY "static" )
330- else ()
331- set (CUDART_LIB_NAME cudart)
332- set (CMAKE_CUDA_RUNTIME_LIBRARY "shared" )
333- endif ()
334-
335- # SafeCUDA (QNX-Safe) does not ship libcudadevrt. When CMAKE_CUDA_RUNTIME_LIBRARY
336- # is "shared" or "static", CMake automatically links -lcudadevrt for targets with
337- # CUDA sources, which breaks QNX-Safe cross-compilation. Setting it to "None"
338- # disables automatic CUDA runtime linking; cudart is still linked manually via
339- # trt_global_definitions.
340- if (TRT_SAFETY_INFERENCE_ONLY AND CMAKE_SYSTEM_NAME STREQUAL "QNX" )
341- set (CMAKE_CUDA_RUNTIME_LIBRARY "None" )
342- endif ()
343-
344- find_library (CUDART_LIB ${CUDART_LIB_NAME} HINTS ${CUDA_TOOLKIT_ROOT_DIR} PATH_SUFFIXES lib lib/x64 lib64 )
345- endif ()
278+ set (CMAKE_CUDA_RUNTIME_LIBRARY "static" CACHE STRING "" )
346279
347280if (NOT MSVC )
348281 find_library (RT_LIB rt )
349282endif ()
350283
351- set (CUDA_LIBRARIES ${CUDART_LIB} )
352-
353284############################################################################################
354285
355286if (NOT MSVC )
@@ -376,11 +307,62 @@ else()
376307 find_library_create_target (${nvonnxparser_lib_name} ${nvonnxparser_lib_name} SHARED "${HINT_PATHS} " )
377308endif ()
378309
379- # Samples:
380- # - BUILD_SAMPLES controls the regular (enterprise/OSS) samples via
381- # samples/CMakeLists.txt.
382- # - BUILD_SAFE_SAMPLES controls the safety samples (builder + infer parts).
383- # Both can be enabled at the same time if desired.
310+ if (NOT TARGET trt_global_definitions)
311+ add_library (trt_global_definitions INTERFACE )
312+ target_include_directories (trt_global_definitions INTERFACE ${CUDAToolkit_INCLUDE_DIRS} )
313+ endif ()
314+
315+ add_library (tensorrt_headers INTERFACE )
316+ target_include_directories (tensorrt_headers INTERFACE ${TRT_INCLUDE_DIR} )
317+
318+ # Samples
384319if (BUILD_SAMPLES OR BUILD_SAFE_SAMPLES)
320+ set (TRT_BUILD_ENABLE_NEW_SAMPLES_FLOW ON )
321+
322+ # Map OSS option names to the internal names used by samples/CMakeLists.txt.
323+ set (TRT_BUILD_SAMPLES ${BUILD_SAMPLES} )
324+ set (TRT_BUILD_TRTEXEC ${BUILD_SAMPLES} )
325+ set (TRT_BUILD_ONNX_PARSER ${BUILD_PARSERS} )
326+ set (TRT_BUILD_PLUGINS ${BUILD_PLUGINS} )
327+
328+ # Set defaults for specific feature enablement for samples.
329+ option (TRT_BUILD_ENABLE_DLA "Build TensorRT with DLA features enabled." OFF )
330+ option (TRT_BUILD_ENABLE_UNIFIED_BUILDER "Build TensorRT with unified builder (safety) features enabled." ${BUILD_SAFE_SAMPLES} )
331+ option (TRT_BUILD_WINML "Build TensorRT with WinML support." OFF )
332+ option (TRT_BUILD_ENABLE_MULTIDEVICE "Build TensorRT with multi-device support." OFF )
333+ set (TRT_BUILD_SAMPLES_LINK_STATIC_TRT OFF CACHE INTERNAL "" )
334+
335+ find_library (NVINFER_LIB nvinfer PATHS ${TRT_LIB_DIR} REQUIRED )
336+ add_library (tensorrt INTERFACE IMPORTED )
337+ target_link_libraries (tensorrt INTERFACE ${NVINFER_LIB} )
338+ target_include_directories (tensorrt INTERFACE ${TRT_INCLUDE_DIR} )
339+
340+ target_include_directories (${nvonnxparser_lib_name} INTERFACE ${TRT_INCLUDE_DIR} )
341+
342+ add_subdirectory (shared )
343+
344+ include (InstallUtils )
345+
346+ if (TRT_BUILD_TESTING)
347+ find_package (GTest QUIET )
348+ if (GTest_FOUND)
349+ if (NOT TARGET gtest_main)
350+ add_library (gtest_main ALIAS GTest::gtest_main )
351+ endif ()
352+ else ()
353+ include (FetchContent )
354+ FetchContent_Declare (
355+ googletest
356+ GIT_REPOSITORY https://github.com/google/googletest.git
357+ GIT_TAG v1.14.0
358+ )
359+ FetchContent_MakeAvailable (googletest)
360+ endif ()
361+ set (TRT_GTEST_DISCOVERY_MODE PRE_TEST CACHE STRING "gtest discovery mode." )
362+ endif ()
363+
364+ # Route sample binaries to TRT_OUT_DIR.
365+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TRT_OUT_DIR} )
366+
385367 add_subdirectory (samples )
386368endif ()
0 commit comments