I am creating a NuGet package of a C++ CMake project using CPack.
cmake -S . -B build
cmake --build build --config Release
cd build
cpack -G NuGet -C 'Release'
I have defined several cpack variables, e.g.:
CPACK_PACKAGE_NAME
CPACK_PACKAGE_VENDOR
CPACK_PACKAGE_DESCRIPTION
- The package is generated successfully. It contains an include and lib directory, just as the CMake's
install()
commands it to. - I can add the NuGet package to my project in Visual Studio. The content gets installed.
- But the project doesn't find the headers and libs. I guess the meta data is missing in the package.
How do I add this info? Or am I missing something?
The meta info I was looking for can be found in a .targets file. See here for more info.
So I manually created such a file and added it with a cmake
install()
instruction, so cpack would include it in the NuGet package. Important: Visual Studio looks for it in a subdirectory calledbuild
, more specifically:<nuget root>/build/**/<nuget name>.targets
. It looks something like this:I mostly reverse engineered the syntax from random nuget packages. I'm not 100% happy with this solution. But it works.
Fee free to tell me more about it if you know anything :-)