title: How do I access the source file name in CMake?
body: <p>I want to enable <a href="https://docs.microsoft.com/en-us/cpp/build/reference/analyze-code-analysis?view=vs-2019" rel="nofollow noreferrer">code analysis</a> using CMake and Ninja:</p>
  
  <pre><code>file(GLOB_RECURSE sources *.cpp)
  
  target_sources(${target}
      PRIVATE 
          ${sources}
  )
  
  target_compile_options(${target}
      PRIVATE
          -analyze:log report.xml
          -analyze:ruleset "${RuleSet}"
          -analyze:quiet
  )
  </code></pre>
  
  <p>The generated build.ninja looks roughly as follows (omitting a lot of irrelevant data):</p>
  
  <pre><code>build foo.cpp.obj: CXX_COMPILER foo.cpp:
    FLAGS = -analyze:log report.xml -analyze:ruleset "C:\rulesets\MixedRecommendedRules.ruleset" -analyze:quiet
  
  build bar.cpp.obj: CXX_COMPILER bar.cpp
    FLAGS = -analyze:log report.xml -analyze:ruleset "C:\rulesets\MixedRecommendedRules.ruleset" -analyze:quiet
  </code></pre>
  
  <p>The problem is that <strong>each source file is compiled individually</strong> and thus <strong>the report gets overwritten</strong> every time the compiler is invoked.</p>
  
  <p>Is there any way to <strong>include the source file name</strong> like this:</p>
  
  <pre><code>target_compile_options(${target}
      PRIVATE
          -analyze:log report_{source_file}.xml
          -analyze:ruleset "${RuleSet}"
          -analyze:quiet
  )
  </code></pre>