title: Set installation prefix automatically to custom path if not explicitly specified on the command line
body: <p>For some internal tests, I would like the install prefix to default to a subdirectory of the build directory, unless explicitly overridden by the user. I know the user can specify a install prefix by:</p>
  
  <pre><code>$ cmake -DCMAKE_INSTALL_PREFIX=/foo/bar ..
  </code></pre>
  
  <p>But if the user does <em>not</em> specify this, it should default to, e.g. <code>${PWD}/installed</code>.</p>
  
  <p>The variable <code>CMAKE_INSTALL_PREFIX</code> is already set to <code>/usr/local</code>, so I cannot just check to see if it unset/empty before setting it.</p>
  
  <p>My current solution is to add a custom switch that the user has to invoke to specify that the <code>CMAKE_INSTALL_PREFIX</code> variable gets respected:</p>
  
  <pre><code>option(ENABLE_INSTALL_PREFIX "Install build targets to system (path given by '-DCMAKE_INSTALL_PREFIX' or '${CMAKE_INSTALL_PREFIX}' if not specified)." OFF)
  if ( ENABLE_INSTALL_PREFIX )
      set (CMAKE_INSTALL_PREFIX installed CACHE PATH "Installation root")
  else()
      set (CMAKE_INSTALL_PREFIX installed CACHE PATH "Installation root" FORCE)
  endif()
  </code></pre>
  
  <p>My questions are:</p>
  
  <p>(a) Are there any issues with the above, beyond the annoyance of the extra flag needing to be passed to CMake to get <code>CMAKE_INSTALL_PREFIX</code> to have an effect?</p>
  
  <p>(b) Is there a better, cleaner, more robust, more idiomatic and/or less annoying way to achieve the above?</p>
  
  <p>Thanks.</p>