CMake and MsVS-NuGet

Mr.Manhattan picture Mr.Manhattan · Aug 8, 2013 · Viewed 12.9k times · Source

I'm currently developing a desktop application, using the C++ REST SDK (codename Casablanca), Qt5 and some other libraries.

For the project setup, I use CMake.

How to get CMake to install NuGet Packages?

I now have to install it each time manually, if I rerun CMake, which isn't really an option.

Answer

Markus Mayer picture Markus Mayer · Jul 18, 2014

The command line reference of NuGet is located at http://docs.nuget.org/docs/reference/command-line-reference

You can install packages using the nuget install or nuget restore command. nuget update updates the installed packages (restore must be run beforhand).

You can instruct cmake to run NuGet before every build by using:

add_custom_command(TARGET ${PROJECT_NAME}
    PRE_BUILD
    COMMAND nuget restore ${CMAKE_BINARY_DIR}\yourSolution.sln
)

or at configure time using execute_process.

You can prepare the nuget config file using configure_file or use appropriate nuget install commands directly.