-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
85 lines (67 loc) · 2.53 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
cmake_minimum_required(VERSION 3.18)
# Project declaration with C++ and CUDA support
project(YOLOv11TRT LANGUAGES CXX CUDA)
# Set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Define the path to TensorRT installation
set(TENSORRT_PATH "F:/Program Files/TensorRT-8.6.1.6") # Update this to the actual path for TensorRT
# Define the path to OpenCV installation
# Allow overriding TensorRT and OpenCV paths via command line
# e.g., cmake -DTENSORRT_PATH="path/to/TensorRT" -DOpenCV_DIR="path/to/OpenCV" ..
option(TENSORRT_PATH_OPTION "Path to TensorRT installation" ${TENSORRT_PATH})
set(TENSORRT_PATH ${TENSORRT_PATH_OPTION} CACHE PATH "Path to TensorRT installation")
# Find OpenCV
find_package(OpenCV REQUIRED)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV not found. Please install OpenCV or set OpenCV_DIR.")
endif()
# Find CUDA
find_package(CUDA REQUIRED)
if(NOT CUDA_FOUND)
message(FATAL_ERROR "CUDA not found. Please install the CUDA Toolkit.")
endif()
# Include directories for TensorRT
include_directories(${TENSORRT_PATH}/include)
# Include directory for your project
include_directories(${CMAKE_SOURCE_DIR}/include)
# Define source files (including CUDA sources)
set(SOURCES
main.cpp
src/yolov11.cpp
src/preprocess.cu
)
# Create executable (CMake handles CUDA sources automatically)
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
# Define API_EXPORTS macro
target_compile_definitions(${PROJECT_NAME} PRIVATE API_EXPORTS)
# Specify include directories (modern CMake approach)
target_include_directories(${PROJECT_NAME} PRIVATE
src/
${OpenCV_INCLUDE_DIRS}
${CUDA_INCLUDE_DIRS}
${TENSORRT_PATH}/include
)
# Link TensorRT libraries
# Specify full paths to TensorRT libraries to avoid relying on link_directories
set(TENSORRT_LIBS
"${TENSORRT_PATH}/lib/nvinfer.lib"
"${TENSORRT_PATH}/lib/nvonnxparser.lib"
"${TENSORRT_PATH}/lib/nvparsers.lib"
"${TENSORRT_PATH}/lib/nvinfer_plugin.lib"
)
# Link libraries to the target
target_link_libraries(${PROJECT_NAME} PRIVATE
${OpenCV_LIBS}
${CUDA_LIBRARIES}
${TENSORRT_LIBS}
)
# Enable separable compilation for CUDA (optional but recommended)
set_target_properties(${PROJECT_NAME} PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
)
# (Optional) Specify CUDA architectures based on your GPU hardware
# set(CMAKE_CUDA_ARCHITECTURES 75) # Example for Turing architecture
# (Optional) Set output directories for binaries
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)