title: How to apply different compiler options for different compilers in cmake?
body: <p>I'm currently working on using cmake to build some projects, with the main platforms being Visual C++, MinGW GCC and Linux GCC. When building with GCC, I need to specify the <code>-Wno-invalid-offsetof</code> compiler option.</p>
  
  <p>My current fix is as follows...</p>
  
  <pre><code>if (   "${CMAKE_GENERATOR}" MATCHES "^Visual Studio"
      OR "${CMAKE_GENERATOR}" MATCHES "^NMake"
     )
      set (CPPLIB_COMPILER_OPTS "")
  else ()
      set (CPPLIB_COMPILER_OPTS "-Wno-invalid-offsetof")
  endif ()
  
  ...
  
  set_target_properties(sh_core PROPERTIES COMPILE_FLAGS "${CPPLIB_COMPILER_OPTS}")
  # repeated for all targets
  </code></pre>
  
  <p>This works, but assuming that all generators other than the visual studio ones will build with gcc is obviously unsafe. For a start, there are IIRC generators for Borland compilers. More importantly, using make doesn't always mean using gcc.</p>
  
  <p>Other compilers I'm likely to use are llvm-gcc and clang. Fortunately, I think even clang supports gcc-compatible options. But this logic is only good for as long as the relevant code is never released.</p>
  
  <p>Cmake appears to check for available compilers and generate a makefile specifically for that compiler (raising the question - why not at least have the option of building the project directly, without the need for a middle-man like make?).</p>
  
  <p>That being the case, I was hoping to be able to test directly for gcc in my CMakeLists.txt files. So far, though, I can't find an appropriate variable to test or any other obvious solution.</p>
  
  <p>Is this possible?</p>