forked from cyrusbehr/tensorrt-cpp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
66 lines (56 loc) · 2.52 KB
/
CMakeLists.txt
File metadata and controls
66 lines (56 loc) · 2.52 KB
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
cmake_minimum_required(VERSION 3.16)
project(tensorrt_cpp_api)
# Use ccache to speed up rebuilds and include cmake deps
include(cmake/ccache.cmake)
include(FetchContent)
# Set C++ version and optimization level
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-deprecated-declarations")
# For finding FindTensorRT.cmake
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# TensorRT installation directory hint
set(TensorRT_DIR "" CACHE PATH "TensorRT install directory.")
if (NOT TensorRT_DIR)
message(WARNING "Finding TensorRT could be difficult for non-standard location, please specify TensorRT_DIR.")
endif()
# We require CUDA, OpenCV, and TensorRT
find_package(TensorRT 8.5 REQUIRED)
find_package(CUDA 11.4 REQUIRED)
find_package(OpenCV 4.8 REQUIRED)
include(FetchContent)
# argparse
FetchContent_Declare(
argparse
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
)
FetchContent_MakeAvailable(argparse)
add_library(tensorrt_cpp_api SHARED src/engine.cpp)
# use rpath instead or runpath, because tensorrt libs has no runpath and rpath is transitive
# but carefull with LD_LIBRARY_PATH
if (UNIX AND NOT APPLE)
target_link_options(tensorrt_cpp_api PUBLIC "-Wl,--disable-new-dtags")
endif()
target_include_directories(tensorrt_cpp_api PUBLIC ${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} ${TensorRT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(tensorrt_cpp_api PUBLIC ${OpenCV_LIBS} ${CUDA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${TensorRT_LIBRARIES})
# Optionnal benchmark
# TODO: use Google benchmark instead
option(WITH_BENCHMARK "Performs benchmarking, do not use in production environment" OFF)
add_library(tensorrt_detector SHARED src/detector.cpp src/transforms.cpp src/configParser.cpp)
if (${WITH_BENCHMARK})
message(WARNING "Benchmarking was enabled, do not use in a production environment!")
target_compile_definitions(tensorrt_detector PRIVATE WITH_BENCHMARK)
endif()
target_include_directories(tensorrt_detector PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(tensorrt_detector PUBLIC tensorrt_cpp_api)
add_executable(run_prediction_image src/main.cpp)
if (${WITH_BENCHMARK})
target_compile_definitions(run_prediction_image PRIVATE WITH_BENCHMARK)
endif()
target_include_directories(run_prediction_image PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(run_prediction_image tensorrt_cpp_api tensorrt_detector argparse)
# tests
option(BUILD_TESTING "..." OFF)
if (BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()