diff --git a/llvm/projects/hpvm-tensor-rt/CMakeLists.txt b/llvm/projects/hpvm-tensor-rt/CMakeLists.txt
index e0940eea58c3a14bda5b7d00d2033c7da8df68a7..d86c8fa3cb7cb70bbe23bda5cb21b57637ab9544 100644
--- a/llvm/projects/hpvm-tensor-rt/CMakeLists.txt
+++ b/llvm/projects/hpvm-tensor-rt/CMakeLists.txt
@@ -103,7 +103,10 @@ target_link_libraries(tensor_runtime ${LINK_LIBS})
 cuda_add_library(tensor_runtime_install ${RUNTIME_SRCS})
 cuda_add_cublas_to_target(tensor_runtime_install)
 target_link_libraries(tensor_runtime_install ${LINK_LIBS})
-
+# tensor_runtime_install is built AFTER tensor_runtime because of a nvcc bug (bug?)
+# that doesn't allow compiling the same file from multiple targets at once.
+# Same for tensor_runtime_online.
+add_dependencies(tensor_runtime_install tensor_runtime)
 
 # Online version
 remove_definitions(-DONLINE_PROFILING=false)
@@ -112,7 +115,8 @@ remove_definitions(-DFP16_tuning=true)
 add_definitions(-DFP16_tuning=false)
 cuda_add_library(tensor_runtime_online ${RUNTIME_SRCS})
 cuda_add_cublas_to_target(tensor_runtime_online)
-target_link_libraries(tensor_runtime_online  ${LINK_LIBS}) 
+target_link_libraries(tensor_runtime_online  ${LINK_LIBS})
+add_dependencies(tensor_runtime_online tensor_runtime)
 
 # Adding new rule for building a cuDNN runtime library