Describing dependency on .targets file for Visual Studio project.
It is great if CMake allows to describe dependency on .targets file that comes with a NuGet package. I have found numerous feature requests for NuGet support, but I think what really matters is this .targets file. Doesn’t matter if the package comes with NuGet or in a .Zip file. After experimenting, other NuGet related files like packages.config are for Visual Studio to keep track of packages, and not really needed for build.
Now Microsoft distributes OpenGL ES2.0 library (ANGLE.WindosStore) for Universal Windows Platform with NuGet. If I am able to build a project that uses this library, it opens up possibilities of porting programs written for other platforms with OpenGL ES 2.0. Also, for drawing text messages to the texture, Win2D library (Win2D.uwp) apparently is the best option. However, this library is also distributed via NuGet.
I am able to automate download of the package by execute_program inside CMakeLists.txt. However, I cannot properly add dependencies to the libraries. For OpenGL ES library, I could somehow use find_path, find_library to set up include directories, libraries, and DLLs. However, Win2D uses a .winmd file, which I have no idea what to do with from the current version of CMake.
What’s needed is to add: for OpenGL ES 2.0 library, and for Win2D library in the .vcxproj that uses these packages. This tag apparently needs to be immediately before the last , or between and . All I need is these two lines in .vcxproj files that rely on these packages.
If this tag is in .vcxproj, Visual Studio 2015 automatically adds include directories, and choose appropriate .lib and .dll files for the architecture, and copy .dll files to the AppX package directory during the deployment.
Right now, I am adding these tags from a Python script after running CMake. I am using target property VC_GLOBAL_propertyname to write a specific keyword in .vcxproj to identify if a .vcxproj needs these packages. So, the project generation takes two steps. Actually, by running CMake within my Python script, it is one command, but when CMake is re-run from msbuild, I need to manually run this script to update .vcxproj files. I can live with it for now, but not a clean solution. The biggest problem is I need to do this trick for all the projects that depends on the packages. What’s ideal is if one of my libraries depends on these packages, and if another target depends on the library, I want the tags to be written in .vcxproj files of all depending targets. Minor problem is when msbuild re-runs CMake, my script is not run automatically.
I also tried to modify .vcxproj in a pre-build command. I was expecting the first build to fail, but the second build may succeed. Turned out, modifying .vcxproj during the build was not a good idea, and .vcxproj file just got corrupted.
There can be many ways to make it possible. Options can be for example:
- CMake recognizes .targets file as an imported library, and adds tag if a project depends on this library.
- Let find_library recognize NuGet package as a library, just like a framework for XCode. Also make some ways of finding .DLL files so that the files can be marked as VS_DEPLOYMENT_CONTENT. (But I still don’t know what to do with .winmd type library)
- It is just a temporary fix, but add a target property like VC_VCXPROJ_TAG to allow inserting a tag in the vcxproj directly. Which may not be the best, but it allows a temporary relief when Visual Studio adds a new feature until CMake officially supports the feature.
- Do it as a post-generation command, but looks like the idea of post-generation command is not accepted? (http://public.kitware.com/Bug/view.php?id=13020) Anyway doing it from the post-generation command will also be just a temporary fix.
I think the best thing is to let CMake recognize .targets file as a kind of library (the first option) because if a library depends on a .targets file, an execurable that uses the library also needs a tag.
I made sure by reading CMake source code that the current version (3.6.2) of CMake does not write this tag for user-specified .target files, but if there is already a solution to my problem, please let me know and I appreciate.
Thank you for the consideration.