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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Nick Appleton
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
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior between building using "cmake --build" and building in Visual Studio

Scott Bloom
Can you make it work by running msbuild directly?

What about building using visual studio from the command line?

Scott

-----Original Message-----
From: CMake <[hidden email]> On Behalf Of [hidden email]
Sent: Sunday, January 20, 2019 21:02
To: [hidden email]
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
--

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
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior between building using "cmake --build" and building in Visual Studio

Nick Appleton
Hi Scott,

Yes, I can invoke msbuild directly on the CMake generated solution
using:

msbuild theproject.sln /p:Platform=Win32

And everything builds fine. I cannot get the same behaviour using CMake
--build - is there a way to determine exactly the arguments CMake is
invoking msbuild with?

On 2019-01-22 03:01, Scott Bloom wrote:

> Can you make it work by running msbuild directly?
>
> What about building using visual studio from the command line?
>
> Scott
>
> -----Original Message-----
> From: CMake <[hidden email]> On Behalf Of
> [hidden email]
> Sent: Sunday, January 20, 2019 21:02
> To: [hidden email]
> 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
--

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
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior between building using "cmake --build" and building in Visual Studio

Scott Bloom
Strange...

When I had a similar problem, the command line for msbuild required the same level of detail.

What about running it from visual studio on the command line?

Scott

-----Original Message-----
From: [hidden email] <[hidden email]>
Sent: Monday, January 21, 2019 14:33
To: Scott Bloom <[hidden email]>
Cc: [hidden email]
Subject: Re: [CMake] Different behavior between building using "cmake --build" and building in Visual Studio

Hi Scott,

Yes, I can invoke msbuild directly on the CMake generated solution
using:

msbuild theproject.sln /p:Platform=Win32

And everything builds fine. I cannot get the same behaviour using CMake --build - is there a way to determine exactly the arguments CMake is invoking msbuild with?

On 2019-01-22 03:01, Scott Bloom wrote:

> Can you make it work by running msbuild directly?
>
> What about building using visual studio from the command line?
>
> Scott
>
> -----Original Message-----
> From: CMake <[hidden email]> On Behalf Of
> [hidden email]
> Sent: Sunday, January 20, 2019 21:02
> To: [hidden email]
> 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
--

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
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior between building using "cmake --build" and building in Visual Studio

SergSuslenkov
In reply to this post by Nick Appleton
Hi Nick,

Not sure if it is relevant for you, but for other who will search.

I have the same problem.
What I found:

1. When you issue "cmake --build", it runs following command line:
msbuild ALL_BUILD.vcxproj /p:Platform=Win32 ...

So it is not a solution file, that have rules to match configurations, but a
ALL_BUILD project file.

2. inside each *.vcxproj, there is a section(s)
    <ProjectReference Include=&quot;&lt;path_to>\ZERO_CHECK.vcxproj">
      <Project>{979FF7F1-351C-30B2-9F05-100EBC38B87E}</Project>
      <Name>ZERO_CHECK</Name>
    </ProjectReference>

  There is reference for each dependent projects.

3. ms build is using this information to build project and all its
dependencies.

4. however, <ProjectReference ..> does not contain configuration matching
rules (set with MAP_IMPORTED_CONFIG_XXX)

5. there is a way to specify configuration in ProjectReference, but VS
generator in CMake does not have this ability.
5.1. Way to specify:
https://stackoverflow.com/questions/6624168/configuration-for-projectreference-in-msbuild
<ProjectReference Include="path to project.projext">
  <SetPlatform>Platform=x64</SetPlatform>
  <SetConfiguration>Configuration=Release</SetConfiguration>
</ProjectReference>

Conclusion: I don't think that CMake can do it right now.
I plan to add Debug/Release targets on my proprietary provided projects.
Probably this can be address in future version of CMake.

Regards,
Serg



--
Sent from: http://cmake.3232098.n2.nabble.com/
--

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