title: Best way to portably set compiler options like -Wall and -pedantic in CMake
body: <p>Even if I don't want to tie my CMakeLists file to a specific compiler, I still would like to enable certain options like -Wall that I know many compilers support.</p>
  
  <p>Currently I am doing it like this to set the -Wall and -pedantic flags if they are accepted by the current compiler:</p>
  
  <pre><code>include(CheckCXXCompilerFlag)
  
  check_cxx_compiler_flag(-Wall temp)
  if(temp)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  endif()
  check_cxx_compiler_flag(-pedantic temp)
  if(temp)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
  endif()
  </code></pre>
  
  <p>Is there a better way? Or at least a nicer way to do essentially the same thing? The above is incredibly verbose and ugly for what it achieves. A much nicer command would be something like:</p>
  
  <pre><code>enable_cxx_compiler_flags_if_supported(-Wall -pedantic)
  </code></pre>