leezu commented on a change in pull request #19742:
URL: https://github.com/apache/incubator-mxnet/pull/19742#discussion_r565274032



##########
File path: CMakeLists.txt
##########
@@ -239,29 +239,23 @@ if(USE_TENSORRT)
   message(STATUS "Using TensorRT")
   set(ONNX_PATH 3rdparty/onnx-tensorrt/third_party/onnx/build/)
   set(ONNX_TRT_PATH 3rdparty/onnx-tensorrt/build/)
+  add_definitions(-DMXNET_USE_TENSORRT=1)
+  add_definitions(-DONNX_NAMESPACE=onnx)
+  add_definitions(-DONNX_ML=1)
+  set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
+  set(BUILD_SHARED_LIBS ON)
+  add_subdirectory(3rdparty/onnx-tensorrt/ EXCLUDE_FROM_ALL)
+  set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")

Review comment:
       Are you trying to prevent `add_subdirectory` from changing the global 
variables? The problem is a "bug" in `3rdparty/onnx-tensorrt/` (ie. they 
shouldn't change the global variables in the first place). A better workaround 
compared to manually saving `BUILD_SHARED_LIBS` is to call `add_subdirectory` 
inside a function. Each function in cmake has it's own scope, and 
`add_subdirectory` can then only modify the variables inside the function 
scope. 
   You can look at `load_omp` function inside this file to see how it's done. 
But if `3rdparty/onnx-tensorrt` only overwrites `BUILD_SHARED_LIBS`, it's also 
fine to merge this PR first and improve later




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to