title: How do you specify a specific compiler in for CMAKE builds in Windows
body: <p>I am trying to get CMAKE to use a specific compiler when running.  Specifically, I want it to use the locally installed GCC compiler.  But when i try to <em>set</em> the <strong>CMAKE_C_COMPILER</strong> variable, it seems to fail.  </p>
  
  <pre><code>set(CMAKE_C_COMPILER "gcc")
  set(CMAKE_CXX_COMPILER "g++")
  
  cmake_minimum_required(VERSION 3.10)
  
  PROJECT(hello C)
  
  add_executable(hello hello.c)
  </code></pre>
  
  <h3>UPDATE USING TOOLCHAIN</h3>
  
  <p>I tried to make it work using the following toolchain file, but it still chooses Visual Studio build tools.  </p>
  
  <pre><code># Toolchain File
  
  # The target of this operating systems is 
  SET(CMAKE_SYSTEM_NAME Windows)
  
  # which compilers to use for C and C++
  SET(CMAKE_C_COMPILER gcc)
  SET(CMAKE_CXX_COMPILER g++)
  
  # here is the target environment located
  SET(CMAKE_FIND_ROOT_PATH  C:/MyPrograms/MinGW/bin/ )
  
  # adjust the default behaviour of the FIND_XXX() commands:
  # search headers and libraries in the target environment, search
  # programs in the host environment
  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  </code></pre>
  
  <h3>MORE UPDATES ON ISSUE</h3>
  
  <p>When i look at the cache file created when using the toolchain file, i find something interesting.  It is trying to point to the correct compiler, but it is using the Visual Studio Generator still... </p>
  
  <pre><code>//Name of generator.
  CMAKE_GENERATOR:INTERNAL=Visual Studio 15 2017
  //Generator instance identifier.
  CMAKE_GENERATOR_INSTANCE:INTERNAL=C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/ 
  </code></pre>
  
  <p>How do i deal with the generator here?</p>