Example or Sample of CPack Generator for NuGet

Today I bought Professional CMake, 15th Edition which says, “CMake 3.13 added a special External generator which doesn’t produce packages itself, but instead creates a JSON file which some other process can consume to produce packages outside of CPack.” Unfortunately, it doesn’t say what that other process is that generates the .nupkg, nor give an example CMakeLists,txt fragment. There is only a single paragraph (28.4.11) that makes reference to configuration variables.

The CPack NuGet Generator documentation provides a list of variables but makes no mention of a JSON file. I found the source code for the NuGet generator, which leverages inherited classes and macros and is relatively short. Without understanding the CPack architecture, it is hard to know what it is doing. I’ve googled for an example or sample or tutorial. Nothing. Exploring the git repo, I found the test CMakeLists.txt for the NuGet generator. I merged the example into my CMakeLists.txt, although there were some adjustments as this is a C++ project. Nothing is generated. No JSON, no .nupkg. Perhaps I am missing some basic way in which CPack is used. Could someone please point me at an example or tutorial that would generate a .nupkg file?

The External generator has nothing to do with NuGet. It is its own separate package generator (actually, it’s a special one that is mean to provide details to something else to do the packaging, not an actual standalone package generator). I think you may have missed that the External generator section of the book is separate from the NuGet section that precedes it.

As for NuGet, the Professional CMake book has very little detail about it because, frankly, I have no experience with it, nor seen a single project using it. I’m sure it works for its original intended purpose, but I can’t offer any advice on its use.