3

I have a CMake file that generates VS2015 solution file MyApp.sln. I build MyApp.sln with the following commands separately for each configuration:

msbuild MyApp.sln /property:Configuration=Debug
msbuild MyApp.sln /property:Configuration=RelWithDebInfo
msbuild MyApp.sln /property:Configuration=Release

I wonder if anyone knows how to build all the configurations with a single msbuild command. Probably CMake can generate some 'All' configuration, for example?

My question is a bit different from How can I build all with MSBuild from the command line?, because I do not modify MyApp.sln file manually, but it is generated by CMake, so I need either some option in CMake to create 'all' target or call msbuild in a way it builds all the configurations.

Koban
  • 463
  • 1
  • 6
  • 12
  • 2
    Possible duplicate of [How can I build all with MSBuild from the command line?](https://stackoverflow.com/questions/842706/how-can-i-build-all-with-msbuild-from-the-command-line) – arrowd Sep 05 '17 at 10:11
  • probably my questions is a bit different, because I use CMake – Koban Sep 05 '17 at 11:59
  • CMake is used to generate a solution, but you build it using msbuild. – arrowd Sep 05 '17 at 12:01
  • Did you already tried `msbuild MyApp.sln /t:ALL_BUILD /Configuration:"Debug;Release;RelWithDebInfo"`? – vre Sep 05 '17 at 12:36
  • With the command msbuild LinesGameQt.sln /t:ALL_BUILD /p:Configuration="Debug;Release;RelWithDebInfo" I get 'error MSB4126: The specified solution configuration "Debug;Release;RelW ithDebInfo|Win32" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties ( e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU")' – Dmitriano Sep 05 '17 at 20:11

1 Answers1

2

This is a bit silly, but you can add a custom target to CMake that causes the project build itself:

add_custom_target(build_all_configs
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ALL_BUILD --config Debug
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ALL_BUILD --config Release
)

You get the idea... Note that CMake can build its own projects, so there is no need to resort to MSBuild at all.

While this works fine, I would rather configure_file a batch script that does the same thing to a location that works for your needs. That will definitely raise fewer eyebrows than the custom command above.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166