title: gcc/g++ alternative to defines
body: <p>I am using a CMake build system for my project.</p>
  
  <p>I want my program executable to know the Project Directory at all times,
  I thought i could set an environment variable and use:</p>
  
  <pre><code>getenv("MYPROJDIR")
  </code></pre>
  
  <p>But i don't want to create a persistent variable across the system, and i don't want to manually create a temporary variable everytime before executing my program.</p>
  
  <p>Is there a way to set some variable in build time so that my source knows the project directory, and can access input files relative to that directory regardless of the location where it is executed from.</p>
  
  <p>I could use a define with the -D switch or:</p>
  
  <pre><code>add_definitions(-DMYPROJDIR=${PROJECT_SOURCE_DIR})
  </code></pre>
  
  <p>but i have heard people say not to use macros unless absolutely necessary.</p>
  
  <p>Overall i need this funtionality:</p>
  
  <pre><code>const string defaultinput = MYPROJDIR + "src/someinputdata.dat"
  ifstream myfile(defaultinput)
  </code></pre>