chore: import upstream snapshot with attribution
Docker Image CI / build-ubuntu2004 (push) Has been cancelled
Docker Image CI / build-ubuntu2004 (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
|
||||
# This file handles logic relating to building "fat" static libraries, that is, ones which contain other static libraries.
|
||||
# Idiomatically, CMake would prefer we ship all static libraries as part of our release and ship a file which specifies the linkages.
|
||||
# However, for various reasons, this is both inadvisable and annoying. Instead, we would prefer to ship one static library containing all dependencies.
|
||||
#
|
||||
# To do that, we need rules to bundle static libraries into other static libraries. Hence, this class.
|
||||
|
||||
define_property(TARGET
|
||||
PROPERTY BUNDLED_LIBRARY_TEMPLATE_PATH
|
||||
BRIEF_DOCS "File path to the template script which will be written to when calling target_bundle_libraries."
|
||||
)
|
||||
|
||||
define_property(TARGET
|
||||
PROPERTY BUNDLE_LIBRARIES
|
||||
BRIEF_DOCS "The list of libraries that have been bundled into this target by target_bundle_libraries."
|
||||
)
|
||||
|
||||
define_property(TARGET
|
||||
PROPERTY BUNDLE_LIBRARY_KNOWN_TYPE
|
||||
BRIEF_DOCS "Fallback type used when a target's TYPE is UNKNOWN_LIBRARY."
|
||||
)
|
||||
|
||||
define_property(TARGET
|
||||
PROPERTY BUNDLE_VISITED_INTERFACES
|
||||
BRIEF_DOCS "Interface libraries already traversed by __bundleRecursiveDeps for this target."
|
||||
)
|
||||
|
||||
# Internal helper to prefix all messages with "[target_bundle_libraries]: ".
|
||||
#
|
||||
# \param mode The message mode to be passed to message(...)
|
||||
# \param argn The message contents.
|
||||
macro(__bundleMessage mode)
|
||||
message(${mode} "[target_bundle_libraries]: " ${ARGN})
|
||||
endmacro()
|
||||
|
||||
# Illegal genex magic™
|
||||
# Given a string containing a generator expression (var), edits the variable in-place to escape any generator expression literals.
|
||||
# The escaped generator expression is then suitable for use within a LIST:TRANSFORM replacement block.
|
||||
# This more or less allows for mapping lists to generator expressions, which can be recursively evaluated.
|
||||
function(escape_generator_expression var)
|
||||
string(REPLACE ">" "__ANGLE_R__" ${var} "${${var}}")
|
||||
string(REPLACE "$" "$<1:$>" ${var} "${${var}}")
|
||||
string(REPLACE "," "$<COMMA>" ${var} "${${var}}")
|
||||
string(REPLACE "__ANGLE_R__" "$<ANGLE-R>" ${var} "${${var}}")
|
||||
return(PROPAGATE ${var})
|
||||
endfunction()
|
||||
|
||||
# Recursively unwraps alias targets until finding the real target. Non-targets are returned verbatim.
|
||||
# We need to ensure that the generated .mri script contains a deduplicated list of bundled targets
|
||||
# so we need to resolve aliases, otherwise we may end up with multiple entries for the same target.
|
||||
#
|
||||
# \param target_name The name of the target to unwrap.
|
||||
# \param result_var The variable to store the unwrapped target name in.
|
||||
function(unwrapAlias target_name result_var)
|
||||
# Check cache first (keyed on the raw input string).
|
||||
get_property(_cache_set GLOBAL PROPERTY _UNWRAP_ALIAS_CACHE_${target_name} SET)
|
||||
if(_cache_set)
|
||||
get_property(_cached GLOBAL PROPERTY _UNWRAP_ALIAS_CACHE_${target_name})
|
||||
set(${result_var} ${_cached} PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# First, try to unwrap common generator expressions that may wrap the target name.
|
||||
string(REGEX MATCH "\\$<LINK_LIBRARY:WHOLE_ARCHIVE,([a-zA-Z0-9_.:]+)>" _ ${target_name})
|
||||
if(TARGET ${CMAKE_MATCH_1})
|
||||
set(target_name ${CMAKE_MATCH_1})
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "\\$<LINK_ONLY:([a-zA-Z0-9_.:]+)>" _ ${target_name})
|
||||
if(TARGET ${CMAKE_MATCH_1})
|
||||
set(target_name ${CMAKE_MATCH_1})
|
||||
endif()
|
||||
|
||||
if(TARGET ${target_name})
|
||||
get_target_property(aliased_target ${target_name} ALIASED_TARGET)
|
||||
if(aliased_target)
|
||||
# Recursively unwrap in case there are multiple levels
|
||||
unwrapAlias(${aliased_target} unwrapped)
|
||||
set(_result ${unwrapped})
|
||||
else()
|
||||
# Not an alias, return the original name
|
||||
set(_result ${target_name})
|
||||
endif()
|
||||
else()
|
||||
# Not a target at all, return the original name
|
||||
set(_result ${target_name})
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY _UNWRAP_ALIAS_CACHE_${target_name} ${_result})
|
||||
set(${result_var} ${_result} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Internal function to retrieve the type of library for a given target.
|
||||
# This function will fallback to the value of BUNDLE_LIBRARY_KNOWN_TYPE if it encounters an UNKNOWN_LIBRARY.
|
||||
#
|
||||
# \param lib A target to evaluate the type for.
|
||||
# \param outVar The output variable to store the type name in.
|
||||
function(__get_lib_type lib outVar)
|
||||
get_target_property(libType ${lib} TYPE)
|
||||
if (${libType} STREQUAL UNKNOWN_LIBRARY)
|
||||
get_target_property(knownType ${lib} BUNDLE_LIBRARY_KNOWN_TYPE)
|
||||
if (NOT ${knownType} STREQUAL "knownType-NOTFOUND")
|
||||
set(libType ${knownType})
|
||||
endif()
|
||||
__bundleMessage(DEBUG "Using known type of unknown library ${lib}: ${knownType}")
|
||||
endif()
|
||||
set(${outVar} ${libType} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This is an internal-only function called the first time that target_bundle_libraries is called.
|
||||
# It "registers" a target for bundling by creating the base template file and populating the target property BUNDLED_LIBRARY_TEMPLATE_PATH.
|
||||
# Additionally, it registers the file generation logic for making the "final" script, as well as the custom command for running it after the build.
|
||||
#
|
||||
# \param lib The mainLib from target_bundle_libraries.
|
||||
# \param templatePath The file path to the template file that will be created.
|
||||
function(__registerTargetForBundling lib templatePath)
|
||||
if(MSVC)
|
||||
set(scriptPath $<TARGET_FILE_DIR:${lib}>/archive-${lib}.bat)
|
||||
|
||||
set(template "/OUT:\"$<TARGET_FILE:${lib}>\" \"$<TARGET_FILE:${lib}>\"\n")
|
||||
|
||||
# Windows-syntax version of the same logic from the linux build below.
|
||||
# Main differences is that windows does not have `addlib`, and uses `\n` instead of `\n`. Additionally, the values need to be quoted to account for spaces in file paths.
|
||||
set(replaceExpr "\"$<IF:$<TARGET_EXISTS:\\1>,$<TARGET_FILE:\\1>,\\1>\"")
|
||||
escape_generator_expression(replaceExpr)
|
||||
string(APPEND template "$<TARGET_GENEX_EVAL:${lib},$<JOIN:$<LIST:TRANSFORM,$<TARGET_PROPERTY:${lib},BUNDLE_LIBRARIES>,REPLACE,(.+),${replaceExpr}>,\n>>\n")
|
||||
|
||||
file(WRITE ${templatePath} ${template})
|
||||
file(GENERATE
|
||||
OUTPUT ${scriptPath}
|
||||
INPUT ${templatePath}
|
||||
)
|
||||
add_custom_command(TARGET ${lib} POST_BUILD
|
||||
COMMAND ${CMAKE_AR} /NOLOGO @\"${scriptPath}\"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Bundled $<LIST:LENGTH,$<TARGET_PROPERTY:${lib},BUNDLE_LIBRARIES>> static libraries into target ${lib}. Script: ${scriptPath}"
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:${lib}>
|
||||
)
|
||||
else()
|
||||
set(scriptPath $<TARGET_FILE_DIR:${lib}>/archive-${lib}.mri)
|
||||
|
||||
set(template "create $<TARGET_FILE:${lib}>\n")
|
||||
string(APPEND template "addlib $<TARGET_FILE:${lib}>\n")
|
||||
# Expand BUNDLE_LIBRARIES into the appropriate chain of addlib commands needed.
|
||||
# BUNDLE_LIBRARIES will contain either (a) target names or (b) absolute file paths to libraries to include.
|
||||
# This first part will disambiguate between (a) and (b) by evaluating (a) to `addlib $<TARGET_FILE:lib>` and (b) to `addlib [[filepath]]`
|
||||
set(replaceExpr "addlib $<IF:$<TARGET_EXISTS:\\1>,$<TARGET_FILE:\\1>,\\1>")
|
||||
escape_generator_expression(replaceExpr)
|
||||
|
||||
# The second part maps every element in BUNDLE_LIBRARIES to `replaceExpr` and evaluates the resulting replacement, which produces the final .mri file.
|
||||
string(APPEND template "$<TARGET_GENEX_EVAL:${lib},$<JOIN:$<LIST:TRANSFORM,$<TARGET_PROPERTY:${lib},BUNDLE_LIBRARIES>,REPLACE,(.+),${replaceExpr}>,\n>>\n")
|
||||
string(APPEND template "save\n")
|
||||
string(APPEND template "end\n")
|
||||
|
||||
file(WRITE ${templatePath} ${template})
|
||||
file(GENERATE
|
||||
OUTPUT ${scriptPath}
|
||||
INPUT ${templatePath}
|
||||
)
|
||||
|
||||
add_custom_command(TARGET ${lib} POST_BUILD
|
||||
COMMAND ${CMAKE_AR} -M < ${scriptPath}
|
||||
COMMAND ${CMAKE_RANLIB} $<TARGET_FILE:${lib}>
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Bundled $<LIST:LENGTH,$<TARGET_PROPERTY:${lib},BUNDLE_LIBRARIES>> static libraries into target ${lib}. Script: ${scriptPath}"
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:${lib}>
|
||||
)
|
||||
endif()
|
||||
|
||||
set_target_properties(${lib}
|
||||
PROPERTIES BUNDLED_LIBRARY_TEMPLATE_PATH ${templatePath}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# Subcomponent of target_bundle_libraries which is responsible for walking the provided depLibs and recursively calling target_bundle_libraries.
|
||||
# This macro must only be used within target_bundle_libraries.
|
||||
#
|
||||
# \param mainLib The current main library from target_bundle_libraries
|
||||
# \param linkVis The link visibility from target_bundle_libraries
|
||||
# \param argn The dependencies to walk. Usually the INTERFACE_LINK_LIBRARIES of a target currently being bundled.
|
||||
function(__bundleRecursiveDeps mainLib linkVis)
|
||||
if(ARGN)
|
||||
get_target_property(bundledLibs ${mainLib} BUNDLE_LIBRARIES)
|
||||
|
||||
foreach(dep IN LISTS ARGN)
|
||||
unwrapAlias(${dep} dep)
|
||||
if(${dep} IN_LIST bundledLibs)
|
||||
continue() # Skip bundling of already-bundled libs to avoid many invocations of the same warnings.
|
||||
endif()
|
||||
|
||||
if(TARGET ${dep})
|
||||
__get_lib_type(${dep} depType)
|
||||
if (${depType} STREQUAL STATIC_LIBRARY)
|
||||
target_bundle_libraries(${mainLib} ${linkVis} ${dep})
|
||||
elseif(${depType} STREQUAL INTERFACE_LIBRARY)
|
||||
# For interface libraries, we want to add all of the static libraries they may be pointing to, without the library itself (since it is not a static).
|
||||
# Skip if we've already traversed this interface lib's deps for mainLib to avoid re-walking shared transitive subtrees.
|
||||
get_target_property(_visited ${mainLib} BUNDLE_VISITED_INTERFACES)
|
||||
if(NOT _visited)
|
||||
set(_visited "")
|
||||
endif()
|
||||
if(${dep} IN_LIST _visited)
|
||||
continue()
|
||||
endif()
|
||||
set_property(TARGET ${mainLib} APPEND PROPERTY BUNDLE_VISITED_INTERFACES ${dep})
|
||||
get_target_property(interfaceLibs ${dep} INTERFACE_LINK_LIBRARIES)
|
||||
__bundleRecursiveDeps(${mainLib} ${linkVis} ${interfaceLibs})
|
||||
elseif(${depType} STREQUAL SHARED_LIBRARY)
|
||||
# Skip SO's, since static libraries at the SO-boundary should not be bundled into the target mainLib.
|
||||
else()
|
||||
__bundleMessage(DEBUG "Skipping unhandled dependency ${dep} (a dependency of ${bundledLib}) with type ${depType} in ${mainLib}")
|
||||
endif()
|
||||
else()
|
||||
__bundleMessage(DEBUG "Failed to recursively bundle dependency ${dep} (a dependency of ${bundledLib}) in ${mainLib}")
|
||||
endif()
|
||||
endforEach()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# This function acts as a replacement target_link_libraries, instead linking
|
||||
# one or more "bundled" static libraries into a "main" static library.
|
||||
# The bundled libs are embedded inside the main lib during the post-build step.
|
||||
# CMake interface properties for definitions, etc. are propagated using the specified visibility.
|
||||
#
|
||||
# This function is recursive. Any static dependencies of any bundled library will also be bundled into the mainLib.
|
||||
#
|
||||
# \param mainLib The main library that other libraries are to be bundled into.
|
||||
# \param linkVis The link visiblity for interface properties. One of PRIVATE or PUBLIC.
|
||||
# Using PRIVATE hides all interface properties of bundled libraries from consumers of this library.
|
||||
# Using PUBLIC will share interface properties with dependents.
|
||||
# \param argn Variadic arguments - The list of targets to be linked into the mainLib.
|
||||
function(target_bundle_libraries mainLib linkVis)
|
||||
if (NOT ${linkVis} STREQUAL PUBLIC AND NOT ${linkVis} STREQUAL PRIVATE)
|
||||
__bundleMessage(FATAL_ERROR "Error: Called target_bundle_libraries with unknown visibility ${linkVis}. Must be either \"PUBLIC\" or \"PRIVATE\".")
|
||||
endif()
|
||||
|
||||
# TODO: Allow direct insertion of absolute file paths when CMAKE_LINK_LIBRARIES_ONLY_TARGETS is off, instead of always forcing targets.
|
||||
if (NOT TARGET ${mainLib})
|
||||
__bundleMessage(FATAL_ERROR "Error: Called target_bundle_libraries for target ${mainLib}, but no target with that name is known.")
|
||||
endif()
|
||||
|
||||
__get_lib_type(${mainLib} mainLibType)
|
||||
if (NOT mainLibType STREQUAL STATIC_LIBRARY)
|
||||
__bundleMessage(FATAL_ERROR "Error: Called target_bundle_libraries for target ${mainLib}, but it is not a static library.")
|
||||
endif()
|
||||
|
||||
get_target_property(isMainLibImported ${mainLib} IMPORTED)
|
||||
if(isMainLibImported)
|
||||
__bundleMessage(FATAL_ERROR "Error: Called target_bundle_libraries for target ${mainLib}, but it is an imported target.")
|
||||
endif()
|
||||
|
||||
if(NOT ARGN)
|
||||
__bundleMessage(WARNING "Called target_bundle_libraries with no libraries for target ${mainLib}")
|
||||
endif()
|
||||
|
||||
__bundleMessage(DEBUG "Bundling ${ARGN} into ${mainLib}")
|
||||
|
||||
get_target_property(templatePath ${mainLib} BUNDLED_LIBRARY_TEMPLATE_PATH)
|
||||
if(NOT EXISTS ${templatePath})
|
||||
if(MSVC)
|
||||
set(templatePath ${PROJECT_BINARY_DIR}/archive-${mainLib}.bat.template)
|
||||
else()
|
||||
set(templatePath ${PROJECT_BINARY_DIR}/archive-${mainLib}.mri.template)
|
||||
endif()
|
||||
__bundleMessage(STATUS "Registering default script path ${templatePath} for target ${mainLib}")
|
||||
__registerTargetForBundling(${mainLib} ${templatePath})
|
||||
endif()
|
||||
|
||||
get_target_property(bundledLibs ${mainLib} BUNDLE_LIBRARIES)
|
||||
if (NOT bundledLibs)
|
||||
set(bundledLibs "")
|
||||
endif()
|
||||
|
||||
foreach(bundledLib IN LISTS ARGN)
|
||||
unwrapAlias(${bundledLib} bundledLib)
|
||||
__get_lib_type(${bundledLib} bundledLibType)
|
||||
|
||||
if(${bundledLibType} STREQUAL INTERFACE_LIBRARY)
|
||||
# Interface libraries are not bundled, since they do not contain any static libraries.
|
||||
# Their dependencies will be bundled recursively in the next step.
|
||||
continue()
|
||||
endif()
|
||||
|
||||
if (NOT ${bundledLibType} STREQUAL STATIC_LIBRARY AND NOT ${bundledLibType} STREQUAL OBJECT_LIBRARY)
|
||||
__bundleMessage(FATAL_ERROR "Attempted to bundle ${bundledLibType} library ${bundledLib} into target ${mainLib} (only static and object libraries may be bundled)")
|
||||
endif()
|
||||
|
||||
if (${bundledLibType} STREQUAL STATIC_LIBRARY)
|
||||
list(APPEND bundledLibs ${bundledLib})
|
||||
else()
|
||||
# Exclude object libs from the BUNDLE_LIBRARIES property as they get added into the static lib using normal means.
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
list(REMOVE_DUPLICATES bundledLibs)
|
||||
set_target_properties(${mainLib}
|
||||
PROPERTIES BUNDLE_LIBRARIES "${bundledLibs}"
|
||||
)
|
||||
|
||||
foreach(bundledLib IN LISTS ARGN)
|
||||
unwrapAlias(${bundledLib} bundledLib)
|
||||
__get_lib_type(${bundledLib} bundledLibType)
|
||||
|
||||
# Recursively bundle all static dependencies of each lib to be bundled.
|
||||
get_target_property(depLibs ${bundledLib} LINK_LIBRARIES)
|
||||
__bundleRecursiveDeps(${mainLib} ${linkVis} ${depLibs})
|
||||
|
||||
# Since we want the main library to be linkable standalone, we need both the LINK_LIBRARIES and INTERFACE_LINK_LIBRARIES bundled in.
|
||||
# Otherwise, private static dependencies may be lost.
|
||||
get_target_property(depLibs ${bundledLib} INTERFACE_LINK_LIBRARIES)
|
||||
__bundleRecursiveDeps(${mainLib} ${linkVis} ${depLibs})
|
||||
|
||||
# Use `target_link_libraries` to propagate INTERFACE definitions from bundled libs
|
||||
# BUILD_LOCAL_INTERFACE prevents clients from seeing this internal link relationship
|
||||
# COMPILE_ONLY prevents the bundled lib from appearing in the link command redundantly
|
||||
if (${bundledLibType} STREQUAL STATIC_LIBRARY OR ${bundledLibType} STREQUAL INTERFACE_LIBRARY)
|
||||
target_link_libraries(${mainLib} ${linkVis}
|
||||
$<BUILD_LOCAL_INTERFACE:$<COMPILE_ONLY:${bundledLib}>>
|
||||
)
|
||||
else()
|
||||
# Include Object Libraries as full libraries, since they do not get added by the bundling stage.
|
||||
# To do this without breaking the link dependency logic, we need to steal the target objects and link the lib as local + compile only.
|
||||
target_link_libraries(${mainLib} ${linkVis}
|
||||
$<BUILD_LOCAL_INTERFACE:$<COMPILE_ONLY:${bundledLib}>>
|
||||
)
|
||||
target_sources(${mainLib} PRIVATE $<TARGET_OBJECTS:${bundledLib}>)
|
||||
endif()
|
||||
|
||||
# require that bundled libs are built before we try to bundle them
|
||||
add_dependencies(${mainLib} ${bundledLib})
|
||||
endforeach()
|
||||
|
||||
if(NOT EXISTS ${templatePath})
|
||||
__bundleMessage(FATAL_ERROR "Template file ${templatePath} for target ${mainLib} does not exist.")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,38 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
include_guard()
|
||||
|
||||
set(_cccl_default_repo "https://github.com/NVIDIA/cccl.git")
|
||||
|
||||
|
||||
set(CCCL_REPO ${_cccl_default_repo} CACHE STRING "The base project URL to FetchContent_Declare for CCCL" )
|
||||
set(CCCL_TAG "v3.4.0-rc0" CACHE STRING "The commit hash to FetchContent_Declare for CCCL")
|
||||
|
||||
# We use this directory to ensure we only fetch a single copy of dependencies, even between builds.
|
||||
# $HOME/storage is expected to be mounted from the host for developers.
|
||||
set(TRT_THIRD_PARTY_DL_DIR "$ENV{HOME}/storage" CACHE PATH "Directory to download third party dependencies to")
|
||||
|
||||
FetchContent_Declare(
|
||||
cccl
|
||||
PREFIX "${CMAKE_BINARY_DIR}/third_party/cccl"
|
||||
GIT_REPOSITORY ${CCCL_REPO}
|
||||
GIT_TAG ${CCCL_TAG}
|
||||
GIT_SHALLOW TRUE
|
||||
SOURCE_DIR "${TRT_THIRD_PARTY_DL_DIR}/cccl/${CCCL_TAG}"
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(cccl)
|
||||
@@ -0,0 +1,49 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
include_guard()
|
||||
|
||||
set(NLOHMANN_JSON_REPO "https://github.com/nlohmann/json.git" CACHE STRING "The base project URL to FetchContent_Declare for nlohmann/json")
|
||||
set(NLOHMANN_JSON_TAG "v3.11.3" CACHE STRING "The git tag to FetchContent_Declare for nlohmann/json")
|
||||
|
||||
# We use this directory to ensure we only fetch a single copy of dependencies, even between builds.
|
||||
# $HOME/storage is expected to be mounted from the host for developers.
|
||||
set(TRT_THIRD_PARTY_DL_DIR "$ENV{HOME}/storage" CACHE PATH "Directory to download third party dependencies to")
|
||||
|
||||
# nlohmann/json's own CMake builds tests and install rules by default. Disable both
|
||||
# so our configure stays fast and our install tree doesn't pick up unrelated targets.
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||
set(JSON_Install OFF CACHE INTERNAL "")
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
nlohmann_json
|
||||
PREFIX "${CMAKE_BINARY_DIR}/third_party/nlohmann_json"
|
||||
GIT_REPOSITORY ${NLOHMANN_JSON_REPO}
|
||||
GIT_TAG ${NLOHMANN_JSON_TAG}
|
||||
GIT_SHALLOW TRUE
|
||||
SOURCE_DIR "${TRT_THIRD_PARTY_DL_DIR}/nlohmann_json/${NLOHMANN_JSON_TAG}"
|
||||
EXCLUDE_FROM_ALL
|
||||
UPDATE_DISCONNECTED ${TRT_FETCH_CONTENT_UPDATES_DISCONNECTED}
|
||||
OVERRIDE_FIND_PACKAGE # downstream find_package(nlohmann_json) is satisfied from here.
|
||||
)
|
||||
FetchContent_MakeAvailable(nlohmann_json)
|
||||
|
||||
# Populate NLOHMANN_JSON_INCLUDE_DIRS for samples/common.
|
||||
if(nlohmann_json_SOURCE_DIR)
|
||||
set(NLOHMANN_JSON_INCLUDE_DIRS "${nlohmann_json_SOURCE_DIR}/include"
|
||||
CACHE PATH "nlohmann/json include directory (set by FetchNlohmannJson.cmake)")
|
||||
endif()
|
||||
@@ -0,0 +1,141 @@
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 1993-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
# FindNCCL.cmake
|
||||
#
|
||||
# This module finds and imports the NCCL (NVIDIA Collective Communication Library) from system paths.
|
||||
#
|
||||
# Installation:
|
||||
# -------------
|
||||
# On Ubuntu/Debian:
|
||||
# apt-get install libnccl2 libnccl-dev
|
||||
# On RHEL/CentOS:
|
||||
# yum install libnccl libnccl-devel
|
||||
# From source:
|
||||
# See https://github.com/NVIDIA/nccl
|
||||
#
|
||||
# Input Variables (optional):
|
||||
# ---------------------------
|
||||
# NCCL_ROOT - Root directory where NCCL is installed (e.g., /usr, /usr/local)
|
||||
# NCCL_INCLUDE_DIR - Directory containing nccl.h
|
||||
# NCCL_LIBRARY - Full path to libnccl.so
|
||||
#
|
||||
# Provided Targets:
|
||||
# -----------------
|
||||
# NCCL::nccl - Imported NCCL library target
|
||||
#
|
||||
# Provided Variables:
|
||||
# -------------------
|
||||
# NCCL_FOUND - True if NCCL was found
|
||||
# NCCL_INCLUDE_DIRS - Include directories for NCCL
|
||||
# NCCL_LIBRARIES - NCCL libraries to link against
|
||||
# NCCL_VERSION - Version of NCCL found
|
||||
#
|
||||
# Usage:
|
||||
# ------
|
||||
# find_package(NCCL REQUIRED)
|
||||
# target_link_libraries(your_target PRIVATE NCCL::nccl)
|
||||
#
|
||||
# For custom installations:
|
||||
# cmake -DNCCL_ROOT=/path/to/nccl ..
|
||||
# or
|
||||
# set(NCCL_ROOT "/path/to/nccl")
|
||||
# find_package(NCCL REQUIRED)
|
||||
|
||||
# Search for NCCL header
|
||||
find_path(NCCL_INCLUDE_DIR
|
||||
NAMES nccl.h
|
||||
HINTS
|
||||
${NCCL_ROOT}
|
||||
${NCCL_ROOT}/include
|
||||
$ENV{NCCL_ROOT}
|
||||
$ENV{NCCL_ROOT}/include
|
||||
PATHS
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/usr/include/x86_64-linux-gnu
|
||||
/usr/local/cuda/include
|
||||
DOC "Path to NCCL include directory"
|
||||
)
|
||||
|
||||
# Search for NCCL library
|
||||
find_library(NCCL_LIBRARY
|
||||
NAMES nccl libnccl
|
||||
HINTS
|
||||
${NCCL_ROOT}
|
||||
${NCCL_ROOT}/lib
|
||||
${NCCL_ROOT}/lib64
|
||||
$ENV{NCCL_ROOT}
|
||||
$ENV{NCCL_ROOT}/lib
|
||||
$ENV{NCCL_ROOT}/lib64
|
||||
PATHS
|
||||
/usr/lib
|
||||
/usr/lib64
|
||||
/usr/local/lib
|
||||
/usr/local/lib64
|
||||
/usr/lib/x86_64-linux-gnu
|
||||
/usr/local/cuda/lib64
|
||||
DOC "Path to NCCL library"
|
||||
)
|
||||
|
||||
# Extract version from header if found
|
||||
if(NCCL_INCLUDE_DIR AND EXISTS "${NCCL_INCLUDE_DIR}/nccl.h")
|
||||
file(READ "${NCCL_INCLUDE_DIR}/nccl.h" NCCL_HEADER_CONTENTS)
|
||||
|
||||
string(REGEX MATCH "#define NCCL_MAJOR[ \t]+([0-9]+)" _ "${NCCL_HEADER_CONTENTS}")
|
||||
set(NCCL_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
||||
|
||||
string(REGEX MATCH "#define NCCL_MINOR[ \t]+([0-9]+)" _ "${NCCL_HEADER_CONTENTS}")
|
||||
set(NCCL_VERSION_MINOR "${CMAKE_MATCH_1}")
|
||||
|
||||
string(REGEX MATCH "#define NCCL_PATCH[ \t]+([0-9]+)" _ "${NCCL_HEADER_CONTENTS}")
|
||||
set(NCCL_VERSION_PATCH "${CMAKE_MATCH_1}")
|
||||
|
||||
if(NCCL_VERSION_MAJOR AND NCCL_VERSION_MINOR AND NCCL_VERSION_PATCH)
|
||||
set(NCCL_VERSION "${NCCL_VERSION_MAJOR}.${NCCL_VERSION_MINOR}.${NCCL_VERSION_PATCH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Standard FindPackage handling
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(NCCL
|
||||
REQUIRED_VARS NCCL_LIBRARY NCCL_INCLUDE_DIR
|
||||
VERSION_VAR NCCL_VERSION
|
||||
)
|
||||
|
||||
if(NCCL_FOUND)
|
||||
set(NCCL_INCLUDE_DIRS ${NCCL_INCLUDE_DIR})
|
||||
set(NCCL_LIBRARIES ${NCCL_LIBRARY})
|
||||
|
||||
# Create imported target if it doesn't exist
|
||||
if(NOT TARGET NCCL::nccl)
|
||||
add_library(NCCL::nccl SHARED IMPORTED)
|
||||
set_target_properties(NCCL::nccl PROPERTIES
|
||||
IMPORTED_LOCATION "${NCCL_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${NCCL_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
# Get library directory for installation purposes
|
||||
get_filename_component(NCCL_LIB_DIR "${NCCL_LIBRARY}" DIRECTORY)
|
||||
message(STATUS "Found NCCL ${NCCL_VERSION} at ${NCCL_LIB_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
NCCL_INCLUDE_DIR
|
||||
NCCL_LIBRARY
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
include_guard()
|
||||
|
||||
if(NOT TARGET dl)
|
||||
# libdl is included in the system library on Windows and QNX.
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
find_library(DL_LIB_PATH
|
||||
NAMES ${CMAKE_DL_LIBS}
|
||||
REQUIRED
|
||||
)
|
||||
|
||||
message(STATUS "Creating imported target 'dl' for ${DL_LIB_PATH}")
|
||||
add_library(dl SHARED IMPORTED)
|
||||
set_target_properties(dl PROPERTIES IMPORTED_LOCATION "${DL_LIB_PATH}")
|
||||
else()
|
||||
message(STATUS "Creating no-op target 'dl' since libdl is not available on this platform.")
|
||||
add_library(dl INTERFACE) # Add a fake dl target so we can still call target_link_libraries without error, even though it's a no-op.
|
||||
endif()
|
||||
endif()
|
||||
@@ -0,0 +1,144 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 1993-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
# This module provides functionality to install imported shared libraries
|
||||
# while properly resolving and installing complete symlink chains.
|
||||
#
|
||||
# This is particularly useful for system libraries that use versioned symlinks
|
||||
# (e.g., libfoo.so -> libfoo.so.1 -> libfoo.so.1.2.3).
|
||||
|
||||
# Copies imported shared library files (including versioned symlinks) into the
|
||||
# build library output directory so tests using LD_LIBRARY_PATH find them without
|
||||
# a cmake --install step. Runs at configure time via file(COPY).
|
||||
#
|
||||
# \param targets One or more CMake imported shared-library targets to copy.
|
||||
# \param destination Destination directory (default: resolved CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
||||
function(copyImportedLibrariesToBuildTree)
|
||||
set(oneValueArgs DESTINATION)
|
||||
set(multiValueArgs TARGETS)
|
||||
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT ARG_TARGETS)
|
||||
message(FATAL_ERROR "copyImportedLibrariesToBuildTree requires at least one target.")
|
||||
endif()
|
||||
|
||||
# Resolve any $<CONFIG> generator expression in CMAKE_LIBRARY_OUTPUT_DIRECTORY.
|
||||
# TRT uses single-config generators (Ninja/Makefiles), so CMAKE_BUILD_TYPE is always set.
|
||||
if(ARG_DESTINATION)
|
||||
set(_dest "${ARG_DESTINATION}")
|
||||
elseif(CMAKE_BUILD_TYPE)
|
||||
string(REPLACE "$<CONFIG>" "${CMAKE_BUILD_TYPE}" _dest "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
else()
|
||||
string(REPLACE "$<CONFIG>/" "" _dest "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
|
||||
foreach(target_name IN LISTS ARG_TARGETS)
|
||||
if(NOT TARGET ${target_name})
|
||||
message(FATAL_ERROR "Target ${target_name} does not exist.")
|
||||
endif()
|
||||
|
||||
get_target_property(target_type ${target_name} TYPE)
|
||||
if(NOT target_type MATCHES "SHARED_LIBRARY|UNKNOWN_LIBRARY")
|
||||
message(FATAL_ERROR "Target ${target_name} is not a shared library (type: ${target_type})")
|
||||
endif()
|
||||
|
||||
# IMPORTED_LOCATION may be unset for config-specific imported targets; fall back to
|
||||
# IMPORTED_LOCATION_<CONFIG>.
|
||||
get_target_property(target_loc ${target_name} IMPORTED_LOCATION)
|
||||
if(NOT target_loc)
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" _config_upper)
|
||||
get_target_property(target_loc ${target_name} "IMPORTED_LOCATION_${_config_upper}")
|
||||
endif()
|
||||
if(NOT target_loc)
|
||||
message(FATAL_ERROR "Target ${target_name} has no IMPORTED_LOCATION or IMPORTED_LOCATION_<CONFIG>.")
|
||||
endif()
|
||||
|
||||
get_filename_component(target_dir "${target_loc}" DIRECTORY)
|
||||
get_filename_component(target_base "${target_loc}" NAME_WE)
|
||||
|
||||
file(GLOB target_libs "${target_dir}/${target_base}${CMAKE_SHARED_LIBRARY_SUFFIX}*")
|
||||
if(target_libs)
|
||||
file(MAKE_DIRECTORY "${_dest}")
|
||||
file(COPY ${target_libs} DESTINATION "${_dest}")
|
||||
message(STATUS "Copied ${target_name} to build tree: ${_dest}")
|
||||
else()
|
||||
message(WARNING "copyImportedLibrariesToBuildTree: no libraries found for ${target_name} in ${target_dir}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# Installs an imported library target with all its symlinks.
|
||||
#
|
||||
# \param targets One or more CMake targets to install. Targets must be a shared library (or an unknown library pointing to a shared library).
|
||||
# \param destination Destination directory relative to CMAKE_INSTALL_PREFIX (default: lib)
|
||||
# \param component Installation component name (optional)
|
||||
#
|
||||
# This function attempts to resolve symlinks by globbing for libname.so* in the directory where the target is located.
|
||||
function(installImportedLibraries)
|
||||
set(options)
|
||||
set(oneValueArgs DESTINATION COMPONENT)
|
||||
set(multiValueArgs TARGETS)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
# Set defaults
|
||||
if(NOT ARG_DESTINATION)
|
||||
# On Windows, shared libraries (dlls) go to the bin dir.
|
||||
# Since this function only handles shared libraries, we can simply default to bin/ here.
|
||||
if(WIN32)
|
||||
set(ARG_DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
else()
|
||||
set(ARG_DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ARG_COMPONENT)
|
||||
set(INSTALL_COMPONENT_INPUT COMPONENT ${ARG_COMPONENT}) # Don't quote this, or the component will fail to eval in the install() command.
|
||||
else()
|
||||
set(INSTALL_COMPONENT_INPUT "")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_TARGETS)
|
||||
message(FATAL_ERROR "installImportedLibraries requires at least one target to install.")
|
||||
endif()
|
||||
|
||||
foreach(target_name IN LISTS ARG_TARGETS)
|
||||
if(NOT TARGET ${target_name})
|
||||
message(FATAL_ERROR "Target ${target_name} does not exist")
|
||||
endif()
|
||||
|
||||
get_target_property(target_type ${target_name} TYPE)
|
||||
if(NOT target_type MATCHES "MODULE_LIBRARY|SHARED_LIBRARY|UNKNOWN_LIBRARY")
|
||||
message(FATAL_ERROR "Target ${target_name} is not a shared library (type: ${target_type})")
|
||||
endif()
|
||||
|
||||
# Install all library files and symlinks directly
|
||||
install(CODE "
|
||||
# Resolve where the target is located at install time so we can grab any adjacent symlinks.
|
||||
# Trying to do so earlier will require knowing the build mode at configure time (which we don't).
|
||||
get_filename_component(TARGET_DIR \$<TARGET_FILE:${target_name}> DIRECTORY)
|
||||
get_filename_component(TARGET_BASE_NAME \$<TARGET_FILE:${target_name}> NAME_WE)
|
||||
|
||||
set(TARGET_LIBS_EXPR \"\${TARGET_DIR}/\${TARGET_BASE_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}*\")
|
||||
|
||||
file(GLOB TARGET_LIBS \${TARGET_LIBS_EXPR})
|
||||
file(INSTALL \${TARGET_LIBS}
|
||||
DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}\"
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
"
|
||||
${INSTALL_COMPONENT_INPUT}
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
@@ -0,0 +1,97 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
|
||||
include_guard()
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Install one or more targets including PDB files on Windows/MSVC
|
||||
# Usage:
|
||||
# installLibraries(
|
||||
# TARGETS target1 [target2 ...]
|
||||
# [COMPONENT component] # Optional component name for packaging
|
||||
# [EXPORT export] # Optional export set name.
|
||||
# [CONFIGURATIONS config1 [config2 ...]] # Optional configurations to install
|
||||
# )
|
||||
function(installLibraries)
|
||||
cmake_parse_arguments(
|
||||
ARG # Prefix for parsed args
|
||||
"OPTIONAL;RUNTIME_ONLY" # Options (flags)
|
||||
"COMPONENT;EXPORT" # Single value args
|
||||
"TARGETS;CONFIGURATIONS" # Multi-value args
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
# Validate required arguments
|
||||
if(NOT ARG_TARGETS)
|
||||
message(FATAL_ERROR "installLibrary() requires TARGETS argument")
|
||||
endif()
|
||||
|
||||
# Prepare optional arguments for regular install command
|
||||
if(ARG_COMPONENT)
|
||||
set(component_arg COMPONENT ${ARG_COMPONENT})
|
||||
endif()
|
||||
|
||||
if(ARG_CONFIGURATIONS)
|
||||
set(config_arg CONFIGURATIONS ${ARG_CONFIGURATIONS})
|
||||
endif()
|
||||
|
||||
if(ARG_OPTIONAL)
|
||||
set(optional_arg OPTIONAL)
|
||||
endif()
|
||||
|
||||
if(ARG_EXPORT)
|
||||
set(export_arg EXPORT ${ARG_EXPORT})
|
||||
endif()
|
||||
|
||||
# When RUNTIME_ONLY is passed, we only want to install .dll files.
|
||||
# Instead of also installing the import library (.lib) files.
|
||||
# This is only relevant on Windows since Linux doesn't have this distinction.
|
||||
if(ARG_RUNTIME_ONLY AND WIN32)
|
||||
set(runtime_only_arg
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Install the libraries
|
||||
install(
|
||||
TARGETS ${ARG_TARGETS}
|
||||
${optional_arg}
|
||||
${component_arg}
|
||||
${config_arg}
|
||||
${export_arg}
|
||||
${runtime_only_arg}
|
||||
)
|
||||
|
||||
# Install PDB files for MSVC builds
|
||||
if(MSVC)
|
||||
foreach(target ${ARG_TARGETS})
|
||||
# Get target type (SHARED_LIBRARY, STATIC_LIBRARY, EXECUTABLE)
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
|
||||
# For shared libraries and executables, PDBs are placed alongside the binaries
|
||||
if(target_type STREQUAL "SHARED_LIBRARY" OR target_type STREQUAL "EXECUTABLE")
|
||||
# Use generator expression to get the PDB file path
|
||||
install(
|
||||
FILES "$<TARGET_PDB_FILE:${target}>"
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
${component_arg}
|
||||
CONFIGURATIONS Debug RelWithDebInfo
|
||||
OPTIONAL
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,54 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
|
||||
# Contains constants for the various platform names TRT supports.
|
||||
|
||||
set(TRT_PLATFORM_X86
|
||||
"x86_64"
|
||||
CACHE INTERNAL "Linux")
|
||||
set(TRT_PLATFORM_AARCH64
|
||||
"aarch64"
|
||||
CACHE INTERNAL "ARM Linux")
|
||||
set(TRT_PLATFORM_QNX
|
||||
"qnx"
|
||||
CACHE INTERNAL "QNX")
|
||||
set(TRT_PLATFORM_QNX_SAFE
|
||||
"qnx-safe"
|
||||
CACHE INTERNAL "QNX Safe")
|
||||
set(TRT_PLATFORM_WIN10
|
||||
"win10"
|
||||
CACHE INTERNAL "Windows 10")
|
||||
|
||||
|
||||
# Checks if the current build platform matches any of the passed (ARGN) platforms.
|
||||
#
|
||||
# \param outVar The output variable name.
|
||||
# \param argn The list of platforms to check against.
|
||||
# \returns TRUE if TRT_BUILD_PLATFORM matches any of the platforms, FALSE otherwise.
|
||||
function(checkPlatform outVar)
|
||||
if(NOT DEFINED TRT_BUILD_PLATFORM)
|
||||
message(FATAL_ERROR "checkPlatform was called before TRT_BUILD_PLATFORM was defined!")
|
||||
endif()
|
||||
|
||||
set(isPlatform FALSE)
|
||||
foreach(platform IN LISTS ARGN)
|
||||
if(${platform} STREQUAL ${TRT_BUILD_PLATFORM})
|
||||
set(isPlatform TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(${outVar} ${isPlatform} PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -0,0 +1,105 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
# \brief Converts a SM string (i.e. 86+abc) into the numeric SM version (i.e. 86).
|
||||
# \returns the sm in the name specified by OUT_VAR.
|
||||
function(get_numeric_sm SM OUT_VAR)
|
||||
# Convert the SM string to a numeric value
|
||||
if(${SM} MATCHES "^([0-9]+).*$")
|
||||
set(${OUT_VAR} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
else()
|
||||
message(FATAL_ERROR "Invalid SM version: ${SM}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# \brief Converts the CMAKE_CUDA_ARCHITECTURES list into a list of numeric SM values.
|
||||
# \returns the list in the name specified by OUT_VAR.
|
||||
function(get_all_numeric_sms OUT_VAR)
|
||||
set(ALL_NUMERIC_SMS "")
|
||||
foreach(SM IN LISTS CMAKE_CUDA_ARCHITECTURES)
|
||||
get_numeric_sm(${SM} "SM")
|
||||
list(APPEND ALL_NUMERIC_SMS ${SM})
|
||||
endforeach()
|
||||
set(${OUT_VAR} ${ALL_NUMERIC_SMS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# \brief Converts the list returned by get_all_numeric_sms into a list of arch values.
|
||||
# \returns the list in the name specified by OUT_VAR for native platform and OUT_VAR_CROSS for cross OS support. e.g. ptx, sm75, sm80, sm86, sm89, sm100, sm120.
|
||||
function(get_all_fatbin_archs OUT_VAR OUT_VAR_CROSS)
|
||||
# Use get_all_numeric_sms to get SM values and convert them to sm-prefixed format
|
||||
set(ARCH_LIST "")
|
||||
set(ARCH_LIST_CROSS "")
|
||||
get_all_numeric_sms(NUMERIC_SMS)
|
||||
foreach(SM IN LISTS NUMERIC_SMS)
|
||||
list(APPEND ARCH_LIST "sm${SM}")
|
||||
endforeach()
|
||||
|
||||
# Note: sm89 it is missing in NUMERIC_SMS since TRT treats sm89 as sm86.
|
||||
# We should add sm89 to the list to generate the builder resource for sm89.
|
||||
# If only sm86 is in the list, it means this build only supports sm86,
|
||||
# so no need to add sm89.
|
||||
list(FIND ARCH_LIST "sm86" SM86_INDEX)
|
||||
list(FIND ARCH_LIST "sm89" SM89_INDEX)
|
||||
list(LENGTH ARCH_LIST ARCH_LIST_COUNT)
|
||||
if(${SM86_INDEX} GREATER_EQUAL 0 AND ${SM89_INDEX} EQUAL -1 AND ${ARCH_LIST_COUNT} GREATER 1)
|
||||
list(APPEND ARCH_LIST "sm89")
|
||||
endif()
|
||||
|
||||
# On SBSA exclude sm87 explicitly since it is proxied to sm86.
|
||||
if(${TRT_IS_ARM_SERVER})
|
||||
list(FILTER ARCH_LIST EXCLUDE REGEX "sm87")
|
||||
endif()
|
||||
|
||||
# Exclude sm103 explicitly since it is proxied to sm100.
|
||||
list(FILTER ARCH_LIST EXCLUDE REGEX "sm103")
|
||||
# Exclude sm121 explicitly since it is proxied to sm120.
|
||||
list(FILTER ARCH_LIST EXCLUDE REGEX "sm121")
|
||||
|
||||
# There is also a klib which only contains PTX code.
|
||||
list(APPEND ARCH_LIST "ptx")
|
||||
|
||||
|
||||
set(ARCH_LIST_CROSS ${ARCH_LIST})
|
||||
set(${OUT_VAR} ${ARCH_LIST} PARENT_SCOPE)
|
||||
set(${OUT_VAR_CROSS} ${ARCH_LIST_CROSS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Certain cubins are binary compatible between different SM versions, so they are reused.
|
||||
# This function checks if a SM-named file should be compiled based on current SM enablement.
|
||||
# Specifically, the SM80 files are compiled if either 80, 86, or 89 are enabled.
|
||||
function(should_compile_kernel SM OUT_VAR)
|
||||
get_all_numeric_sms(__TRT_NUMERIC_CUDA_ARCHS)
|
||||
# If the target SM is any of 80/86/89, we need to check if any of those are enabled in __TRT_NUMERIC_CUDA_ARCHS.
|
||||
if((${SM} EQUAL 80) OR (${SM} EQUAL 86) OR (${SM} EQUAL 89))
|
||||
list(FIND __TRT_NUMERIC_CUDA_ARCHS 80 SM80_INDEX)
|
||||
list(FIND __TRT_NUMERIC_CUDA_ARCHS 86 SM86_INDEX)
|
||||
list(FIND __TRT_NUMERIC_CUDA_ARCHS 89 SM89_INDEX)
|
||||
if((NOT ${SM80_INDEX} EQUAL -1) OR
|
||||
(NOT ${SM86_INDEX} EQUAL -1) OR
|
||||
(NOT ${SM89_INDEX} EQUAL -1)
|
||||
)
|
||||
set(${OUT_VAR} TRUE PARENT_SCOPE)
|
||||
else()
|
||||
set(${OUT_VAR} FALSE PARENT_SCOPE)
|
||||
endif()
|
||||
else()
|
||||
list(FIND __TRT_NUMERIC_CUDA_ARCHS ${SM} SM_INDEX)
|
||||
if (NOT ${SM_INDEX} EQUAL -1)
|
||||
set(${OUT_VAR} TRUE PARENT_SCOPE)
|
||||
else()
|
||||
set(${OUT_VAR} FALSE PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,58 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
# Utility module for smoke testing a static library.
|
||||
# This allows us to verify that the static library can be linked without any unexpected dependencies.
|
||||
|
||||
include_guard()
|
||||
|
||||
define_property(TARGET
|
||||
PROPERTY STATIC_LIBRARY_SMOKE_TEST_SOURCE_CODE
|
||||
BRIEF_DOCS "Source code to use when executing the static library smoke test. Defaults to 'int main() { return 0; }'"
|
||||
)
|
||||
|
||||
# Creates a new target that links the given static library and builds a simple executable.
|
||||
# The executable will be added to the ALL target if the static library target is also in the ALL target.
|
||||
function(smoke_test_static_lib static_lib_target)
|
||||
get_target_property(static_lib_type ${static_lib_target} TYPE)
|
||||
if(NOT static_lib_type STREQUAL "STATIC_LIBRARY")
|
||||
message(FATAL_ERROR "Target ${static_lib_target} is not a static library.")
|
||||
endif()
|
||||
|
||||
set(smoke_test_target "${static_lib_target}_smoke_test")
|
||||
get_target_property(smoke_test_src ${static_lib_target} STATIC_LIBRARY_SMOKE_TEST_SOURCE_CODE)
|
||||
# Handle NOTFOUND sentinel and empty string; otherwise treat property as source content.
|
||||
if(NOT smoke_test_src)
|
||||
set(smoke_test_src "int main() { return 0; }\n")
|
||||
endif()
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${smoke_test_target}.cpp" "${smoke_test_src}")
|
||||
|
||||
add_executable(${smoke_test_target} "${CMAKE_CURRENT_BINARY_DIR}/${smoke_test_target}.cpp")
|
||||
|
||||
target_link_libraries(${smoke_test_target} PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,${static_lib_target}>)
|
||||
# cuDLA is not available as a static library, so we link it dynamically
|
||||
if(${TRT_BUILD_ENABLE_DLA} AND TARGET CUDA::cudla)
|
||||
target_link_libraries(${smoke_test_target} PRIVATE CUDA::cudla)
|
||||
endif()
|
||||
|
||||
# If the static library target is in the ALL target, add the smoke test target to the ALL target as well.
|
||||
get_target_property(static_lib_excluded_from_all ${static_lib_target} EXCLUDE_FROM_ALL)
|
||||
if(static_lib_excluded_from_all)
|
||||
set_target_properties(${smoke_test_target} PROPERTIES
|
||||
EXCLUDE_FROM_ALL ON
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,97 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
# This file provides functionality to create stub libraries from existing CMake targets
|
||||
# by calling the existing stubify.sh script.
|
||||
#
|
||||
# Stub libraries contain the same exported symbols as the original shared library but with empty function bodies,
|
||||
# removing all dependencies while maintaining the same API surface for linking purposes.
|
||||
|
||||
# Creates a stub library from an existing CMake target by calling stubify.sh.
|
||||
#
|
||||
# \param target_name Name of an existing CMake shared library target
|
||||
#
|
||||
# Creates a new target called ${target_name}_stub that contains empty implementations
|
||||
# of all exported symbols from the original target. The stub library is also installed
|
||||
# to lib/stubs during the install phase.
|
||||
function(create_stub_lib target_name)
|
||||
if(MSVC)
|
||||
message(FATAL_ERROR "Creating stub libs is not supported on Windows.")
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ${target_name})
|
||||
message(FATAL_ERROR "Target ${target_name} does not exist")
|
||||
endif()
|
||||
|
||||
get_target_property(target_type ${target_name} TYPE)
|
||||
if(NOT target_type STREQUAL "SHARED_LIBRARY")
|
||||
message(FATAL_ERROR "Target ${target_name} is not a shared library")
|
||||
endif()
|
||||
|
||||
set(stub_target "${target_name}_stub")
|
||||
|
||||
# The stub output should be the same base name of the library with a _stub suffix.
|
||||
# We need to read the OUTPUT_NAME of the target, and fallback to the target name otherwise.
|
||||
get_target_property(output_name ${target_name} OUTPUT_NAME)
|
||||
if(NOT output_name)
|
||||
set(output_name ${target_name})
|
||||
endif()
|
||||
set(stub_output "${CMAKE_CURRENT_BINARY_DIR}/stubs/lib${output_name}.so")
|
||||
|
||||
# Find the stubify.sh script
|
||||
find_file(STUBIFY_SCRIPT stubify.sh
|
||||
PATHS ${CMAKE_SOURCE_DIR}/scripts
|
||||
NO_DEFAULT_PATH
|
||||
REQUIRED
|
||||
)
|
||||
|
||||
# Create a custom target that calls stubify.sh
|
||||
add_custom_command(
|
||||
OUTPUT ${stub_output}
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
CC=${CMAKE_C_COMPILER}
|
||||
CC_ARGS=${STUBIFY_CC_ARGS}
|
||||
--
|
||||
${STUBIFY_SCRIPT} $<TARGET_FILE:${target_name}> ${stub_output}
|
||||
DEPENDS $<TARGET_FILE:${target_name}> ${STUBIFY_SCRIPT}
|
||||
COMMENT "Creating stub library ${stub_output} for ${target_name}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Create an imported library target for the stub
|
||||
add_library(${stub_target} SHARED IMPORTED)
|
||||
set_target_properties(${stub_target} PROPERTIES
|
||||
IMPORTED_LOCATION ${stub_output}
|
||||
)
|
||||
|
||||
# Create a custom target to ensure the stub gets built
|
||||
add_custom_target(${stub_target}_build
|
||||
ALL
|
||||
DEPENDS ${stub_output}
|
||||
)
|
||||
|
||||
# Make sure the stub builds after the original
|
||||
add_dependencies(${stub_target}_build ${target_name})
|
||||
|
||||
# Make the imported target depend on the build target
|
||||
add_dependencies(${stub_target} ${stub_target}_build)
|
||||
|
||||
# Install the stub library to lib/stubs
|
||||
install(FILES ${stub_output}
|
||||
DESTINATION lib/stubs
|
||||
COMPONENT external
|
||||
OPTIONAL
|
||||
)
|
||||
endfunction()
|
||||
@@ -0,0 +1,93 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
## Helper file for management of symbol exports in shared libraries via linker scripts.
|
||||
## This allows controlling symbol visibility across different platforms without needing platform-specific code.
|
||||
|
||||
# Applies an export map to one or more targets (specified by TARGETS).
|
||||
# The export map file should be provided without extension; the appropriate extension will be added based on the platform (Windows: .def, Unix: .map).
|
||||
# If CONFIGURE_FIRST is set, the export map will be configured via CMake configure_file (@ONLY). The source file must have the additional extension .in.
|
||||
#
|
||||
# \param CONFIGURE_FIRST Optional flag to indicate that the export map file should be configured first.
|
||||
# \param EXPORT_MAP_FILE The base name of the export map file (without extension). If not provided, the function will look for a file matching the target's output name in the 'exports' directory.
|
||||
# \param BINARY_DIR Optional path to the binary directory where the configured file will be placed. If not set, the current binary directory is used.
|
||||
# \param TARGETS The targets to which the export map should be applied. Must not be empty.
|
||||
function(apply_export_map)
|
||||
cmake_parse_arguments(ARG "CONFIGURE_FIRST" "EXPORT_MAP_FILE;BINARY_DIR" "TARGETS" ${ARGN})
|
||||
|
||||
if(NOT ARG_TARGETS)
|
||||
message(FATAL_ERROR "apply_export_map: TARGETS argument must not be empty.")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_BINARY_DIR)
|
||||
set(ARG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set(export_extension ".def")
|
||||
else()
|
||||
set(export_extension ".map")
|
||||
endif()
|
||||
|
||||
foreach(target IN LISTS ARG_TARGETS)
|
||||
if(ARG_EXPORT_MAP_FILE)
|
||||
cmake_path(IS_RELATIVE ARG_EXPORT_MAP_FILE is_relative)
|
||||
if(is_relative)
|
||||
set(export_map_file "${CMAKE_CURRENT_SOURCE_DIR}/${ARG_EXPORT_MAP_FILE}")
|
||||
else()
|
||||
set(export_map_file "${ARG_EXPORT_MAP_FILE}")
|
||||
endif()
|
||||
else()
|
||||
# Otherwise, default to searching for a file that matches the target's output name.
|
||||
get_target_property(output_name ${target} OUTPUT_NAME)
|
||||
if(NOT output_name)
|
||||
set(output_name ${target})
|
||||
endif()
|
||||
set(export_map_file "${CMAKE_CURRENT_SOURCE_DIR}/exports/${output_name}")
|
||||
endif()
|
||||
|
||||
if(ARG_CONFIGURE_FIRST)
|
||||
if(NOT EXISTS "${export_map_file}${export_extension}.in")
|
||||
message(FATAL_ERROR "apply_export_map: Expected to find export map template file '${export_map_file}${export_extension}.in' for configuration.")
|
||||
endif()
|
||||
get_filename_component(export_file_name ${export_map_file} NAME_WE)
|
||||
configure_file(
|
||||
"${export_map_file}${export_extension}.in"
|
||||
"${ARG_BINARY_DIR}/${export_file_name}${export_extension}"
|
||||
@ONLY
|
||||
)
|
||||
set(export_map_file "${ARG_BINARY_DIR}/${export_file_name}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${export_map_file}${export_extension}")
|
||||
message(FATAL_ERROR "apply_export_map: Expected to find export map file '${export_map_file}${export_extension}'.")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
# On Windows, use a .def file to control exported symbols
|
||||
target_sources(${target} PRIVATE "${export_map_file}${export_extension}")
|
||||
else()
|
||||
# On Unix-like systems, use a version script for symbol visibility
|
||||
target_link_options(${target} PRIVATE "LINKER:--version-script=${export_map_file}${export_extension}")
|
||||
# We also need to update the link dependencies. We don't need to do this on Windows since the .def file is a source file.
|
||||
get_target_property(link_deps ${target} LINK_DEPENDS)
|
||||
if(NOT link_deps)
|
||||
set(link_deps "")
|
||||
endif()
|
||||
list(APPEND link_deps "${export_map_file}${export_extension}")
|
||||
set_target_properties(${target} PROPERTIES LINK_DEPENDS "${link_deps}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
@@ -0,0 +1,43 @@
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
include_guard()
|
||||
|
||||
# \brief Handles setting output names for libraries on Windows to include version information.
|
||||
# We have two conventions:
|
||||
# 1. For enterprise, shared libraries have a suffix _${major_version}
|
||||
# 2. For TRT-RTX, shared libraries have a suffix _${major_version}_${minor_version}
|
||||
# \note This is a no-op for non-Windows platforms.
|
||||
#
|
||||
# \param target_name The name of the target to update.
|
||||
# \param major_version The major version of the library.
|
||||
# \param minor_version The minor version of the library.
|
||||
function(update_windows_output_name target_name major_version minor_version)
|
||||
if(MSVC)
|
||||
get_target_property(tgt_output_name ${target_name} OUTPUT_NAME)
|
||||
if(NOT tgt_output_name)
|
||||
set(tgt_output_name ${target_name})
|
||||
endif()
|
||||
|
||||
if(${TRT_BUILD_WINML})
|
||||
set(tgt_output_name "${tgt_output_name}_${major_version}_${minor_version}")
|
||||
else()
|
||||
set(tgt_output_name "${tgt_output_name}_${major_version}")
|
||||
endif()
|
||||
|
||||
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${tgt_output_name})
|
||||
message(STATUS "Updated output name for target '${target_name}' to '${tgt_output_name}'")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,40 @@
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
macro(find_library_create_target target_name lib libtype hints)
|
||||
message(STATUS "========================= Importing and creating target ${target_name} ==========================")
|
||||
message(STATUS "Looking for library ${lib}")
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
find_library(
|
||||
${lib}_LIB_PATH ${lib}${TRT_DEBUG_POSTFIX}
|
||||
HINTS ${hints}
|
||||
NO_DEFAULT_PATH)
|
||||
endif()
|
||||
find_library(
|
||||
${lib}_LIB_PATH ${lib}
|
||||
HINTS ${hints}
|
||||
NO_DEFAULT_PATH)
|
||||
find_library(${lib}_LIB_PATH ${lib})
|
||||
message(STATUS "Library that was found ${${lib}_LIB_PATH}")
|
||||
add_library(${target_name} ${libtype} IMPORTED)
|
||||
if(MSVC)
|
||||
set_property(TARGET ${target_name} PROPERTY IMPORTED_IMPLIB ${${lib}_LIB_PATH})
|
||||
else()
|
||||
set_property(TARGET ${target_name} PROPERTY IMPORTED_LOCATION ${${lib}_LIB_PATH})
|
||||
endif()
|
||||
message(STATUS "==========================================================================================")
|
||||
endmacro()
|
||||
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
function(set_ifndef variable value)
|
||||
if(NOT DEFINED ${variable})
|
||||
set(${variable}
|
||||
${value}
|
||||
PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user