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

Scott Bloom scott at towel42.com
Mon Jan 21 11:01:52 EST 2019


Can you make it work by running msbuild directly?

What about building using visual studio from the command line?

Scott

-----Original Message-----
From: CMake <cmake-bounces at cmake.org> On Behalf Of nick at appletonaudio.com
Sent: Sunday, January 20, 2019 21:02
To: cmake at cmake.org
Subject: [CMake] Different behavior between building using "cmake --build" and building in Visual Studio

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
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list