diff --git a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/CMakeLists.txt b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/CMakeLists.txt
index ce2d4c80fd3f885e1d3c6e83d43f35480f9770c8..832f6334a4bc048992ee545844941f44ef2c8fe0 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/CMakeLists.txt
+++ b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/CMakeLists.txt
@@ -2,6 +2,8 @@ if(WIN32 OR CYGWIN)
   set(LLVM_LINK_COMPONENTS Core Support)
 endif()
 
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${PROJECT_BINARY_DIR}")
+
 add_llvm_library( LLVMDFG2LLVM_NVPTX
   MODULE
   DFG2LLVM_NVPTX.cpp
diff --git a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
index f582a9ab6a4510b5d403d0709f2a06d0339d5a93..d250562043b633aa69b4ac6bf77ba2bf51167093 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+++ b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
@@ -40,6 +40,14 @@
 
 #include <sstream>
 
+#ifndef LLVM_BUILD_DIR
+#error LLVM_BUILD_DIR is not defined
+#endif
+
+#define STR_VALUE(X) #X
+#define STRINGIFY(X) STR_VALUE(X)
+#define LLVM_BUILD_DIR_STR STRINGIFY(LLVM_BUILD_DIR)
+
 using namespace llvm;
 using namespace builddfg;
 using namespace dfg2llvm;
@@ -254,14 +262,10 @@ void CGT_NVPTX::initRuntimeAPI() {
   // Load Runtime API Module
   SMDiagnostic Err;
 
-  char *LLVM_SRC_ROOT = getenv("LLVM_SRC_ROOT");
-  assert(LLVM_SRC_ROOT != NULL && "Define LLVM_SRC_ROOT environment variable!");
-
-  Twine llvmSrcRoot = LLVM_SRC_ROOT;
-  Twine runtimeAPI =
-      llvmSrcRoot + "/../build/tools/hpvm/projects/hpvm-rt/hpvm-rt.bc";
+  std::string runtimeAPI = std::string(LLVM_BUILD_DIR_STR) +
+                           "/tools/hpvm/projects/hpvm-rt/hpvm-rt.bc";
 
-  runtimeModule = parseIRFile(runtimeAPI.str(), Err, M.getContext());
+  runtimeModule = parseIRFile(runtimeAPI, Err, M.getContext());
   if (runtimeModule == nullptr) {
     DEBUG(errs() << Err.getMessage() << " " << runtimeAPI << "\n");
     assert(false && "couldn't parse runtime");
@@ -1620,8 +1624,8 @@ void CGT_NVPTX::codeGen(DFLeafNode *N) {
     }
     // check that addressspace is 1
     //	  if (GEPIaddrspace != 1) {
-    //			// does not fit this pattern - addrspace of pointer argument
-    //is not global 			continue;
+    //			// does not fit this pattern - addrspace of pointer
+    //argument is not global 			continue;
     //		}
     if (!(GEPI->hasOneUse())) {
       // does not fit this pattern - more than one uses
diff --git a/hpvm/lib/Transforms/DFG2LLVM_X86/CMakeLists.txt b/hpvm/lib/Transforms/DFG2LLVM_X86/CMakeLists.txt
index b79c6a3bf919bffeed21f156c84d3fce943d7cbd..0a3a225f1967dd73d44d1401a2bc45cb8d43ee69 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_X86/CMakeLists.txt
+++ b/hpvm/lib/Transforms/DFG2LLVM_X86/CMakeLists.txt
@@ -2,6 +2,8 @@ if(WIN32 OR CYGWIN)
   set(LLVM_LINK_COMPONENTS Core Support)
 endif()
 
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${PROJECT_BINARY_DIR}")
+
 add_llvm_library( LLVMDFG2LLVM_X86
   MODULE
   DFG2LLVM_X86.cpp
diff --git a/hpvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp b/hpvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp
index 21adabf4ebe5999134491f163aa8119d44f84f10..c0e2b715fa9a7a14f6c728a3c58728742f80d77c 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp
+++ b/hpvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp
@@ -21,6 +21,14 @@
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/ValueMapper.h"
 
+#ifndef LLVM_BUILD_DIR
+#error LLVM_BUILD_DIR is not defined
+#endif
+
+#define STR_VALUE(X) #X
+#define STRINGIFY(X) STR_VALUE(X)
+#define LLVM_BUILD_DIR_STR STRINGIFY(LLVM_BUILD_DIR)
+
 using namespace llvm;
 using namespace builddfg;
 using namespace dfg2llvm;
@@ -157,15 +165,10 @@ void CGT_X86::initRuntimeAPI() {
   // Load Runtime API Module
   SMDiagnostic Err;
 
-  char *LLVM_SRC_ROOT = getenv("LLVM_SRC_ROOT");
-  assert(LLVM_SRC_ROOT != NULL && "Define LLVM_SRC_ROOT environment variable!");
-
-  Twine llvmSrcRoot = LLVM_SRC_ROOT;
-  Twine runtimeAPI =
-      llvmSrcRoot + "/../build/tools/hpvm/projects/hpvm-rt/hpvm-rt.bc";
-
-  runtimeModule = parseIRFile(runtimeAPI.str(), Err, M.getContext());
+  std::string runtimeAPI = std::string(LLVM_BUILD_DIR_STR) +
+                           "/tools/hpvm/projects/hpvm-rt/hpvm-rt.bc";
 
+  runtimeModule = parseIRFile(runtimeAPI, Err, M.getContext());
   if (runtimeModule == nullptr) {
     DEBUG(errs() << Err.getMessage() << " " << runtimeAPI << "\n");
     assert(false && "couldn't parse runtime");
diff --git a/hpvm/lib/Transforms/GenHPVM/CMakeLists.txt b/hpvm/lib/Transforms/GenHPVM/CMakeLists.txt
index 967766e7058c1ef8bcc1414afb7ff0087e3ce188..fc4c9fc5a98007dd700973c598b6731edcd61e14 100644
--- a/hpvm/lib/Transforms/GenHPVM/CMakeLists.txt
+++ b/hpvm/lib/Transforms/GenHPVM/CMakeLists.txt
@@ -2,6 +2,8 @@ if(WIN32 OR CYGWIN)
   set(LLVM_LINK_COMPONENTS Core Support)
 endif()
 
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${PROJECT_BINARY_DIR}")
+
 add_llvm_library( LLVMGenHPVM
   MODULE
   GenHPVM.cpp
diff --git a/hpvm/lib/Transforms/GenHPVM/GenHPVM.cpp b/hpvm/lib/Transforms/GenHPVM/GenHPVM.cpp
index 738b39905b885aa42bc861e3a19c3bdf9c65668e..d6ad357a33dee7014ef703c7abba00c28b325378 100644
--- a/hpvm/lib/Transforms/GenHPVM/GenHPVM.cpp
+++ b/hpvm/lib/Transforms/GenHPVM/GenHPVM.cpp
@@ -32,6 +32,14 @@
     }                                                                          \
   } while (0)
 
+#ifndef LLVM_BUILD_DIR
+#error LLVM_BUILD_DIR is not defined
+#endif
+
+#define STR_VALUE(X) #X
+#define STRINGIFY(X) STR_VALUE(X)
+#define LLVM_BUILD_DIR_STR STRINGIFY(LLVM_BUILD_DIR)
+
 using namespace llvm;
 using namespace hpvmUtils;
 
@@ -263,16 +271,11 @@ bool GenHPVM::runOnModule(Module &M) {
   // Load Runtime API Module
   SMDiagnostic Err;
 
-  char *LLVM_SRC_ROOT = getenv("LLVM_SRC_ROOT");
-  assert(LLVM_SRC_ROOT != NULL && "Define LLVM_SRC_ROOT environment variable!");
-
-  Twine llvmSrcRoot = LLVM_SRC_ROOT;
-  Twine runtimeAPI =
-      llvmSrcRoot + "/../build/tools/hpvm/projects/hpvm-rt/hpvm-rt.bc";
-  DEBUG(errs() << llvmSrcRoot << "\n");
+  std::string runtimeAPI = std::string(LLVM_BUILD_DIR_STR) +
+                           "/tools/hpvm/projects/hpvm-rt/hpvm-rt.bc";
 
   std::unique_ptr<Module> runtimeModule =
-      parseIRFile(runtimeAPI.str(), Err, M.getContext());
+      parseIRFile(runtimeAPI, Err, M.getContext());
 
   if (runtimeModule == NULL) {
     DEBUG(errs() << Err.getMessage() << " " << runtimeAPI << "\n");