title: How to add an images folder to CMake project in order to use those images in the c++ executables?
body: <p>I am totally new to Qt and CMake. I have been doing a google test on my project (cmake and qt) for which I need to test the match of two images. I have a folder (outside the project directory) that contains these images. I want to access these images but not using the absolute path.</p>
  
  <p>Something like this:</p>
  
  <pre><code>imread("home/../../test_images/img1.jpg")
  </code></pre>
  
  <p>But I want to set a common path for the images folder, so that anybody using my project later on will just have to set their <code>test_image</code> folder path with respect to their machine, and need not make changes in the code.</p>
  
  <p>I have tried the following so far.</p>
  
  <p>1 . Tried adding a <code>.qrc</code> resource file and tried to access the images. (This did not work since the images folder was outside the project directory.)</p>
  
  <ol start="2">
  <li>Tried to set a Path variable in QT build environment settings. </li>
  </ol>
  
  <p>None of the two methods worked.</p>
  
  <p>What I am trying to accomplish: "To be able to avoid using an absolute path for the images I use and allow people trying to implement my code to only change the path at one place with their own test image locations."</p>
  
  <p>Edit:
  Looking for a way for setting a variable <code>eg.IMG_PATH = "/path/to/image/files"</code> which can be set once and only the variable is used all over the executable files. So when someone clones my project they will just have to update the <code>IMG_PATH</code> variable with the path to where their image files are located. So that now the <code>IMG_PATH</code> variable gets updated everywhere in the remaining parts of the project. </p>
  
  <p><strong>UPDATE after answer given by @squareskittles :</strong></p>
  
  <p><strong>My project Structure  :</strong></p>
  
  <pre><code>Project_Tester
  
  |--CMakeList.txt
  
  |--ExecutableScript.sh.in   
  
  |--test
  
         |---CMakeList.txt
  
         |---sample1.cpp
  
         |---sample2.cpp
  
         |---main.cpp
  
  </code></pre>
  
  <p>Sample 1,2 are c++ files with different testcases.
  The main.cpp runs all tests in the sample.cpp files, as below :</p>
  
  <pre><code>#include "gtest/gtest.h" 
  
  int main(int argc, char** argv)
   { 
         ::testing::InitGoogleTest(&amp;argc, argv);
  
         return RUN_ALL_TESTS(); 
  }
  </code></pre>
  
  <p>According to answer given by @squareskittles , How should i structure my main.cpp ,to be able to use/access the variable <strong>"IMAGES_PATH"</strong> in the files sample1.cpp and sample2.cpp ?</p>
  
  <ol>
  <li><p>Is there a way to do it from QT Creator alone than running it from the terminal ?(by modifying .sh file contents)?</p></li>
  <li><p>Or can the Path be set manually in the <strong>ExecutableScript.sh.in</strong> file ?</p></li>
  <li><p>How can I access this variable that is set, from the other cpp files of the project ?</p></li>
  </ol>