Skip to content

Add generator expression to exclude auto generated files

Until now, we have been using msbuild for static code analysis of MSVC in our CI. Now we have switched to Ninja. This means we also have to pass the analysis options via target_compile_options instead of using VS_GLOBAL_CodeAnalysisRuleSet.

This lead to code like this:

if(CMAKE_GENERATOR MATCHES "Visual Studio")
  set_target_properties(${target} PROPERTIES
    VS_GLOBAL_RunCodeAnalysis true
    VS_GLOBAL_EnableMicrosoftCodeAnalysis true
    VS_GLOBAL_CodeAnalysisRuleSet ${VS_GLOBAL_CodeAnalysisRuleSet}
  )
else()
  # For command line tools
  target_compile_options(${target} PRIVATE $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/analyze /analyze:external- /analyze:ruleset "${VS_GLOBAL_CodeAnalysisRuleSet}" /analyze:plugin EspXEngine.dll>)
endif()

However, the problem currently is that these options are also passed on to the autogen files (of Qt).

So far, I have not found a workaround to ensure that these options are only used for our files:

  • We cannot use set_source_files_properties because we use target_sources to add files to a target and cannot read them out of the target later.
  • Using the generator expression SOURCE_FILE is also not possible because, to my knowledge, wildcards are not supported.

Therefore, it would be useful if we could use a generator expression to query whether a file was added automatically or not.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information