Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build all configurations with CMake + msbuild

Tags:

msbuild

cmake

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.

like image 765
Koban Avatar asked Jun 02 '26 20:06

Koban


1 Answers

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.

like image 73
ComicSansMS Avatar answered Jun 06 '26 05:06

ComicSansMS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!