-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathCMakeLists.txt
93 lines (79 loc) · 2.44 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
86
87
88
89
90
91
92
93
# 设置项目
cmake_minimum_required(VERSION 3.15.0)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0146 OLD)
project(pose LANGUAGES CXX CUDA)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 添加依赖项
find_package(CUDA REQUIRED)
set(CMAKE_CUDA_ARCHITECTURES native)
set(CUDA_PATH ${CUDA_TOOLKIT_ROOT_DIR})
find_package(OpenCV REQUIRED)
# 添加编译选项
option(TENSORRT_PATH "TensorRT Path. Example: /usr/local/tensorrt" "")
if(NOT DEFINED TENSORRT_PATH)
message(FATAL_ERROR "TensorRT path is not set. Please specify the TensorRT path.")
endif()
option(DEPLOY_PATH "TensorRT-YOLO Project Path." "")
if(NOT DEFINED DEPLOY_PATH)
message(FATAL_ERROR "TensorRT-YOLO project path is not set. Please specify the TensorRT-YOLO Project path.")
endif()
# 添加可执行文件
add_executable(pose "")
# 包含头文件目录
target_include_directories(pose PRIVATE
${CUDA_INCLUDE_DIRS}
${TENSORRT_PATH}/include
${OpenCV_INCLUDE_DIRS}
${DEPLOY_PATH}/include
)
# 链接库目录
target_link_directories(pose PRIVATE
${TENSORRT_PATH}/lib
${DEPLOY_PATH}/lib
)
# 私有源文件
target_sources(pose PRIVATE pose.cpp)
# 私有编译定义
target_compile_definitions(pose PRIVATE ${CUDA_DEFINITIONS})
# 私有链接库
target_link_libraries(pose PRIVATE
${CUDA_cudart_LIBRARY}
${OpenCV_LIBS}
deploy
)
# 根据平台选择不同的 TensorRT 库
if(MSVC AND EXISTS ${TENSORRT_PATH}/lib/nvinfer_10.dll)
target_link_libraries(pose PRIVATE nvinfer_10 nvinfer_plugin_10 nvonnxparser_10)
else()
target_link_libraries(pose PRIVATE nvinfer nvinfer_plugin nvonnxparser)
endif()
# 设置输出目录
set_target_properties(pose PROPERTIES OUTPUT_NAME "pose")
if(MSVC)
set_target_properties(pose PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/bin"
)
else()
set_target_properties(pose PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
)
endif()
# 编译选项
if(MSVC)
target_compile_options(pose PRIVATE
$<$<CONFIG:Release>:-O2>
)
set_property(TARGET pose PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
target_compile_options(pose PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-O3 -flto=auto>
)
target_link_options(pose PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-O3 -flto=auto>
)
endif()