[CMake] Different behavior between building using "cmake --build" and building in Visual Studio

nick at appletonaudio.com nick at appletonaudio.com
Mon Jan 21 00:01:38 EST 2019


Hello,

I have a CMake project which is generating Visual Studio (VS2017) 
solutions which can be compiled using the Visual Studio IDE but cannot 
be built from the command line using "cmake --build".

The project contains a shared library which links against two static 
libraries. The two static libraries are non-CMake projects with .vcproj 
files which are generated using another (proprietary) build system. They 
are being included in the project on Windows using the 
include_external_msproject() command. These two projects do not have the 
standard configuration names ("Debug","Release",etc) and their 
configurations are mapped to the main CMake project's configurations 
using MAP_IMPORTED_CONFIG_XXX properties. This all works very well using 
the VS IDE.

There are two things that happen which I find surprising when I run 
"cmake --build":

1) It doesn't seem to automatically decide on the correct platform 
toolset version to use. So running "cmake.exe --build . --config Debug" 
ends up resulting in a build log containing lots of errors about missing 
tools. I can fix this by manually specifiying the toolset version as: 
"cmake.exe --build . --config Debug -- -property:PlatformToolset=v140" 
(if anyone can hint to why this happens, I would be interested - but it 
is secondary to the following issue) which results in:

2) The following issues in the build tool log:

"MY_DEVELOPMENT_PATH\PATH1\build\ALL_BUILD.vcxproj" (default target) (1) 
->
"MY_DEVELOPMENT_PATH\PATH2\library_1.vcxproj" (default target) (3) ->
(PrepareForBuild target) ->
   C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(349,5): 
error MSB8013: This project doesn't contain the Configuration and 
Platform combination of Debug|Win32. 
[MY_DEVELOPMENT_PATH\PATH2\dependent_library_1.vcxproj]


"MY_DEVELOPMENT_PATH\PATH1\build\ALL_BUILD.vcxproj" (default target) (1) 
->
"MY_DEVELOPMENT_PATH\PATH3\library_2.vcxproj" (default target) (4) ->
   C:\Program Files 
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(349,5): 
error MSB8013: This project doesn't contain the Configuration and 
Platform combination of Debug|Win32. 
[MY_DEVELOPMENT_PATH\PATH3\dependent_library_2.vcxproj]

Where library_1 and library_2 correspond to the two static libraries. 
Given the output, my guess is that the mapped configurations are not 
being honoured anymore (while they are definitely being honoured when 
the project is built inside Visual Studio). I would have assumed that 
CMake would invoke msbuild/devenv on the created solution and things 
would work, but it does not seem to be happening. Could anyone provide 
me with some information as to whether this is a bug in CMake or if I am 
missing something bigger here?

Thanks!

Nick


More information about the CMake mailing list