title: CMake -DCMAKE_CXX_COMPILER works but SET(CMAKE_CXX_COMPILER ...) is ignored?
body: <p>Been messing around trying to set the CPP compiler to <code>g++</code> using the following line in my toolchain file.</p>
  
  <pre><code># specify the cross compiler
  SET(CMAKE_CXX_COMPILER:FILEPATH /opt/qnx641/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.4.0-g++)
  </code></pre>
  
  <p>This didn't appear to be used, so I tried something right out just to be sue</p>
  
  <pre><code>SET(CMAKE_C_COMPILER:FILEPATH   /junk/gcc)
  </code></pre>
  
  <p>Okay, overkill, but this way I'm definitely sure CMake isn't doing any funny inferences from the path and command structure I was passing in.</p>
  
  <p>I'd gone down this route by looking at the <a href="http://www.cmake.org/Wiki/CMake_Cross_Compiling" rel="nofollow noreferrer"><strong><em>CMake Cross Compiling page</em></strong></a> where it talks about toolchain files.</p>
  
  <p>So read around a bit and decided to do it from the command line as <a href="http://www.cmake.org/pipermail/cmake/2011-May/044570.html" rel="nofollow noreferrer"><strong><em>this QA thread</em></strong></a> showed that the command line <code>-D</code> would override cached vars. </p>
  
  <p>This worked!</p>
  
  <p><strong>So my question is</strong>, does anyone know why when I do <em>not</em> use the <code>-D</code> command line option how CMake finds my cross-compiler path and exename but ignores the <code>SET(CMAKE_CXX_COMPILER...</code> line in my toolchain.</p>
  
  <p>I have, before each build deleted the <code>build</code> directory and the <code>CMakeCache.txt</code> file.</p>
  
  <p>For completeness the command line I'm using is</p>
  
  <pre><code>rm CMakeCache.txt; 
  rm -fr build; 
  cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=./build 
  -DMAKE_TOOLCHAIN_FILE=/path/to/toolchain-file.cmake 
  -C CMakeCrossCompile-TryRunResult-qnx-armle.cmake . 
  </code></pre>
  
  <p>The file <code>CMakeCrossCompile-TryRunResult-qnx-armle.cmake</code> does not contain <code>CMAKE_CXX_COMPILER</code>.</p>
  
  <p>Any clue to what's giong on much appreciated!</p>
  
  <p>I also used the -LA command line option to see the cached variables being used and its definitely not getting the right value from the <code>SET</code> command when the command linne <code>-D...</code> is <em>not</em> present...</p>
  
  <p>EDIT: I found the following <a href="http://www.cmake.org/pipermail/cmake/2012-February/049035.html" rel="nofollow noreferrer"><strong><em>CMake Support Request</em></strong></a> that recommends using environment variables, found <a href="https://stackoverflow.com/questions/9129233/recommended-ways-to-use-cmake-with-icc-via-configuration-options"><strong><em>via this SO thread</em></strong></a>.</p>
  
  <p>It seems that using the variables in the ToolChain file might be too late in the process? Strange, because it shows this method in the guide linked to above. Can any confirm/deny this? Thanks.</p>