How do I change the startup project of a Visual Studio solution via CMake?

giggle picture giggle · Sep 5, 2011 · Viewed 18.2k times · Source

I am using CMake to generate Visual Studio projects. Everything works fine except one thing.

The startup project in the solution is always ALL_BUILD. How do I change the startup project to the real project I want via CMake?

Answer

ComicSansMS picture ComicSansMS · Jun 23, 2016

CMake now supports this with versions 3.6 and higher through the VS_STARTUP_PROJECT directory property:

cmake_minimum_required(VERSION 3.6)
project(foo)
# ...

add_executable(bar ${BAR_SOURCES})
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT bar)

This will set bar as the startup project for the foo.sln solution.