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
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)
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.
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)
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 ).
You can use CMake's "dependency graphs generator". Please read this link for details
cmake --graphviz=test.dot . ...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With