From 555c2d04ef5b64ba60b77e6041a307131a5f0987 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 3 Apr 2021 17:35:24 +0200 Subject: [PATCH] Make the first executable the startup project in Visual Studio --- src/cmkrlib/gen.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmkrlib/gen.cpp b/src/cmkrlib/gen.cpp index f16a293..a9c7f46 100644 --- a/src/cmkrlib/gen.cpp +++ b/src/cmkrlib/gen.cpp @@ -542,6 +542,16 @@ int generate_cmake(const char *path, bool root) { cmd(add_command)(target.name, target_type, "${" + target.name + "_SOURCES}").endl(); + // The first executable target will become the Visual Studio startup project + if (target.type == cmake::target_executable) { + cmd("get_directory_property")("CMKR_VS_STARTUP_PROJECT", "DIRECTORY", "${PROJECT_SOURCE_DIR}", "DEFINITION", "VS_STARTUP_PROJECT"); + // clang-format off + cmd("if")("NOT", "CMKR_VS_STARTUP_PROJECT"); + cmd("set_property")("DIRECTORY", "${PROJECT_SOURCE_DIR}", "PROPERTY", "VS_STARTUP_PROJECT", target.name); + cmd("endif")().endl(); + // clang-format on + } + if (!target.sources.empty()) { cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + target.name + "_SOURCES}").endl(); }