title: Get C/CXX FLAGS set by commands add_definitions() and add_compile_options()
body: <p>In my <code>CMakeLists.txt</code>, global C and CXX flags are set using commands <a href="https://cmake.org/cmake/help/latest/command/add_definitions" rel="nofollow">add_definitions()</a>
  and
  <a href="https://cmake.org/cmake/help/latest/command/add_compile_options.html" rel="nofollow">add_compile_options</a>.</p>
  
  <p>Many attempts to retrieve the C/CXX flags:</p>
  
  <ol>
  <li><code>${CMAKE_C_FLAGS}</code> and <code>${CMAKE_CXX_FLAGS}</code> are empty</li>
  <li><code>${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}</code> is the original default CMake value<br>
  (e.g. <code>-g</code> for <code>CMAKE_C_FLAGS_DEBUG</code>)</li>
  <li><code>${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}</code> same as above</li>
  <li><code>get_cmake_property(def COMPILE_DEFINITIONS)</code> is <code>NOTFOUND</code></li>
  <li><code>get_cmake_property(opt COMPILE_OPTIONS)</code> is also <code>NOTFOUND</code></li>
  </ol>
  
  <p>I want to pass my custom C/CXX flags to an external project based on <code>./configure</code>:</p>
  
  <pre><code>ExternalProject_Add( my_external_lib
    DEPENDS            Threads::Threads
    SOURCE_DIR         ${CMAKE_CURRENT_LIST_DIR}
    BUILD_IN_SOURCE    1
    UPDATE_COMMAND     echo "Full clean" &amp;&amp; make distclean
    CONFIGURE_COMMAND  ${CMAKE_CURRENT_LIST_DIR}/configure
         --prefix=${CMAKE_BINARY_DIR}
         --cc=${CMAKE_C_COMPILER}
         --cxx=${CMAKE_CXX_COMPILER}
         --CFLAGS=${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}
         --CXXFLAGS=${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}
         --LDFLAGS=${CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}
         --ARFLAGS=${CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}
         --enable-static
  )
  </code></pre>
  
  <p>(1) <strong>How to get compilation flags set by <a href="https://cmake.org/cmake/help/latest/command/add_definitions" rel="nofollow">add_definitions()</a> and <a href="https://cmake.org/cmake/help/latest/command/add_compile_options.html" rel="nofollow">add_compile_options</a>?</strong></p>
  
  <p>Note: I use CMake version 3.3.2</p>
  
  <hr>
  
  <p><sub>While writing the question, I realize I am wondering another question:</sub></p>
  
  <p>I use <code>ccache</code> but the <code>./configure</code> script does not see my environment variables <code>CC</code> and <code>CXX</code> when I set them like that:</p>
  
  <pre><code>get_cmake_property(launcher   RULE_LAUNCH_COMPILE)
  set(ENV{CC}  ${launcher} ${CMAKE_C_COMPILER})
  set(ENV{CXX} ${launcher} ${CMAKE_CXX_COMPILER})
  </code></pre>
  
  <p>(2) <strong>Are these above CMake statements correct?</strong></p>
  
  <hr>
  
  <p><sub>Oops I have again another question:</sub></p>
  
  <p>I retrieve the <code>LDFLAGS</code> and <code>ARFLAGS</code> from the same variable <code>${CMAKE_STATIC_LINKER_FLAGS}</code>.<br>
  (3) <strong>Is there another CMake variable to set <code>ARFLAGS</code>?</strong></p>