I already use a compile_commands.json. I pass it to all my static analyzers. But the problem is that the compile_commands.json has all files in it. So I need to add filter to the static analyzers to only the entries belonging to the target.
So that’s what I basically try to do. Pass the source files to the static analyzer and the static analyer will then pick up the entry from the compile_commands.json
"command": "<compiler> .... -o some/path/someTarget.dir/someFile.o",
So your suggestion, as far as I understood it, is that I query this file for an all the entries that contain
-o .../myTarget.dir/.... For instance as a python script.
I guess that should be doable.
The cmake-file-api would be an alternative to python? How can it help me here? I had a look at it, but it seems not too easy to use.
Regarding an “official way” → There are basically two problems here:
SOURCES contains absolute and relative paths. The relative paths basically just need to be prepended with the target source directory, right? So I just need to add some logic to determine if a path is already absolute
May I can even use https://cmake.org/cmake/help/latest/command/cmake_path.html#generation? This sounds like I can pass both relatives and absolute paths in it and it will just convert the relativ paths
- Getting all the source files. Currently I can use SOURCES already, but I need to call then my function at the end and cannot use generator expressions in the target_sources. Not nice, but kinda acceptable for now.
Better would it be to use a generator expression myself, which solves both of these issues. But then SOURCES will contain also inherited source files.
→ Is this something CMake could improve? → I feel like in general it would be useful to have a seperation between inherited and directly specified sources / libraries / include paths? This would also help in other scenarios.
Is this something that could be added to cmake, so have for instance three variables SOURCES (as before) and addionally a SPECIFIED_SOURCES and possible INHERITED_SOURCES? (SOURCES would then be a merge of these two)?