I struggle to create a NuGet package from a native C++ library. For now, I have the following setup:
include(GNUInstallDirs)
file(RELATIVE_PATH relDir
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relDir})
set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME})
# ...other CMake config...
install(TARGETS MyLib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mylib
)
set(CPACK_PACKAGE_NAME MyLib)
set(CPACK_PACKAGE_VENDOR Me)
# ...standard CPack variables...
if(WIN32)
set(CPACK_NUGET_PACKAGE_TAGS "Native" "native")
set(CPACK_GENERATOR ZIP;NuGet)
else()
set(CPACK_GENERATOR TGZ)
endif()
include(CPack)
Then, I run cmake --build . --target package
to package my lib, and CMake correctly generates a .nupkg
file containing the .lib
and .h
files I want. But then, when I try to use the generated package in a C++/WinRT project, I cannot #include
the packaged headers.
So I have the following questions :
- according to this SO answer and MS documentation, the packaged files should follow a certain hierarchy. Do I need to change CMake
install()
paths? - according to this SO answer, the reason I cannot find my headers is because I don't have any
.targets
file. Do I need to create one myself or is there a way to tell CPack to generate it?