Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the list of dependencies of cmake target?

Tags:

cmake

For instance, how can I know if my executable target E depends on my library target L?

Let's image E depends on L1 and L2, but I don't know if they depend on L.

target_link_libraries(E L1 L2)

I'd like to get the list from CMake itself before calling target_link_libraries, so that I can do some tricks if I detect that E depends on two libraries which are incompatible. I played a bit with GetPrerequisites, but this finds out dependencies on existing libraries which are on disk, not on target which are being built.

thanks

like image 332
Daniel Pinyol Avatar asked Feb 25 '14 17:02

Daniel Pinyol


People also ask

How do I add dependencies to a CMake project?

The simplest way of doing dependency management is to simply copy source code of your dependencies into your project source directory. For example, you can just copy SFML sources to your <source-dir>/dependencies/SFML and then just do add_subdirectory (dependencies/SFML) in your main CMake file (and then link to SFML’s targets as needed)

How do I build a specific target in CMake?

cmake --build . You can also build a specific target if you run You’ll find the executable in <your-build-dir>/src/ directory or <your-build-dir>/Debug/src if you’re using Visual Studio to build the project. $ ./src/example_exe Hello, world! If you've generated a Visual Studio solution, you can just use Visual Studio for building.

How do I link multiple libraries in CMake?

However, you can use a cmake variable to collect the name of the libraries that you want to link (using the set ( ... or the list (APPEND ... command), and then use this variable in your target_link_libraries command: The same variable can also be used to create your copy commands (for example using this custom target)

How does CMake work with imgui?

Basically, CMake will take build artifacts of ImGui-SFML, sfml-graphics, sfml-window and sfml-system targets (DLLs) and copy them to the directory where executable example_exe will be built. Note that this is only done when you’re building your project, not installing it (when you run cmake --build . --target install ).


2 Answers

You can use CMake's "dependency graphs generator". Please read this link for details

cmake --graphviz=test.dot . ... 
like image 56
Peter Avatar answered Sep 29 '22 03:09

Peter


While graphviz output likely is more intuitive, sufficiently equivalent functionality can be enabled via a simple

set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1) 

GLOBAL_DEPENDS_DEBUG_MODE cmake.org help

like image 43
LinuxDev Avatar answered Sep 29 '22 04:09

LinuxDev