Problem
When you install a package with vcpkg
it tells you the CMake targets. But if you didn’t make a note of them at the time, how do you find out what they are?
And what if you want the CMake targets for a package’s dependencies?
Solution
To show the CMake targets for a package, just re-run vcpkg install
on it.
When you install a package, vcpkg
tells you the CMake targets to put in CMakeLists.txt
.
For example, here’s the output after installing sdl2-image:x64-windows
for the first time.
C:> vcpkg install sdl2-image:x64-windows
...
The package sdl2-image:x64-windows provides **CMake** targets:
find_package(sdl2-image CONFIG REQUIRED)
target_link_libraries(main PRIVATE SDL2::SDL2_image)
It will show the same information if you re-run vcpkg install
on a package that is already installed.
Don’t laugh, but it took me about an hour to figure this out.
Dependencies
Some packages have dependencies that are useful in their own right, so you might also want to use those with CMake. To find the dependencies for a vcpkg
package, run vckpg depend-info
.
For example, here are the dependencies for sdl2-image:x64-windows
.
C:> vcpkg depend-info sdl2-image:x64-windows
zlib:
libpng: zlib
sdl2:
sdl2-image: libpng, sdl2
One of the dependencies is libpng
. You can find its CMake targets by running vcpkg install
.
C:> vcpkg install libpng:x64-windows
...
The package libpng:x64-windows provides CMake targets:
find_package(libpng CONFIG REQUIRED)
target_link_libraries(main PRIVATE png)