Search code examples
c++cmakevcpkg

vcpkg: recalling the CMake instructions shown after installing a package?


After installing packages with vcpkg, help text is shown, eg...

The package fmt:x64-windows provides CMake targets:

    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt fmt::fmt-header-only)

... for the varying instructions needed for using them with CMake. Where do you get this information from if you want to recall it in the future and didn't write it down? Some libraries have more involved instructions than the above.


Solution

  • You can find the help text in files called 'usage'.

    You can locate them in either in ports directory or if you are interested only for your packages, then they are in installed. You can search for them with the following command:

    # VCPKG_ROOT denotes where is vcpkg installed
    $ find $VCPKG_ROOT . -name usage
    installed/x64-linux/share/openssl/usage
    installed/x64-linux/share/gtest/usage
    

    However some packages, including fmt, are not providing this information in a specific file, they are providing only targets. They are stored in $VCPKG_ROOT/installed/<YOUR_ARCHITECTURE>/share/fmt/fmt-targets.cmake.

    vcpkg is then printing a list of targets after the installation. I don't know if there exists a better solution then finding the <package>-targets.cmake files and checks the content.

    $ find $VCPKG_ROOT/installed -name *-targets.cmake 
    installed/x64-linux/share/cxxopts/cxxopts-targets.cmake
    installed/x64-linux/share/fmt/fmt-targets.cmake
    

    So if you combine these two techniques, you should be able to find all the information that vcpkg is printing after installation.