I'm trying to understand a good method for understanding expansive CMake projects (several layers of subdirectories) without having to be intimately familiar with every part of the project. In short I'd like to have some sort of code navigation ability for cmake files. This could potentially be something like ctags or VS Code's Intellisense's "Go To Definition" that can take some library name, (or generally some variable) and go to the definition of the library or variable. I'll clarify what I mean by "definition of the library" in the example below.
Here is a simple example, where I wouldn't need such a tool, but I hope makes the question more clear. Say I had a library module_a
created by cmake in a file src/module_a/CMakeLists.txt
:
add_library(module_a STATIC
module_a.c
)
target_include_directories(module_a PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
and an executable that depends on this library, that is created via src/main/CMakeLists.txt
:
add_executable(main
main.c
)
target_link_libraries(main
module_a
)
Is there any way for me to know what module_a
is referencing within the src/main/CMakeLists.txt
without already knowing about the file src/module_a/CMakeLists.txt
? In other words I want to be able to look at a single CMakeLists.txt file within a larger project and have some tool be able to tell me where the variables, libraries, and other dependencies are defined.
For the above example, I'd like to open src/main/CMakeLists.txt
and click something and jump to src/module_a/CMakeLists.txt
on the add_library
call in src/module_a/CMakeLists.txt
. In this way I can see what I'm calling the "definition of the library".
If no such tool/plugin exists, what is there a good way to grep the output directory of cmake to find this information? I'm guessing the information is in there somewhere, but I'm just not sure what to look for and just a blanket grep -R module_a src/build
even for this simple example is an overwhelming amount of information.