I'm building a cross-platform library with CMake which has a few (pretty common) dependencies (e.g. PCRE). The dependencies are available through the usual package managers (APT on Ubuntu/Debian, Homebrew on OSX), and also through NuGet on Windows. In my CMakeLists.txt
, I use the "module" version of find_package
to locate these dependencies and set the right include/library flags.
This question provides one way of integrating CMake + NuGet, but also suggests that CMake and NuGet aren't likely to play nice together, and I can't seem to find a way to get find_package
to find the installed dependencies. Is there some way to get CMake to read the NuGet config files (ala the way pkg_check_modules
works on systems with pkg-config
) and populate the appropriate CMake variables from there? Or do I have to hand-roll my own solution in FindPCRE.cmake
?
CMake searches for a file called Find<package>. cmake in the CMAKE_MODULE_PATH followed by the CMake installation. If the file is found, it is read and processed by CMake. It is responsible for finding the package, checking the version, and producing any needed messages.
CMake ships with its own set of built-in find_package scripts, and their location is in the default CMAKE_MODULE_PATH.
As of CMake 3.15, CMake now supports referencing Nuget packages with VS_PACKAGE_REFERENCES
, without the need for the Nuget CLI, or hard-coding paths to references. To add a Nuget package reference to a CMake target, we can use the syntax <package-name>_<package-version>
. Here is a simple example for the Nuget logging package Serilog
version 2.9.0:
set_property(TARGET MyLibrary
PROPERTY VS_PACKAGE_REFERENCES "Serilog_2.9.0"
)
The linked documentation shows how you can add multiple Nuget packages by semicolon-delimiting ;
the package arguments.
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