|
| 1 | +# Copyright (c) 2025-present WATonomous. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +cmake_minimum_required(VERSION 3.8) |
| 15 | +project(onnxruntime_gpu_vendor VERSION 1.22.0) |
| 16 | + |
| 17 | +find_package(ament_cmake REQUIRED) |
| 18 | + |
| 19 | +set(ONNXRUNTIME_VERSION "${PROJECT_VERSION}") |
| 20 | +set(ONNXRUNTIME_URL |
| 21 | + "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz" |
| 22 | +) |
| 23 | +set(ONNXRUNTIME_DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-download") |
| 24 | +set(ONNXRUNTIME_EXTRACT_DIR "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}") |
| 25 | + |
| 26 | +# Download and extract ONNX Runtime GPU |
| 27 | +if(NOT EXISTS "${ONNXRUNTIME_EXTRACT_DIR}") |
| 28 | + message(STATUS "Downloading ONNX Runtime GPU ${ONNXRUNTIME_VERSION}...") |
| 29 | + file(DOWNLOAD |
| 30 | + ${ONNXRUNTIME_URL} |
| 31 | + "${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime-gpu.tgz" |
| 32 | + SHOW_PROGRESS |
| 33 | + STATUS DOWNLOAD_STATUS |
| 34 | + ) |
| 35 | + |
| 36 | + list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT) |
| 37 | + if(NOT DOWNLOAD_RESULT EQUAL 0) |
| 38 | + message(FATAL_ERROR "Failed to download ONNX Runtime GPU") |
| 39 | + endif() |
| 40 | + |
| 41 | + message(STATUS "Extracting ONNX Runtime GPU...") |
| 42 | + execute_process( |
| 43 | + COMMAND ${CMAKE_COMMAND} -E tar xzf "${ONNXRUNTIME_DOWNLOAD_DIR}/onnxruntime-gpu.tgz" |
| 44 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 45 | + RESULT_VARIABLE EXTRACT_RESULT |
| 46 | + ) |
| 47 | + |
| 48 | + if(NOT EXTRACT_RESULT EQUAL 0) |
| 49 | + message(FATAL_ERROR "Failed to extract ONNX Runtime GPU") |
| 50 | + endif() |
| 51 | +endif() |
| 52 | + |
| 53 | +# Install headers |
| 54 | +install( |
| 55 | + DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/include/" |
| 56 | + DESTINATION include |
| 57 | +) |
| 58 | + |
| 59 | +# Install libraries |
| 60 | +install( |
| 61 | + DIRECTORY "${ONNXRUNTIME_EXTRACT_DIR}/lib/" |
| 62 | + DESTINATION lib |
| 63 | + PATTERN "*.a" EXCLUDE |
| 64 | +) |
| 65 | + |
| 66 | +# Create an interface library for users to link against |
| 67 | +add_library(onnxruntime_gpu_lib INTERFACE) |
| 68 | +target_include_directories(onnxruntime_gpu_lib INTERFACE |
| 69 | + $<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/include> |
| 70 | + $<INSTALL_INTERFACE:include> |
| 71 | +) |
| 72 | +target_link_libraries(onnxruntime_gpu_lib INTERFACE |
| 73 | + $<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime.so> |
| 74 | + $<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime_providers_cuda.so> |
| 75 | + $<BUILD_INTERFACE:${ONNXRUNTIME_EXTRACT_DIR}/lib/libonnxruntime_providers_shared.so> |
| 76 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime.so> |
| 77 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime_providers_cuda.so> |
| 78 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/lib/libonnxruntime_providers_shared.so> |
| 79 | +) |
| 80 | + |
| 81 | +# Export the target |
| 82 | +install( |
| 83 | + TARGETS onnxruntime_gpu_lib |
| 84 | + EXPORT ${PROJECT_NAME} |
| 85 | + LIBRARY DESTINATION lib |
| 86 | + ARCHIVE DESTINATION lib |
| 87 | + RUNTIME DESTINATION bin |
| 88 | + INCLUDES DESTINATION include |
| 89 | +) |
| 90 | + |
| 91 | +ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET) |
| 92 | +ament_export_dependencies() |
| 93 | + |
| 94 | +ament_package() |
0 commit comments