From 8de12676236964d2f61f6b328ff99569132647ed Mon Sep 17 00:00:00 2001 From: ccpisheden Date: Tue, 1 Dec 2026 11:50:35 +0100 Subject: [PATCH] Generate only the preset's configuration in multi-config solutions vcpkg installs dependencies for the preset's triplet only, so every other configuration in a multi-config VS/Xcode solution built silently against libraries of the original triplet's flavor, not the selected one. After this change, only the original flavor is exposed in the IDE. --- README.md | 4 ++- cmake/CcpBuildConfigurations.cmake | 42 +++++++++-------------------- cmake/CcpPackageConfigHelpers.cmake | 3 ++- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 8fc93f1e4..a6cae9bb8 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,13 @@ cmake --preset x64-windows-internal This will generate an .slnx at `.cmake-build-/`. Run `cmake --list-presets` to see the presets (`x64-windows-*`, `arm64-osx-*`, `x64-osx-*`, each in `internal`, `release`, `debug` and `trinitydev` flavours). +The solution contains only the preset's flavour, because vcpkg installs the dependencies for that flavour alone. +To work on another flavour, generate it with its own preset into its own build folder. Or build from the command line: ```powershell -cmake --build .cmake-build-x64-windows-internal --config Release +cmake --build .cmake-build-x64-windows-internal --config Internal ``` - Open the generated solution, not the repo folder. Opening the folder makes Visual Studio diff --git a/cmake/CcpBuildConfigurations.cmake b/cmake/CcpBuildConfigurations.cmake index ebc6c16ed..1e3a386c0 100644 --- a/cmake/CcpBuildConfigurations.cmake +++ b/cmake/CcpBuildConfigurations.cmake @@ -9,38 +9,20 @@ Options placed in the toolchain files apply to both this top level project and i While it is desierable for all dependencies to share the same build flags and other settings provided by the toolchain, we do not want 3rd party dependencies to be configured with the settings provided by this file. ]] -# this applies to multi-configuration build system, e.g. XCode, Visual Studio, Ninja Multi-Config +# Every flavor a Carbon component is published in. The published package holds one build of each. +set(CCP_BUILD_FLAVORS Debug TrinityDev Internal Release) -set(CMAKE_CONFIGURATION_TYPES Debug TrinityDev Internal Release) - -get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if(is_multi_config) - set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" - CACHE - STRING - "Reset the configurations to what we need" - FORCE - ) -else() - if (NOT CMAKE_BUILD_TYPE) - message(STATUS "No CMAKE_BUILD_TYPE was specified, defaulting to 'Debug'") - set(CMAKE_BUILD_TYPE "Debug") - endif() - # Update the documentation string of CMAKE_BUILD_TYPE for GUIs - set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" - CACHE - STRING - "Choose the type of build, options are: ${CMAKE_CONFIGURATION_TYPES}." - FORCE - ) - - # check if a valid build type was supplied - if (CMAKE_BUILD_TYPE IN_LIST CMAKE_CONFIGURATION_TYPES) - message(STATUS "Building configuration ${CMAKE_BUILD_TYPE}") - else() - message(FATAL_ERROR "Invalid configuration ${CMAKE_BUILD_TYPE}. Available options are: ${CMAKE_CONFIGURATION_TYPES}") - endif() +# A build folder holds one flavor: the one its preset's vcpkg triplet installed dependencies for. +# This applies to multi-config generators too (Visual Studio, Xcode, Ninja Multi-Config): any other configuration +# would build against that flavor's dependencies. +if (NOT CMAKE_BUILD_TYPE IN_LIST CCP_BUILD_FLAVORS) + message(FATAL_ERROR "CMAKE_BUILD_TYPE is '${CMAKE_BUILD_TYPE}', expected one of: ${CCP_BUILD_FLAVORS}. " + "Configure with a preset, e.g. cmake --preset x64-windows-trinitydev") endif() +set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Build flavor, one of: ${CCP_BUILD_FLAVORS}" FORCE) +message(STATUS "Building configuration ${CMAKE_BUILD_TYPE}") + +set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "The build flavor only" FORCE) # Create a new configuration based on an existing one function(create_new_build_config config prototype) diff --git a/cmake/CcpPackageConfigHelpers.cmake b/cmake/CcpPackageConfigHelpers.cmake index 02013aa0e..4b43d2a95 100644 --- a/cmake/CcpPackageConfigHelpers.cmake +++ b/cmake/CcpPackageConfigHelpers.cmake @@ -31,7 +31,8 @@ function(configure_ccp_vendor_config_file) set(CCP_PACKAGE_CONFIG_TARGET_DEPENDENCIES "${CCP_PACKAGE_CONFIG_TARGET_DEPENDENCIES}find_dependency(${_DEP} REQUIRED CONFIG NO_CMAKE_PATH)\n") endforeach() if(NOT CCP_PACKAGE_CONFIG_CONFIGURATIONS) - set(CCP_PACKAGE_CONFIG_CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES}) + # A build folder builds one flavor, but the published package holds every flavor + set(CCP_PACKAGE_CONFIG_CONFIGURATIONS ${CCP_BUILD_FLAVORS}) endif() get_target_property(CCP_PACKAGE_CONFIG_TARGET_TYPE ${CCP_PACKAGE_CONFIG_TARGET} TYPE) if (${CCP_PACKAGE_CONFIG_TARGET_TYPE} STREQUAL STATIC_LIBRARY)