[cmake-developers] Visual Studio dependencies bug work-around

Robert Goulet Robert.Goulet at autodesk.com
Wed Apr 15 12:31:23 EDT 2015


Hi,

In our CMake setup, we currently have a dependency on a static library that is also part of the solution, but only when NOT building in Release. For clarity, let's call the application Foo, and the static lib Bar.

As such, we have defined EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1 on Bar cmake target properties. This work when using the solution from Visual Studio, we see that Bar is not selected for build in the properties of the solution in Release configuration. We also removed the link to Bar in the Foo cmake file, using generator expression target_link_library(Foo $<$<NOT:$<CONFIG:RELEASE>>:Bar>).

All seems to work from within Visual Studio, when we launch a Release build the Bar project is not built. However, when we launch a build from the command-line it does not work; it builds the Bar project. At first we thought it might be a cmake bug, but we can reproduce it using msbuild.exe command-line tool: It turns out this happens if we specify the target project to be built instead of the solution. In our case, we set the target project to be INSTALL.vcxproj generated by cmake.

We see that the dependency on Bar is still there when looking at the dependencies of Foo, which is ok because we need it in Debug, and that Visual Studio doesn't seems to support dependencies by configuration. When building from the command-line using msbuild.exe, if we tell it to build the solution instead of a specific project, it works as it should.

So now, my question is, has anyone experienced that before, and is there a work-around to this fail case? It seems to be a limitation of Visual Studio so I'm not sure what are my options.

Trying something like:
msbuild.exe foo.sln /t:INSTALL /p:Configuration=Release
...didn't work because INSTALL is never part of any targets in the solution

It seems the only way to skip building Bar is to tell msbuild to build the solution instead of the specific project, but we NEED to build INSTALL in this case.
Any ideas?

-Robert Goulet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20150415/67b6b91e/attachment.html>


More information about the cmake-developers mailing list