Skip to content

Commit 984e57c

Browse files
authored
Add library-only build target (#659)
Signed-off-by: Kevin Chen <[email protected]>
1 parent cb2ae79 commit 984e57c

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

CMakeLists.txt

+27-16
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ if(BUILD_ONNXIFI)
7474
set(ONNXIFI_SOURCES onnx_trt_backend.cpp)
7575
endif()
7676

77-
set(EXECUTABLE_SOURCES
78-
main.cpp
79-
)
80-
81-
set(API_TESTS_SOURCES
82-
getSupportedAPITest.cpp
83-
ModelImporter.cpp
84-
)
77+
# Build executables if BUILD_LIBRARY_ONLY flag is not set
78+
if (NOT DEFINED BUILD_LIBRARY_ONLY)
79+
set(EXECUTABLE_SOURCES
80+
main.cpp
81+
)
82+
set(API_TESTS_SOURCES
83+
getSupportedAPITest.cpp
84+
ModelImporter.cpp
85+
)
86+
endif()
8587

8688
set(HEADERS
8789
NvOnnxParser.h
@@ -158,25 +160,27 @@ endif()
158160
# --------------------------------
159161
# Converter executable
160162
# --------------------------------
161-
add_executable(onnx2trt ${EXECUTABLE_SOURCES})
162-
target_include_directories(onnx2trt PUBLIC ${ONNX_INCLUDE_DIRS})
163-
target_link_libraries(onnx2trt PUBLIC ${PROTOBUF_LIB} onnx nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) #${CUDA_LIBRARIES}
163+
if (NOT DEFINED BUILD_LIBRARY_ONLY)
164+
add_executable(onnx2trt ${EXECUTABLE_SOURCES})
165+
target_include_directories(onnx2trt PUBLIC ${ONNX_INCLUDE_DIRS})
166+
target_link_libraries(onnx2trt PUBLIC ${PROTOBUF_LIB} onnx nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) #${CUDA_LIBRARIES}
167+
endif()
164168

165169
# --------------------------------
166170
# API Tests
167171
# --------------------------------
168-
add_executable(getSupportedAPITest ${API_TESTS_SOURCES})
169-
target_include_directories(getSupportedAPITest PUBLIC ${ONNX_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
170-
target_link_libraries(getSupportedAPITest PUBLIC ${PROTOBUF_LIB} nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) #${CUDA_LIBRARIES}
172+
if (NOT DEFINED BUILD_LIBRARY_ONLY)
173+
add_executable(getSupportedAPITest ${API_TESTS_SOURCES})
174+
target_include_directories(getSupportedAPITest PUBLIC ${ONNX_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
175+
target_link_libraries(getSupportedAPITest PUBLIC ${PROTOBUF_LIB} nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) #${CUDA_LIBRARIES}
176+
endif()
171177

172178
# --------------------------------
173179
# Installation
174180
# --------------------------------
175181
install(TARGETS
176-
onnx2trt
177182
nvonnxparser
178183
nvonnxparser_static
179-
RUNTIME DESTINATION bin
180184
LIBRARY DESTINATION lib
181185
ARCHIVE DESTINATION lib
182186
)
@@ -185,6 +189,13 @@ install(FILES ${HEADERS}
185189
DESTINATION include
186190
)
187191

192+
if (NOT DEFINED BUILD_LIBRARY_ONLY)
193+
install(TARGETS
194+
onnx2trt
195+
RUNTIME DESTINATION bin
196+
)
197+
endif()
198+
188199
SET(CPACK_GENERATOR "DEB")
189200
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Mike Houston") #required
190201
SET(CPACK_PACKAGE_NAME "onnx-trt-dev")

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Once you have cloned the repository, you can build the parser libraries and exec
5757
// Ensure that you update your LD_LIBRARY_PATH to pick up the location of the newly built library:
5858
export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
5959

60+
For building only the libraries, append `-DBUILD_LIBRARY_ONLY=1` to the CMake build command.
61+
6062
## Executable Usage
6163

6264
ONNX models can be converted to serialized TensorRT engines using the `onnx2trt` executable:

0 commit comments

Comments
 (0)